Move to client side

This commit is contained in:
MrWaffle
2014-01-22 21:08:43 +01:00
parent 03d92eb5cd
commit d63ced8a5c
4 changed files with 38 additions and 33 deletions

View File

@@ -3,6 +3,7 @@ var posts = require('../posts'),
topics = require('../topics'),
favourites = require('../favourites'),
postTools = require('../postTools'),
user = require('../user'),
index = require('./index'),
SocketPosts = {};
@@ -168,4 +169,28 @@ SocketPosts.getPrivileges = function(socket, pid, callback) {
});
};
SocketPosts.getFavouritedUsers = function(socket, pid, callback) {
favourites.getFavouritedUidsByPids([pid], function(data) {
var max = 5; //hardcoded
var usernames = "";
var pid_uids = data[pid];
var rest_amount = 0;
if (data.hasOwnProperty(pid) && pid_uids.length > 0) {
if (pid_uids.length > max) {
rest_amount = pid_uids.length - max;
pid_uids = pid_uids.slice(0, max);
}
user.getUsernamesByUids(pid_uids, function(result) {
usernames = result.join(', ') + (rest_amount > 0
? " and " + rest_amount + (rest_amount > 1 ? " others" : " other")
: "");
callback(null, usernames);
});
} else {
callback(null, "");
}
});
};
module.exports = SocketPosts;