|
|
|
@ -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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|