mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-06 22:15:48 +01:00
Merge branch 'favourite-spy' of https://github.com/BitBangersCode/NodeBB into BitBangersCode-favourite-spy
This commit is contained in:
@@ -341,6 +341,17 @@ define(['composer'], function(composer) {
|
||||
updateHeader();
|
||||
}
|
||||
})();
|
||||
|
||||
$('#post-container').on('mouseenter', '.favourite-tooltip', function(e) {
|
||||
if (!$(this).data('users-loaded')) {
|
||||
$(this).data('users-loaded', "true");
|
||||
var pid = $(this).parents('.post-row').attr('data-pid');
|
||||
var el = $(this).attr('title', "Loading...");
|
||||
socket.emit('posts.getFavouritedUsers', pid, function(err, usernames) {
|
||||
el.attr('title', usernames).tooltip('show');
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function enableInfiniteLoading() {
|
||||
|
||||
@@ -66,7 +66,7 @@
|
||||
<!-- IF @first -->
|
||||
<button class="btn btn-sm btn-default follow" type="button" title="Be notified of new replies in this topic"><i class="fa fa-eye"></i></button>
|
||||
<!-- ENDIF @first -->
|
||||
<button data-favourited="{posts.favourited}" class="favourite btn btn-sm btn-default <!-- IF posts.favourited --> btn-warning <!-- ENDIF posts.favourited -->" type="button">
|
||||
<button data-favourited="{posts.favourited}" class="favourite favourite-tooltip btn btn-sm btn-default <!-- IF posts.favourited --> btn-warning <!-- ENDIF posts.favourited -->" type="button">
|
||||
<span class="favourite-text">[[topic:favourite]]</span>
|
||||
<span class="post_rep_{posts.pid}">{posts.reputation} </span>
|
||||
<!-- IF posts.favourited -->
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
var db = require('./database'),
|
||||
var async = require('async'),
|
||||
|
||||
db = require('./database'),
|
||||
posts = require('./posts'),
|
||||
user = require('./user'),
|
||||
translator = require('./../public/src/translator');
|
||||
@@ -98,21 +100,33 @@ var db = require('./database'),
|
||||
};
|
||||
|
||||
Favourites.getFavouritesByPostIDs = function (pids, uid, callback) {
|
||||
var loaded = 0;
|
||||
var data = {};
|
||||
|
||||
for (var i = 0, ii = pids.length; i < ii; i++) {
|
||||
(function (post_id) {
|
||||
Favourites.hasFavourited(post_id, uid, function (hasFavourited) {
|
||||
|
||||
data[post_id] = hasFavourited;
|
||||
loaded++;
|
||||
if (loaded === pids.length) {
|
||||
callback(data);
|
||||
}
|
||||
function iterator(pid, next) {
|
||||
Favourites.hasFavourited(pid, uid, function (hasFavourited) {
|
||||
data[pid] = hasFavourited;
|
||||
next()
|
||||
});
|
||||
}(pids[i]));
|
||||
}
|
||||
|
||||
async.each(pids, iterator, function(err) {
|
||||
callback(data);
|
||||
});
|
||||
};
|
||||
|
||||
Favourites.getFavouritedUidsByPids = function (pids, callback) {
|
||||
var data = {};
|
||||
|
||||
function getUids(pid, next) {
|
||||
db.getSetMembers('pid:' + pid + ':users_favourited', function(err, uids) {
|
||||
data[pid] = uids;
|
||||
next();
|
||||
});
|
||||
}
|
||||
|
||||
async.each(pids, getUids, function(err) {
|
||||
callback(data);
|
||||
});
|
||||
};
|
||||
|
||||
}(exports));
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user