diff --git a/public/language/en-GB/topic.json b/public/language/en-GB/topic.json index 509f238589..91e1a97f14 100644 --- a/public/language/en-GB/topic.json +++ b/public/language/en-GB/topic.json @@ -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.", diff --git a/src/topics/events.js b/src/topics/events.js index a5a28da265..a1af6fc714 100644 --- a/src/topics/events.js +++ b/src/topics/events.js @@ -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; } diff --git a/src/topics/index.js b/src/topics/index.js index 95ddf5a81d..f687c68cba 100644 --- a/src/topics/index.js +++ b/src/topics/index.js @@ -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];