mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 17:16:14 +01:00
cleanup
This commit is contained in:
@@ -207,30 +207,38 @@ SocketPosts.getPrivileges = function(socket, pid, callback) {
|
||||
|
||||
SocketPosts.getFavouritedUsers = function(socket, pid, callback) {
|
||||
|
||||
favourites.getFavouritedUidsByPids([pid], function(data) {
|
||||
favourites.getFavouritedUidsByPids([pid], function(err, data) {
|
||||
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if(!Array.isArray(data) || !data.length) {
|
||||
callback(null, "");
|
||||
}
|
||||
|
||||
console.log(data);
|
||||
var max = 5; //hardcoded
|
||||
var usernames = "";
|
||||
|
||||
var pid_uids = data[pid];
|
||||
var pid_uids = data[0];
|
||||
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(err, result) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
usernames = result.join(', ') + (rest_amount > 0
|
||||
? " and " + rest_amount + (rest_amount > 1 ? " others" : " other")
|
||||
: "");
|
||||
callback(null, usernames);
|
||||
});
|
||||
} else {
|
||||
callback(null, "");
|
||||
if (pid_uids.length > max) {
|
||||
rest_amount = pid_uids.length - max;
|
||||
pid_uids = pid_uids.slice(0, max);
|
||||
}
|
||||
|
||||
user.getUsernamesByUids(pid_uids, function(err, result) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
usernames = result.join(', ') + (rest_amount > 0
|
||||
? " and " + rest_amount + (rest_amount > 1 ? " others" : " other")
|
||||
: "");
|
||||
callback(null, usernames);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user