rejigged Topics.get so that it does not return a hardcoded return if no topics were returned

v1.18.x
Julian Lam 12 years ago
parent 785e49c8d9
commit 3df8d7279b

@ -75,24 +75,24 @@ marked.setOptions({
active_usernames = replies[1]; active_usernames = replies[1];
var topics = []; var topics = [];
if (tids.length > 0) { title = replies[2];
title = replies[2]; uid = replies[3];
uid = replies[3]; timestamp = replies[4];
timestamp = replies[4]; slug = replies[5];
slug = replies[5]; postcount = replies[6];
postcount = replies[6]; locked = replies[7];
locked = replies[7]; deleted = replies[8];
deleted = replies[8]; pinned = replies[9];
pinned = replies[9];
var usernames,
var usernames, has_read,
has_read, moderators,
moderators, teaser_info;
teaser_info;
function generate_topic() {
function generate_topic() { if (!usernames || !has_read || !moderators || !teaser_info) return;
if (!usernames || !has_read || !moderators || !teaser_info) return;
if (tids.length > 0) {
for (var i=0, ii=title.length; i<ii; i++) { for (var i=0, ii=title.length; i<ii; i++) {
topics.push({ topics.push({
'title' : title[i], 'title' : title[i],
@ -111,60 +111,60 @@ marked.setOptions({
'teaser_username': teaser_info[i].username 'teaser_username': teaser_info[i].username
}); });
} }
// Float pinned topics to the top
topics = topics.sort(function(a, b) {
if (a.pinned !== b.pinned) return b.pinned - a.pinned;
else {
// Sort by datetime descending
return b.timestamp - a.timestamp;
}
});
var active_users = [];
for (var username in active_usernames) {
active_users.push({'username': active_usernames[username]});
}
callback({
'category_name' : category_id ? category_name : 'Recent',
'show_topic_button' : category_id ? 'show' : 'hidden',
'category_id': category_id || 0,
'topics': topics,
'active_users': active_users,
'moderator_block_class': moderators.length > 0 ? '' : 'none',
'moderators': moderators
});
} }
user.get_usernames_by_uids(uid, function(userNames) { // Float pinned topics to the top
usernames = userNames; topics = topics.sort(function(a, b) {
generate_topic(); if (a.pinned !== b.pinned) return b.pinned - a.pinned;
}); else {
// Sort by datetime descending
Topics.hasReadTopics(tids, current_user, function(hasRead) { return b.timestamp - a.timestamp;
has_read = hasRead; }
generate_topic();
}); });
categories.getModerators(category_id, function(mods) { var active_users = [];
moderators = mods; for (var username in active_usernames) {
generate_topic(); active_users.push({'username': active_usernames[username]});
}); }
Topics.get_teasers(tids, function(teasers) {
teaser_info = teasers;
generate_topic();
});
}
else {
callback({ callback({
'category_name' : category_id ? category_name : 'Recent', 'category_name' : category_id ? category_name : 'Recent',
'show_topic_button' : category_id ? 'show' : 'hidden', 'show_topic_button' : category_id ? 'show' : 'hidden',
'category_id': category_id || 0, 'category_id': category_id || 0,
'topics': [] 'topics': topics,
'active_users': active_users,
'moderator_block_class': moderators.length > 0 ? '' : 'none',
'moderators': moderators
}); });
} }
user.get_usernames_by_uids(uid, function(userNames) {
usernames = userNames;
generate_topic();
});
Topics.hasReadTopics(tids, current_user, function(hasRead) {
has_read = hasRead;
generate_topic();
});
categories.getModerators(category_id, function(mods) {
moderators = mods;
generate_topic();
});
Topics.get_teasers(tids, function(teasers) {
teaser_info = teasers;
generate_topic();
});
// else {
// callback({
// 'category_name' : category_id ? category_name : 'Recent',
// 'show_topic_button' : category_id ? 'show' : 'hidden',
// 'category_id': category_id || 0,
// 'topics': []
// });
// }
}); });
}); });
} }

@ -447,9 +447,10 @@ var config = require('../config.js'),
}; };
User.get_usernames_by_uids = function(uids, callback) { User.get_usernames_by_uids = function(uids, callback) {
var usernames = []; var usernames = [];
if (!Array.isArray(uids)) return callback([]);
for(var i=0, ii=uids.length; i<ii; ++i) { for(var i=0, ii=uids.length; i<ii; ++i) {
User.getUserField(uids[i],'username', function(username){ User.getUserField(uids[i],'username', function(username){

Loading…
Cancel
Save