This commit is contained in:
barisusakli
2014-08-05 18:18:34 -04:00
parent d4dc716acd
commit f49c95c16f
3 changed files with 19 additions and 24 deletions

View File

@@ -241,37 +241,18 @@ SocketPosts.getPrivileges = function(socket, pid, callback) {
};
SocketPosts.getFavouritedUsers = function(socket, pid, callback) {
favourites.getFavouritedUidsByPids([pid], function(err, data) {
if(err) {
return callback(err);
}
if(!Array.isArray(data) || !data.length) {
callback(null, "");
callback(null, []);
}
var max = 5; //hardcoded
var finalText = "";
var pid_uids = data[0];
var rest_amount = 0;
if (pid_uids.length > max) {
rest_amount = pid_uids.length - max;
pid_uids = pid_uids.slice(0, max);
}
user.getUsernamesByUids(pid_uids, function(err, usernames) {
if(err) {
return callback(err);
}
finalText = usernames.join(', ') + (rest_amount > 0 ?
(" and " + rest_amount + (rest_amount > 1 ? " others" : " other")) : "");
callback(null, finalText);
});
user.getUsernamesByUids(pid_uids, callback);
});
};