mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 09:06:15 +01:00
feat: post-queue topic event
This commit is contained in:
@@ -45,6 +45,7 @@
|
|||||||
"unpinned-by": "Unpinned by",
|
"unpinned-by": "Unpinned by",
|
||||||
"deleted-by": "Deleted by",
|
"deleted-by": "Deleted by",
|
||||||
"restored-by": "Restored 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.",
|
"bookmark_instructions" : "Click here to return to the last read post in this thread.",
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
const db = require('../database');
|
const db = require('../database');
|
||||||
const user = require('../user');
|
const user = require('../user');
|
||||||
|
const posts = require('../posts');
|
||||||
const plugins = require('../plugins');
|
const plugins = require('../plugins');
|
||||||
|
|
||||||
const Events = module.exports;
|
const Events = module.exports;
|
||||||
@@ -41,6 +42,10 @@ Events._types = {
|
|||||||
icon: 'fa-trash-o',
|
icon: 'fa-trash-o',
|
||||||
text: '[[topic:restored-by]]',
|
text: '[[topic:restored-by]]',
|
||||||
},
|
},
|
||||||
|
'post-queue': {
|
||||||
|
icon: 'fa-history',
|
||||||
|
text: '[[topic:queued-by]]',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
Events.init = async () => {
|
Events.init = async () => {
|
||||||
@@ -49,7 +54,7 @@ Events.init = async () => {
|
|||||||
Events._types = types;
|
Events._types = types;
|
||||||
};
|
};
|
||||||
|
|
||||||
Events.get = async (tid) => {
|
Events.get = async (tid, uid) => {
|
||||||
const topics = require('.');
|
const topics = require('.');
|
||||||
|
|
||||||
if (!await topics.exists(tid)) {
|
if (!await topics.exists(tid)) {
|
||||||
@@ -61,7 +66,7 @@ Events.get = async (tid) => {
|
|||||||
const timestamps = eventIds.map(obj => obj.score);
|
const timestamps = eventIds.map(obj => obj.score);
|
||||||
eventIds = eventIds.map(obj => obj.value);
|
eventIds = eventIds.map(obj => obj.value);
|
||||||
let events = await db.getObjects(keys);
|
let events = await db.getObjects(keys);
|
||||||
events = await modifyEvent({ eventIds, timestamps, events });
|
events = await modifyEvent({ tid, uid, eventIds, timestamps, events });
|
||||||
|
|
||||||
return events;
|
return events;
|
||||||
};
|
};
|
||||||
@@ -77,7 +82,21 @@ async function getUserInfo(uids) {
|
|||||||
return userMap;
|
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));
|
const users = await getUserInfo(events.map(event => event.uid).filter(Boolean));
|
||||||
|
|
||||||
// Remove events whose types no longer exist (e.g. plugin uninstalled)
|
// 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]);
|
Object.assign(event, Events._types[event.type]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Sort events
|
||||||
|
events.sort((a, b) => a.timestamp - b.timestamp);
|
||||||
|
|
||||||
return events;
|
return events;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ Topics.getTopicWithPosts = async function (topicData, set, uid, start, stop, rev
|
|||||||
getMerger(topicData),
|
getMerger(topicData),
|
||||||
getRelated(topicData, uid),
|
getRelated(topicData, uid),
|
||||||
Topics.thumbs.load([topicData]),
|
Topics.thumbs.load([topicData]),
|
||||||
Topics.events.get(topicData.tid),
|
Topics.events.get(topicData.tid, uid),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
topicData.thumbs = thumbs[0];
|
topicData.thumbs = thumbs[0];
|
||||||
|
|||||||
Reference in New Issue
Block a user