feat: show editor in post diffs if available

This commit is contained in:
Julian Lam
2020-06-15 17:16:44 -04:00
parent 2515aa77ba
commit f909ed2541
4 changed files with 28 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
'use strict';
const posts = require('../../posts');
const user = require('../../user');
const privileges = require('../../privileges');
const websockets = require('..');
@@ -8,12 +9,24 @@ module.exports = function (SocketPosts) {
SocketPosts.getDiffs = async function (socket, data) {
await privilegeCheck(data.pid, socket.uid);
const timestamps = await posts.diffs.list(data.pid);
const post = await posts.getPostFields(data.pid, ['timestamp', 'uid']);
const diffs = await posts.diffs.get(data.pid);
const uids = diffs.map(diff => diff.uid || null);
uids.push(post.uid);
let usernames = await user.getUsersFields(uids, ['username']);
usernames = usernames.map(userObj => (userObj.uid ? userObj.username : null));
const cid = await posts.getCidByPid(data.pid);
const canEdit = await privileges.categories.can('edit', cid, socket.uid);
const postTime = await posts.getPostField(data.pid, 'timestamp');
timestamps.push(postTime);
timestamps.push(post.timestamp);
return {
timestamps: timestamps,
revisions: timestamps.map((timestamp, idx) => ({
timestamp: timestamp,
username: usernames[idx],
})),
editable: canEdit,
};
};