Implement favourite tooltip to show who favourited a post

v1.18.x
MrWaffle 11 years ago
parent baa74958c5
commit b887b76c29

@ -341,6 +341,8 @@ define(['composer'], function(composer) {
updateHeader(); updateHeader();
} }
})(); })();
$('.favourite-tooltip').tooltip();
}); });
function enableInfiniteLoading() { function enableInfiniteLoading() {

@ -66,7 +66,7 @@
<!-- IF @first --> <!-- 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> <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 --> <!-- 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 title="{posts.favourited_users}" 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="favourite-text">[[topic:favourite]]</span>
<span class="post_rep_{posts.pid}">{posts.reputation} </span> <span class="post_rep_{posts.pid}">{posts.reputation} </span>
<!-- IF posts.favourited --> <!-- IF posts.favourited -->

@ -115,4 +115,23 @@ var db = require('./database'),
} }
}; };
Favourites.getFavouritedUidsByPids = function (pids, callback) {
//Might as well take the method above this as an example
var loaded = 0;
var data = {};
for (var i = 0, ii = pids.length; i < ii; i++) {
(function (post_id) {
db.getSetMembers('pid:' + post_id + ':users_favourited', function(err, uids) {
data[post_id] = uids;
loaded++;
if (loaded === pids.length) {
callback(data);
}
});
}(pids[i]));
}
//Literally
};
}(exports)); }(exports));

@ -370,6 +370,24 @@ var async = require('async'),
}); });
} }
function getFavouritedUsers(next) {
favourites.getFavouritedUidsByPids(pids, function(data) {
var usernames = {};
async.each(pids, function(pid, next) {
if (data.hasOwnProperty(pid) && data[pid].length > 0) {
user.getUsernamesByUids(data[pid], function(result) {
usernames[pid] = result;
});
} else {
usernames[pid] = [];
}
next();
}, function(err) {
next(err, usernames);
});
});
}
function addUserInfoToPosts(next) { function addUserInfoToPosts(next) {
function iterator(post, callback) { function iterator(post, callback) {
posts.addUserInfoToPost(post, function() { posts.addUserInfoToPost(post, function() {
@ -399,17 +417,19 @@ var async = require('async'),
} }
} }
async.parallel([getFavouritesData, addUserInfoToPosts, getPrivileges], function(err, results) { async.parallel([getFavouritesData, addUserInfoToPosts, getPrivileges, getFavouritedUsers], function(err, results) {
if(err) { if(err) {
return callback(err); return callback(err);
} }
var fav_data = results[0], var fav_data = results[0],
privileges = results[2]; privileges = results[2],
fav_users = results[3];
for (var i = 0; i < postData.length; ++i) { for (var i = 0; i < postData.length; ++i) {
var pid = postData[i].pid; var pid = postData[i].pid;
postData[i].favourited = fav_data[pid]; postData[i].favourited = fav_data[pid];
postData[i].favourited_users = fav_users[pid].join(', ');
postData[i].display_moderator_tools = (current_user != 0) && privileges[pid].editable; postData[i].display_moderator_tools = (current_user != 0) && privileges[pid].editable;
postData[i].display_move_tools = privileges[pid].move ? '' : 'hidden'; postData[i].display_move_tools = privileges[pid].move ? '' : 'hidden';
} }

Loading…
Cancel
Save