refactor: async/await socket.io/posts
parent
4652c68ba7
commit
e93ef0d7fd
@ -1,14 +1,14 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
var helpers = require('./helpers');
|
const helpers = require('./helpers');
|
||||||
|
|
||||||
module.exports = function (SocketPosts) {
|
module.exports = function (SocketPosts) {
|
||||||
SocketPosts.bookmark = function (socket, data, callback) {
|
SocketPosts.bookmark = async function (socket, data) {
|
||||||
helpers.postCommand(socket, 'bookmark', 'bookmarked', '', data, callback);
|
return await helpers.postCommand(socket, 'bookmark', 'bookmarked', '', data);
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketPosts.unbookmark = function (socket, data, callback) {
|
SocketPosts.unbookmark = async function (socket, data) {
|
||||||
helpers.postCommand(socket, 'unbookmark', 'bookmarked', '', data, callback);
|
return await helpers.postCommand(socket, 'unbookmark', 'bookmarked', '', data);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -1,46 +1,30 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var async = require('async');
|
const posts = require('../../posts');
|
||||||
var posts = require('../../posts');
|
const privileges = require('../../privileges');
|
||||||
var privileges = require('../../privileges');
|
|
||||||
|
|
||||||
module.exports = function (SocketPosts) {
|
module.exports = function (SocketPosts) {
|
||||||
SocketPosts.getDiffs = function (socket, data, callback) {
|
SocketPosts.getDiffs = async function (socket, data) {
|
||||||
async.waterfall([
|
await privilegeCheck(data.pid, socket.uid);
|
||||||
async.apply(privilegeCheck, data.pid, socket.uid),
|
const timestamps = await posts.diffs.list(data.pid);
|
||||||
function (next) {
|
timestamps.unshift(Date.now());
|
||||||
posts.diffs.list(data.pid, next);
|
return timestamps;
|
||||||
},
|
|
||||||
function (timestamps, next) {
|
|
||||||
timestamps.unshift(Date.now());
|
|
||||||
next(null, timestamps);
|
|
||||||
},
|
|
||||||
], callback);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketPosts.showPostAt = function (socket, data, callback) {
|
SocketPosts.showPostAt = async function (socket, data) {
|
||||||
privilegeCheck(data.pid, socket.uid, function (err) {
|
await privilegeCheck(data.pid, socket.uid);
|
||||||
if (err) {
|
return await posts.diffs.load(data.pid, data.since, socket.uid);
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
posts.diffs.load(data.pid, data.since, socket.uid, callback);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function privilegeCheck(pid, uid, callback) {
|
async function privilegeCheck(pid, uid) {
|
||||||
async.parallel({
|
const [deleted, privilegesData] = await Promise.all([
|
||||||
deleted: async.apply(posts.getPostField, pid, 'deleted'),
|
posts.getPostField(pid, 'deleted'),
|
||||||
privileges: async.apply(privileges.posts.get, [pid], uid),
|
privileges.posts.get([pid], uid),
|
||||||
}, function (err, payload) {
|
]);
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
payload.privileges = payload.privileges[0];
|
|
||||||
|
|
||||||
const allowed = payload.privileges['posts:history'] && (payload.deleted ? payload.privileges['posts:view_deleted'] : true);
|
const allowed = privilegesData[0]['posts:history'] && (deleted ? privilegesData[0]['posts:view_deleted'] : true);
|
||||||
callback(!allowed ? new Error('[[error:no-privileges]]') : null);
|
if (!allowed) {
|
||||||
});
|
throw new Error('[[error:no-privileges]]');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,81 +1,69 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var async = require('async');
|
const validator = require('validator');
|
||||||
var validator = require('validator');
|
const _ = require('lodash');
|
||||||
var _ = require('lodash');
|
|
||||||
|
|
||||||
var posts = require('../../posts');
|
const posts = require('../../posts');
|
||||||
var groups = require('../../groups');
|
const groups = require('../../groups');
|
||||||
var events = require('../../events');
|
const events = require('../../events');
|
||||||
var meta = require('../../meta');
|
const meta = require('../../meta');
|
||||||
var utils = require('../../utils');
|
const utils = require('../../utils');
|
||||||
var websockets = require('../index');
|
const websockets = require('../index');
|
||||||
|
|
||||||
module.exports = function (SocketPosts) {
|
module.exports = function (SocketPosts) {
|
||||||
SocketPosts.edit = function (socket, data, callback) {
|
SocketPosts.edit = async function (socket, data) {
|
||||||
if (!socket.uid) {
|
if (!socket.uid) {
|
||||||
return callback(new Error('[[error:not-logged-in]]'));
|
throw new Error('[[error:not-logged-in]]');
|
||||||
} else if (!data || !data.pid || (meta.config.minimumPostLength !== 0 && !data.content)) {
|
} else if (!data || !data.pid || (meta.config.minimumPostLength !== 0 && !data.content)) {
|
||||||
return callback(new Error('[[error:invalid-data]]'));
|
throw new Error('[[error:invalid-data]]');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trim and remove HTML (latter for composers that send in HTML, like redactor)
|
// Trim and remove HTML (latter for composers that send in HTML, like redactor)
|
||||||
var contentLen = utils.stripHTMLTags(data.content).trim().length;
|
var contentLen = utils.stripHTMLTags(data.content).trim().length;
|
||||||
|
|
||||||
if (data.title && data.title.length < meta.config.minimumTitleLength) {
|
if (data.title && data.title.length < meta.config.minimumTitleLength) {
|
||||||
return callback(new Error('[[error:title-too-short, ' + meta.config.minimumTitleLength + ']]'));
|
throw new Error('[[error:title-too-short, ' + meta.config.minimumTitleLength + ']]');
|
||||||
} else if (data.title && data.title.length > meta.config.maximumTitleLength) {
|
} else if (data.title && data.title.length > meta.config.maximumTitleLength) {
|
||||||
return callback(new Error('[[error:title-too-long, ' + meta.config.maximumTitleLength + ']]'));
|
throw new Error('[[error:title-too-long, ' + meta.config.maximumTitleLength + ']]');
|
||||||
} else if (data.tags && data.tags.length < meta.config.minimumTagsPerTopic) {
|
} else if (data.tags && data.tags.length < meta.config.minimumTagsPerTopic) {
|
||||||
return callback(new Error('[[error:not-enough-tags, ' + meta.config.minimumTagsPerTopic + ']]'));
|
throw new Error('[[error:not-enough-tags, ' + meta.config.minimumTagsPerTopic + ']]');
|
||||||
} else if (data.tags && data.tags.length > meta.config.maximumTagsPerTopic) {
|
} else if (data.tags && data.tags.length > meta.config.maximumTagsPerTopic) {
|
||||||
return callback(new Error('[[error:too-many-tags, ' + meta.config.maximumTagsPerTopic + ']]'));
|
throw new Error('[[error:too-many-tags, ' + meta.config.maximumTagsPerTopic + ']]');
|
||||||
} else if (meta.config.minimumPostLength !== 0 && contentLen < meta.config.minimumPostLength) {
|
} else if (meta.config.minimumPostLength !== 0 && contentLen < meta.config.minimumPostLength) {
|
||||||
return callback(new Error('[[error:content-too-short, ' + meta.config.minimumPostLength + ']]'));
|
throw new Error('[[error:content-too-short, ' + meta.config.minimumPostLength + ']]');
|
||||||
} else if (contentLen > meta.config.maximumPostLength) {
|
} else if (contentLen > meta.config.maximumPostLength) {
|
||||||
return callback(new Error('[[error:content-too-long, ' + meta.config.maximumPostLength + ']]'));
|
throw new Error('[[error:content-too-long, ' + meta.config.maximumPostLength + ']]');
|
||||||
}
|
}
|
||||||
|
|
||||||
data.uid = socket.uid;
|
data.uid = socket.uid;
|
||||||
data.req = websockets.reqFromSocket(socket);
|
data.req = websockets.reqFromSocket(socket);
|
||||||
|
|
||||||
var editResult;
|
const editResult = await posts.edit(data);
|
||||||
async.waterfall([
|
if (editResult.topic.renamed) {
|
||||||
function (next) {
|
await events.log({
|
||||||
posts.edit(data, next);
|
type: 'topic-rename',
|
||||||
},
|
uid: socket.uid,
|
||||||
function (result, next) {
|
ip: socket.ip,
|
||||||
editResult = result;
|
tid: editResult.topic.tid,
|
||||||
if (result.topic.renamed) {
|
oldTitle: validator.escape(String(editResult.topic.oldTitle)),
|
||||||
events.log({
|
newTitle: validator.escape(String(editResult.topic.title)),
|
||||||
type: 'topic-rename',
|
});
|
||||||
uid: socket.uid,
|
}
|
||||||
ip: socket.ip,
|
|
||||||
tid: result.topic.tid,
|
if (!editResult.post.deleted) {
|
||||||
oldTitle: validator.escape(String(result.topic.oldTitle)),
|
websockets.in('topic_' + editResult.topic.tid).emit('event:post_edited', editResult);
|
||||||
newTitle: validator.escape(String(result.topic.title)),
|
return editResult.post;
|
||||||
});
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!result.post.deleted) {
|
const memberData = await groups.getMembersOfGroups([
|
||||||
websockets.in('topic_' + result.topic.tid).emit('event:post_edited', result);
|
'administrators',
|
||||||
return callback(null, result.post);
|
'Global Moderators',
|
||||||
}
|
'cid:' + editResult.topic.cid + ':privileges:moderate',
|
||||||
|
'cid:' + editResult.topic.cid + ':privileges:groups:moderate',
|
||||||
|
]);
|
||||||
|
|
||||||
groups.getMembersOfGroups([
|
const uids = _.uniq(_.flatten(memberData).concat(socket.uid.toString()));
|
||||||
'administrators',
|
uids.forEach(uid => websockets.in('uid_' + uid).emit('event:post_edited', editResult));
|
||||||
'Global Moderators',
|
return editResult.post;
|
||||||
'cid:' + result.topic.cid + ':privileges:moderate',
|
|
||||||
'cid:' + result.topic.cid + ':privileges:groups:moderate',
|
|
||||||
], next);
|
|
||||||
},
|
|
||||||
function (results, next) {
|
|
||||||
var uids = _.uniq(_.flatten(results).concat(socket.uid.toString()));
|
|
||||||
uids.forEach(function (uid) {
|
|
||||||
websockets.in('uid_' + uid).emit('event:post_edited', editResult);
|
|
||||||
});
|
|
||||||
next(null, editResult.post);
|
|
||||||
},
|
|
||||||
], callback);
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -1,82 +1,62 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
var async = require('async');
|
const posts = require('../../posts');
|
||||||
var posts = require('../../posts');
|
const plugins = require('../../plugins');
|
||||||
var plugins = require('../../plugins');
|
const websockets = require('../index');
|
||||||
var websockets = require('../index');
|
const socketHelpers = require('../helpers');
|
||||||
var socketHelpers = require('../helpers');
|
|
||||||
|
|
||||||
var helpers = module.exports;
|
const helpers = module.exports;
|
||||||
|
|
||||||
helpers.postCommand = function (socket, command, eventName, notification, data, callback) {
|
helpers.postCommand = async function (socket, command, eventName, notification, data) {
|
||||||
if (!socket.uid) {
|
if (!socket.uid) {
|
||||||
return callback(new Error('[[error:not-logged-in]]'));
|
throw new Error('[[error:not-logged-in]]');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data || !data.pid) {
|
if (!data || !data.pid) {
|
||||||
return callback(new Error('[[error:invalid-data]]'));
|
throw new Error('[[error:invalid-data]]');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data.room_id) {
|
if (!data.room_id) {
|
||||||
return callback(new Error('[[error:invalid-room-id, ' + data.room_id + ' ]]'));
|
throw new Error('[[error:invalid-room-id, ' + data.room_id + ' ]]');
|
||||||
}
|
}
|
||||||
|
const [exists, deleted] = await Promise.all([
|
||||||
|
posts.exists(data.pid),
|
||||||
|
posts.getPostField(data.pid, 'deleted'),
|
||||||
|
]);
|
||||||
|
|
||||||
async.waterfall([
|
if (!exists) {
|
||||||
function (next) {
|
throw new Error('[[error:invalid-pid]]');
|
||||||
async.parallel({
|
}
|
||||||
exists: function (next) {
|
|
||||||
posts.exists(data.pid, next);
|
|
||||||
},
|
|
||||||
deleted: function (next) {
|
|
||||||
posts.getPostField(data.pid, 'deleted', next);
|
|
||||||
},
|
|
||||||
}, next);
|
|
||||||
},
|
|
||||||
function (results, next) {
|
|
||||||
if (!results.exists) {
|
|
||||||
return next(new Error('[[error:invalid-pid]]'));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (results.deleted) {
|
if (deleted) {
|
||||||
return next(new Error('[[error:post-deleted]]'));
|
throw new Error('[[error:post-deleted]]');
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
hooks:
|
hooks:
|
||||||
filter:post.upvote
|
filter:post.upvote
|
||||||
filter:post.downvote
|
filter:post.downvote
|
||||||
filter:post.unvote
|
filter:post.unvote
|
||||||
filter:post.bookmark
|
filter:post.bookmark
|
||||||
filter:post.unbookmark
|
filter:post.unbookmark
|
||||||
*/
|
*/
|
||||||
plugins.fireHook('filter:post.' + command, { data: data, uid: socket.uid }, next);
|
const filteredData = await plugins.fireHook('filter:post.' + command, { data: data, uid: socket.uid });
|
||||||
},
|
return await executeCommand(socket, command, eventName, notification, filteredData.data);
|
||||||
function (filteredData, next) {
|
|
||||||
executeCommand(socket, command, eventName, notification, filteredData.data, next);
|
|
||||||
},
|
|
||||||
], callback);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function executeCommand(socket, command, eventName, notification, data, callback) {
|
async function executeCommand(socket, command, eventName, notification, data) {
|
||||||
async.waterfall([
|
const result = await posts[command](data.pid, socket.uid);
|
||||||
function (next) {
|
if (result && eventName) {
|
||||||
posts[command](data.pid, socket.uid, next);
|
websockets.in('uid_' + socket.uid).emit('posts.' + command, result);
|
||||||
},
|
websockets.in(data.room_id).emit('event:' + eventName, result);
|
||||||
function (result, next) {
|
}
|
||||||
if (result && eventName) {
|
if (result && command === 'upvote') {
|
||||||
websockets.in('uid_' + socket.uid).emit('posts.' + command, result);
|
socketHelpers.upvote(result, notification);
|
||||||
websockets.in(data.room_id).emit('event:' + eventName, result);
|
} else if (result && notification) {
|
||||||
}
|
socketHelpers.sendNotificationToPostOwner(data.pid, socket.uid, command, notification);
|
||||||
|
} else if (result && command === 'unvote') {
|
||||||
if (result && command === 'upvote') {
|
socketHelpers.rescindUpvoteNotification(data.pid, socket.uid);
|
||||||
socketHelpers.upvote(result, notification);
|
}
|
||||||
} else if (result && notification) {
|
return result;
|
||||||
socketHelpers.sendNotificationToPostOwner(data.pid, socket.uid, command, notification);
|
|
||||||
} else if (result && command === 'unvote') {
|
|
||||||
socketHelpers.rescindUpvoteNotification(data.pid, socket.uid);
|
|
||||||
}
|
|
||||||
next(null, result);
|
|
||||||
},
|
|
||||||
], callback);
|
|
||||||
}
|
}
|
||||||
|
@ -1,40 +1,31 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var async = require('async');
|
const privileges = require('../../privileges');
|
||||||
var privileges = require('../../privileges');
|
const topics = require('../../topics');
|
||||||
var topics = require('../../topics');
|
const socketHelpers = require('../helpers');
|
||||||
var socketHelpers = require('../helpers');
|
|
||||||
|
|
||||||
module.exports = function (SocketPosts) {
|
module.exports = function (SocketPosts) {
|
||||||
SocketPosts.movePost = function (socket, data, callback) {
|
SocketPosts.movePost = async function (socket, data) {
|
||||||
SocketPosts.movePosts(socket, { pids: [data.pid], tid: data.tid }, callback);
|
await SocketPosts.movePosts(socket, { pids: [data.pid], tid: data.tid });
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketPosts.movePosts = function (socket, data, callback) {
|
SocketPosts.movePosts = async function (socket, data) {
|
||||||
if (!socket.uid) {
|
if (!socket.uid) {
|
||||||
return callback(new Error('[[error:not-logged-in]]'));
|
throw new Error('[[error:not-logged-in]]');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data || !Array.isArray(data.pids) || !data.tid) {
|
if (!data || !Array.isArray(data.pids) || !data.tid) {
|
||||||
return callback(new Error('[[error:invalid-data]]'));
|
throw new Error('[[error:invalid-data]]');
|
||||||
}
|
}
|
||||||
async.eachSeries(data.pids, function (pid, next) {
|
|
||||||
async.waterfall([
|
|
||||||
function (next) {
|
|
||||||
privileges.posts.canMove(pid, socket.uid, next);
|
|
||||||
},
|
|
||||||
function (canMove, next) {
|
|
||||||
if (!canMove) {
|
|
||||||
return next(new Error('[[error:no-privileges]]'));
|
|
||||||
}
|
|
||||||
|
|
||||||
topics.movePostToTopic(socket.uid, pid, data.tid, next);
|
for (const pid of data.pids) {
|
||||||
},
|
/* eslint-disable no-await-in-loop */
|
||||||
function (next) {
|
const canMove = await privileges.posts.canMove(pid, socket.uid);
|
||||||
socketHelpers.sendNotificationToPostOwner(pid, socket.uid, 'move', 'notifications:moved_your_post');
|
if (!canMove) {
|
||||||
next();
|
throw new Error('[[error:no-privileges]]');
|
||||||
},
|
}
|
||||||
], next);
|
await topics.movePostToTopic(socket.uid, pid, data.tid);
|
||||||
}, callback);
|
socketHelpers.sendNotificationToPostOwner(pid, socket.uid, 'move', 'notifications:moved_your_post');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -1,103 +1,74 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var async = require('async');
|
const db = require('../../database');
|
||||||
|
const user = require('../../user');
|
||||||
var db = require('../../database');
|
const posts = require('../../posts');
|
||||||
var user = require('../../user');
|
const privileges = require('../../privileges');
|
||||||
var posts = require('../../posts');
|
const meta = require('../../meta');
|
||||||
var privileges = require('../../privileges');
|
const helpers = require('./helpers');
|
||||||
var meta = require('../../meta');
|
|
||||||
var helpers = require('./helpers');
|
|
||||||
|
|
||||||
module.exports = function (SocketPosts) {
|
module.exports = function (SocketPosts) {
|
||||||
SocketPosts.getVoters = function (socket, data, callback) {
|
SocketPosts.getVoters = async function (socket, data) {
|
||||||
if (!data || !data.pid || !data.cid) {
|
if (!data || !data.pid || !data.cid) {
|
||||||
return callback(new Error('[[error:invalid-data]]'));
|
throw new Error('[[error:invalid-data]]');
|
||||||
}
|
}
|
||||||
const showDownvotes = !meta.config['downvote:disabled'];
|
const showDownvotes = !meta.config['downvote:disabled'];
|
||||||
async.waterfall([
|
const canSeeVotes = meta.config.votesArePublic || await privileges.categories.isAdminOrMod(data.cid, socket.uid);
|
||||||
function (next) {
|
if (!canSeeVotes) {
|
||||||
if (meta.config.votesArePublic) {
|
throw new Error('[[error:no-privileges]]');
|
||||||
return next(null, true);
|
}
|
||||||
}
|
const [upvoteUids, downvoteUids] = await Promise.all([
|
||||||
privileges.categories.isAdminOrMod(data.cid, socket.uid, next);
|
db.getSetMembers('pid:' + data.pid + ':upvote'),
|
||||||
},
|
showDownvotes ? db.getSetMembers('pid:' + data.pid + ':downvote') : [],
|
||||||
function (isAdminOrMod, next) {
|
]);
|
||||||
if (!isAdminOrMod) {
|
|
||||||
return next(new Error('[[error:no-privileges]]'));
|
const [upvoters, downvoters] = await Promise.all([
|
||||||
}
|
user.getUsersFields(upvoteUids, ['username', 'userslug', 'picture']),
|
||||||
|
user.getUsersFields(downvoteUids, ['username', 'userslug', 'picture']),
|
||||||
|
]);
|
||||||
|
|
||||||
async.parallel({
|
return {
|
||||||
upvoteUids: function (next) {
|
upvoteCount: upvoters.length,
|
||||||
db.getSetMembers('pid:' + data.pid + ':upvote', next);
|
downvoteCount: downvoters.length,
|
||||||
},
|
showDownvotes: showDownvotes,
|
||||||
downvoteUids: function (next) {
|
upvoters: upvoters,
|
||||||
if (!showDownvotes) {
|
downvoters: downvoters,
|
||||||
return setImmediate(next, null, []);
|
};
|
||||||
}
|
|
||||||
db.getSetMembers('pid:' + data.pid + ':downvote', next);
|
|
||||||
},
|
|
||||||
}, next);
|
|
||||||
},
|
|
||||||
function (results, next) {
|
|
||||||
async.parallel({
|
|
||||||
upvoters: function (next) {
|
|
||||||
user.getUsersFields(results.upvoteUids, ['username', 'userslug', 'picture'], next);
|
|
||||||
},
|
|
||||||
downvoters: function (next) {
|
|
||||||
user.getUsersFields(results.downvoteUids, ['username', 'userslug', 'picture'], next);
|
|
||||||
},
|
|
||||||
}, next);
|
|
||||||
},
|
|
||||||
function (results, next) {
|
|
||||||
results.upvoteCount = results.upvoters.length;
|
|
||||||
results.downvoteCount = results.downvoters.length;
|
|
||||||
results.showDownvotes = showDownvotes;
|
|
||||||
next(null, results);
|
|
||||||
},
|
|
||||||
], callback);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketPosts.getUpvoters = function (socket, pids, callback) {
|
SocketPosts.getUpvoters = async function (socket, pids) {
|
||||||
if (!Array.isArray(pids)) {
|
if (!Array.isArray(pids)) {
|
||||||
return callback(new Error('[[error:invalid-data]]'));
|
throw new Error('[[error:invalid-data]]');
|
||||||
|
}
|
||||||
|
const data = await posts.getUpvotedUidsByPids(pids);
|
||||||
|
if (!data.length) {
|
||||||
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
async.waterfall([
|
const result = await Promise.all(data.map(async function (uids) {
|
||||||
function (next) {
|
let otherCount = 0;
|
||||||
posts.getUpvotedUidsByPids(pids, next);
|
if (uids.length > 6) {
|
||||||
},
|
otherCount = uids.length - 5;
|
||||||
function (data, next) {
|
uids = uids.slice(0, 5);
|
||||||
if (!data.length) {
|
}
|
||||||
return callback(null, []);
|
const usernames = await user.getUsernamesByUids(uids);
|
||||||
}
|
return {
|
||||||
|
otherCount: otherCount,
|
||||||
async.map(data, function (uids, next) {
|
usernames: usernames,
|
||||||
var otherCount = 0;
|
};
|
||||||
if (uids.length > 6) {
|
}));
|
||||||
otherCount = uids.length - 5;
|
return result;
|
||||||
uids = uids.slice(0, 5);
|
|
||||||
}
|
|
||||||
user.getUsernamesByUids(uids, function (err, usernames) {
|
|
||||||
next(err, {
|
|
||||||
otherCount: otherCount,
|
|
||||||
usernames: usernames,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}, next);
|
|
||||||
},
|
|
||||||
], callback);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketPosts.upvote = function (socket, data, callback) {
|
SocketPosts.upvote = async function (socket, data) {
|
||||||
helpers.postCommand(socket, 'upvote', 'voted', 'notifications:upvoted_your_post_in', data, callback);
|
return await helpers.postCommand(socket, 'upvote', 'voted', 'notifications:upvoted_your_post_in', data);
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketPosts.downvote = function (socket, data, callback) {
|
SocketPosts.downvote = async function (socket, data) {
|
||||||
helpers.postCommand(socket, 'downvote', 'voted', '', data, callback);
|
return await helpers.postCommand(socket, 'downvote', 'voted', '', data);
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketPosts.unvote = function (socket, data, callback) {
|
SocketPosts.unvote = async function (socket, data) {
|
||||||
helpers.postCommand(socket, 'unvote', 'voted', '', data, callback);
|
return await helpers.postCommand(socket, 'unvote', 'voted', '', data);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue