@ginstone/nga-api
Version:
78 lines (77 loc) • 3.2 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TopicParent = exports.TopicInfo = void 0;
const Reply_1 = require("./Reply");
const TitleFont_1 = require("./TitleFont");
const TopicMiscVar_1 = require("./TopicMiscVar");
const ReplyStatus_1 = require("../../enums/ReplyStatus");
const TimeUtils_1 = require("../../utils/TimeUtils");
const StrUtils_1 = require("@ginstone/common-utils/dist/src/utils/StrUtils");
const AnonymousUtils_1 = require("../../utils/AnonymousUtils");
const EntranceType_1 = require("../../enums/EntranceType");
const ForumType_1 = require("../../enums/ForumType");
class TopicInfo {
constructor(raw) {
if (raw.__P)
this.reply = new Reply_1.ReplySimple(raw.__P);
if (raw.authorid) {
if (typeof raw.authorid === 'string' && raw.authorid.startsWith("#anony")) {
this.authorUid = 0;
this.authorName = (0, AnonymousUtils_1.getAnonyName)(raw.authorid);
}
else if (typeof raw.authorid === 'number') {
this.authorName = raw.author;
this.authorUid = raw.authorid;
}
}
this.forumId = raw.fid;
this.jData = raw.jdata;
this.lastModify = (0, TimeUtils_1.secondsToDate)(raw.lastmodify);
this.lastPost = (0, TimeUtils_1.secondsToDate)(raw.lastpost);
this.lastPosterName = raw.lastposter;
this.parent = raw.parent ? new TopicParent(raw.parent) : undefined;
this.postDatetime = (0, TimeUtils_1.secondsToDate)(raw.postdate);
this.quoteFromTopicId = raw.quote_from;
this.recommendScore = raw.recommend;
if (raw.topic_misc)
this.titleFont = new TitleFont_1.TitleFont(raw.topic_misc);
this.replies = raw.replies;
this.title = raw.subject ? (0, StrUtils_1.unEscape)(raw.subject) : undefined;
this.topicId = raw.tid;
this.url = raw.tpcurl;
this.topicMiscVar = raw.topic_misc_var ? new TopicMiscVar_1.TopicMiscVar(raw.topic_misc_var) : undefined;
this.status = (0, ReplyStatus_1.parseStatus)(raw.type);
if (raw.replies) {
const total = raw.replies + 1;
const p = Math.floor(total / 20);
const m = total % 20;
this.totalPage = p + (m > 0 ? 1 : 0);
}
//判断入口类型
if (this.status && this.status.id.includes(ReplyStatus_1.ReplyStatusEnum.IS_SET)) {
// 合集入口
this.entranceType = EntranceType_1.EntranceType.COL;
}
else if (this.topicMiscVar && this.topicMiscVar.entrance === ForumType_1.ForumType.FORUM) {
// 版面入口
this.entranceType = EntranceType_1.EntranceType.FORUM;
this.forumId = this.topicMiscVar.forumId;
}
else {
// 主题入口
this.entranceType = EntranceType_1.EntranceType.TOPIC;
}
}
}
exports.TopicInfo = TopicInfo;
/**
* 合集中主题的上级信息
*/
class TopicParent {
constructor(raw) {
this.forumId = raw[0];
this.colTid = raw[1];
this.name = raw[2];
}
}
exports.TopicParent = TopicParent;