UNPKG

@ginstone/nga-api

Version:

57 lines (56 loc) 2.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ReadBody = void 0; const Forum_1 = require("../field/Forum"); const TopicDetail_1 = require("../field/TopicDetail"); const UserContext_1 = require("../field/user/UserContext"); const ReplyInfo_1 = require("../field/ReplyInfo"); /** * read.php 接口响应 */ class ReadBody { constructor(raw) { raw.__F.fid = raw.__T.fid; this.currentUser = raw.__CU; this.forum = new Forum_1.Forum(raw.__F); if (raw.__T) this.topicInfo = new TopicDetail_1.TopicDetail(raw.__T); this.userContext = new UserContext_1.UserContext(raw.__U); // 复制一份声望等级数据 this.userContext.customLevels = this.forum.customLevels; this.replies = raw.__R ? Object.keys(raw.__R).map(i => new ReplyInfo_1.ReplyInfo(raw.__R[i])) : []; this.pageData = ReadBody.getPageData(raw); //填充 审核状态楼层 const size = 20; // 本页的第一个楼层号 const firstLevel = (this.pageData.page - 1) * size; // 本页的最后一个楼层号 const lastLevel = firstLevel + Math.min(size, this.pageData.total - firstLevel); for (let level = firstLevel; level < lastLevel; level++) { const r = this.replies.filter(i => i.floorNumber === level)[0]; if (!r) { this.replies.push(new ReplyInfo_1.ReplyInfo({ subject: '[本条回复不可见,可能: 被隐藏/审核中/审核不通过]', lou: level })); } } // @ts-ignore this.replies.sort((a, b) => a.floorNumber - b.floorNumber); } static getPageData(raw) { const page = raw.__PAGE; const total = raw.__ROWS; const size = raw.__R__ROWS_PAGE; if (raw.totalPage) { return { page, total, size, totalPage: raw.totalPage }; } else { const p = Math.floor((total / size)); const m = total % size; return { page, total, size, totalPage: p + (m > 0 ? 1 : 0) }; } } } exports.ReadBody = ReadBody;