feat: post-queue topic event

v1.18.x
Julian Lam 4 years ago
parent 3f35fd335d
commit 8fd78ce512

@ -45,6 +45,7 @@
"unpinned-by": "Unpinned by",
"deleted-by": "Deleted by",
"restored-by": "Restored by",
"queued-by": "Post queued for approval →",
"bookmark_instructions" : "Click here to return to the last read post in this thread.",

@ -2,6 +2,7 @@
const db = require('../database');
const user = require('../user');
const posts = require('../posts');
const plugins = require('../plugins');
const Events = module.exports;
@ -41,6 +42,10 @@ Events._types = {
icon: 'fa-trash-o',
text: '[[topic:restored-by]]',
},
'post-queue': {
icon: 'fa-history',
text: '[[topic:queued-by]]',
},
};
Events.init = async () => {
@ -49,7 +54,7 @@ Events.init = async () => {
Events._types = types;
};
Events.get = async (tid) => {
Events.get = async (tid, uid) => {
const topics = require('.');
if (!await topics.exists(tid)) {
@ -61,7 +66,7 @@ Events.get = async (tid) => {
const timestamps = eventIds.map(obj => obj.score);
eventIds = eventIds.map(obj => obj.value);
let events = await db.getObjects(keys);
events = await modifyEvent({ eventIds, timestamps, events });
events = await modifyEvent({ tid, uid, eventIds, timestamps, events });
return events;
};
@ -77,7 +82,21 @@ async function getUserInfo(uids) {
return userMap;
}
async function modifyEvent({ eventIds, timestamps, events }) {
async function modifyEvent({ tid, uid, eventIds, timestamps, events }) {
// Add posts from post queue
const isPrivileged = await user.isPrivileged(uid);
if (isPrivileged) {
const queuedPosts = await posts.getQueuedPosts({ tid }, { metadata: false });
Object.assign(events, queuedPosts.map(item => ({
type: 'post-queue',
timestamp: item.data.timestamp || Date.now(),
uid: item.data.uid,
})));
queuedPosts.forEach((item) => {
timestamps.push(item.data.timestamp || Date.now());
});
}
const users = await getUserInfo(events.map(event => event.uid).filter(Boolean));
// Remove events whose types no longer exist (e.g. plugin uninstalled)
@ -95,6 +114,9 @@ async function modifyEvent({ eventIds, timestamps, events }) {
Object.assign(event, Events._types[event.type]);
});
// Sort events
events.sort((a, b) => a.timestamp - b.timestamp);
return events;
}

@ -168,7 +168,7 @@ Topics.getTopicWithPosts = async function (topicData, set, uid, start, stop, rev
getMerger(topicData),
getRelated(topicData, uid),
Topics.thumbs.load([topicData]),
Topics.events.get(topicData.tid),
Topics.events.get(topicData.tid, uid),
]);
topicData.thumbs = thumbs[0];

Loading…
Cancel
Save