2018-02-16 16:41:06 -05:00
|
|
|
'use strict';
|
|
|
|
|
|
2018-06-06 16:21:48 -04:00
|
|
|
var async = require('async');
|
2018-02-16 16:41:06 -05:00
|
|
|
var posts = require('../../posts');
|
2018-06-07 12:23:08 -04:00
|
|
|
var privileges = require('../../privileges');
|
2018-02-16 16:41:06 -05:00
|
|
|
|
|
|
|
|
module.exports = function (SocketPosts) {
|
|
|
|
|
SocketPosts.getDiffs = function (socket, data, callback) {
|
2018-06-06 16:21:48 -04:00
|
|
|
async.waterfall([
|
2018-06-07 12:23:08 -04:00
|
|
|
function (next) {
|
|
|
|
|
privileges.posts.can('posts:history', data.pid, socket.uid, function (err, allowed) {
|
|
|
|
|
next(err || allowed ? null : new Error('[[error:no-privileges]]'));
|
|
|
|
|
});
|
|
|
|
|
},
|
2018-06-06 16:21:48 -04:00
|
|
|
function (next) {
|
|
|
|
|
posts.diffs.list(data.pid, next);
|
|
|
|
|
},
|
|
|
|
|
function (timestamps, next) {
|
|
|
|
|
timestamps.unshift(Date.now());
|
|
|
|
|
next(null, timestamps);
|
|
|
|
|
},
|
|
|
|
|
], callback);
|
2018-02-16 16:41:06 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SocketPosts.showPostAt = function (socket, data, callback) {
|
2018-06-07 12:23:08 -04:00
|
|
|
privileges.posts.can('posts:history', data.pid, socket.uid, function (err, allowed) {
|
|
|
|
|
if (err || !allowed) {
|
|
|
|
|
return callback(err || new Error('[[error:no-privileges]]'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
posts.diffs.load(data.pid, data.since, socket.uid, callback);
|
|
|
|
|
});
|
2018-02-16 16:41:06 -05:00
|
|
|
};
|
|
|
|
|
};
|