mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 03:55:55 +01:00
more work
This commit is contained in:
@@ -115,111 +115,91 @@ var RDB = require('./redis.js'),
|
|||||||
|
|
||||||
// not the permanent location for this function
|
// not the permanent location for this function
|
||||||
Categories.getTopicsByTids = function(tids, current_user, callback, category_id /*temporary*/) {
|
Categories.getTopicsByTids = function(tids, current_user, callback, category_id /*temporary*/) {
|
||||||
var title = [],
|
var retrieved_topics = [];
|
||||||
uid = [],
|
|
||||||
timestamp = [],
|
function getTopicInfoMoar(topicData, callback) {
|
||||||
lastposttime = [],
|
|
||||||
slug = [],
|
|
||||||
postcount = [],
|
|
||||||
locked = [],
|
|
||||||
deleted = [],
|
|
||||||
pinned = [];
|
|
||||||
|
|
||||||
for (var i=0, ii=tids.length; i<ii; i++) {
|
function getUserNames(next) {
|
||||||
title.push('tid:' + tids[i] + ':title');
|
user.getUserField(topicData.uid, 'username', function(username) {
|
||||||
uid.push('tid:' + tids[i] + ':uid');
|
next(null, username);
|
||||||
timestamp.push('tid:' + tids[i] + ':timestamp');
|
});
|
||||||
lastposttime.push('tid:' + tids[i] + ':lastposttime');
|
}
|
||||||
slug.push('tid:' + tids[i] + ':slug');
|
|
||||||
postcount.push('tid:' + tids[i] + ':postcount');
|
function hasReadTopics(next) {
|
||||||
locked.push('tid:' + tids[i] + ':locked');
|
topics.hasReadTopics([topicData.tid], current_user, function(hasRead) {
|
||||||
deleted.push('tid:' + tids[i] + ':deleted');
|
next(null, hasRead);
|
||||||
pinned.push('tid:' + tids[i] + ':pinned');
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTeaserInfo(next) {
|
||||||
|
topics.get_teasers([topicData.tid], function(teasers) {
|
||||||
|
next(null, teasers);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// temporary. I don't think this call should belong here
|
||||||
|
function getPrivileges(next) {
|
||||||
|
Categories.privileges(category_id, current_user, function(user_privs) {
|
||||||
|
next(null, user_privs);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async.parallel([getUserNames, hasReadTopics, getTeaserInfo, getPrivileges], function(err, results) {
|
||||||
|
var username = results[0],
|
||||||
|
hasReadTopic = results[1],
|
||||||
|
teaserInfo = results[2],
|
||||||
|
privileges = results[3];
|
||||||
|
|
||||||
|
callback({
|
||||||
|
username: username,
|
||||||
|
hasReadTopic: hasReadTopic,
|
||||||
|
teaserInfo: teaserInfo,
|
||||||
|
privileges: privileges
|
||||||
|
});
|
||||||
|
//if (!deleted[i] || (deleted[i] && privileges.view_deleted) || uid[i] === current_user) {
|
||||||
|
/*retrieved_topics.push({
|
||||||
|
|
||||||
|
'username': usernames[i],
|
||||||
|
'badgeclass' : (hasReadTopics[i] && current_user !=0) ? '' : 'badge-important',
|
||||||
|
'teaser_text': teaserInfo[i].text,
|
||||||
|
'teaser_username': teaserInfo[i].username,
|
||||||
|
'teaser_timestamp': utils.relativeTime(teaserInfo[i].timestamp)
|
||||||
|
});*/
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
RDB.multi()
|
for(var i=0; i<tids.length; ++i) {
|
||||||
.mget(title)
|
|
||||||
.mget(uid)
|
|
||||||
.mget(timestamp)
|
|
||||||
.mget(lastposttime)
|
|
||||||
.mget(slug)
|
|
||||||
.mget(postcount)
|
|
||||||
.mget(locked)
|
|
||||||
.mget(deleted)
|
|
||||||
.mget(pinned)
|
|
||||||
.exec(function(err, replies) {
|
|
||||||
var retrieved_topics = [];
|
|
||||||
|
|
||||||
title = replies[0];
|
topics.getTopicData(tids[i], function(topicData) {
|
||||||
uid = replies[1];
|
|
||||||
timestamp = replies[2];
|
|
||||||
lastposttime = replies[3];
|
|
||||||
slug = replies[4];
|
|
||||||
postcount = replies[5];
|
|
||||||
locked = replies[6];
|
|
||||||
deleted = replies[7];
|
|
||||||
pinned = replies[8];
|
|
||||||
|
|
||||||
function getUserNames(next) {
|
|
||||||
user.get_usernames_by_uids(uid, function(userNames) {
|
|
||||||
next(null, userNames);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function hasReadTopics(next) {
|
getTopicInfoMoar(topicData, function(topicInfo) {
|
||||||
topics.hasReadTopics(tids, current_user, function(hasRead) {
|
console.log(topicInfo);
|
||||||
next(null, hasRead);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function getTeaserInfo(next) {
|
topicData['pin-icon'] = topicData.pinned === '1' ? 'icon-pushpin' : 'none';
|
||||||
topics.get_teasers(tids, function(teasers) {
|
topicData['lock-icon'] = topicData.locked === '1' ? 'icon-lock' : 'none';
|
||||||
next(null, teasers);
|
topicData['deleted-class'] = topicData.deleted === '1' ? 'deleted' : '';
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// temporary. I don't think this call should belong here
|
topicData.relativeTime = utils.relativeTime(topicData.timestamp);
|
||||||
function getPrivileges(next) {
|
|
||||||
Categories.privileges(category_id, current_user, function(user_privs) {
|
|
||||||
next(null, user_privs);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async.parallel([getUserNames, hasReadTopics, getTeaserInfo, getPrivileges], function(err, results) {
|
topicData.username = topicInfo.username;
|
||||||
var usernames = results[0],
|
topicData.badgeclass = (topicInfo.hasread && current_user != 0) ? '' : 'badge-important';
|
||||||
hasReadTopics = results[1],
|
topicData.teaser_text = topicInfo.teaserInfo.text,
|
||||||
teaserInfo = results[2],
|
topicData.teaser_username = topicInfo.teaserInfo.username;
|
||||||
privileges = results[3];
|
topicData.teaser_timestamp = utils.relativeTime(topicInfo.teaserInfo.timestamp);
|
||||||
|
|
||||||
for (var i=0, ii=tids.length; i<ii; i++) {
|
retrieved_topics.push(topicData);
|
||||||
if (!deleted[i] || (deleted[i] && privileges.view_deleted) || uid[i] === current_user) {
|
|
||||||
retrieved_topics.push({
|
|
||||||
'tid' : tids[i],
|
|
||||||
'title' : title[i],
|
|
||||||
'uid' : uid[i],
|
|
||||||
'username': usernames[i],
|
|
||||||
'timestamp' : timestamp[i],
|
|
||||||
'lastposttime' : lastposttime[i],
|
|
||||||
'relativeTime': utils.relativeTime(timestamp[i]),
|
|
||||||
'slug' : slug[i],
|
|
||||||
'post_count' : postcount[i],
|
|
||||||
'lock-icon': locked[i] === '1' ? 'icon-lock' : 'none',
|
|
||||||
'deleted': deleted[i],
|
|
||||||
'deleted-class': deleted[i] ? 'deleted' : '',
|
|
||||||
'pinned': parseInt(pinned[i] || 0), // For sorting purposes
|
|
||||||
'pin-icon': pinned[i] === '1' ? 'icon-pushpin' : 'none',
|
|
||||||
'badgeclass' : (hasReadTopics[i] && current_user !=0) ? '' : 'badge-important',
|
|
||||||
'teaser_text': teaserInfo[i].text,
|
|
||||||
'teaser_username': teaserInfo[i].username,
|
|
||||||
'teaser_timestamp': utils.relativeTime(teaserInfo[i].timestamp)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
callback(retrieved_topics);
|
if(retrieved_topics.length === tids.length)
|
||||||
|
callback(retrieved_topics);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Categories.getAllCategories = function(callback, current_user) {
|
Categories.getAllCategories = function(callback, current_user) {
|
||||||
|
|||||||
15
src/posts.js
15
src/posts.js
@@ -103,6 +103,21 @@ marked.setOptions({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Posts.getPostFields = function(pid, fields, callback) {
|
||||||
|
RDB.hmget('post:' + pid, fields, function(err, data) {
|
||||||
|
if(err === null) {
|
||||||
|
var returnData = {};
|
||||||
|
|
||||||
|
for(var i=0, ii=fields.length; i<ii; ++i) {
|
||||||
|
returnData[fields[i]] = data[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(returnData);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Posts.get_cid_by_pid = function(pid, callback) {
|
Posts.get_cid_by_pid = function(pid, callback) {
|
||||||
Posts.getPostField(pid, 'tid', function(tid) {
|
Posts.getPostField(pid, 'tid', function(tid) {
|
||||||
|
|||||||
@@ -303,11 +303,9 @@ marked.setOptions({
|
|||||||
Topics.get_teaser = function(tid, callback) {
|
Topics.get_teaser = function(tid, callback) {
|
||||||
Topics.get_latest_undeleted_pid(tid, function(pid) {
|
Topics.get_latest_undeleted_pid(tid, function(pid) {
|
||||||
if (pid !== null) {
|
if (pid !== null) {
|
||||||
RDB.mget([
|
|
||||||
'pid:' + pid + ':content',
|
posts.getPostFields(pid, ['content', 'uid', 'timestamp'], function(content) {
|
||||||
'pid:' + pid + ':uid',
|
|
||||||
'pid:' + pid + ':timestamp'
|
|
||||||
], function(err, content) {
|
|
||||||
user.getUserField(content[1], 'username', function(username) {
|
user.getUserField(content[1], 'username', function(username) {
|
||||||
var stripped = content[0],
|
var stripped = content[0],
|
||||||
timestamp = content[2];
|
timestamp = content[2];
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ var utils = require('./../public/src/utils.js'),
|
|||||||
|
|
||||||
(function(User) {
|
(function(User) {
|
||||||
User.getUserField = function(uid, field, callback) {
|
User.getUserField = function(uid, field, callback) {
|
||||||
RDB.hget('user:'+uid, field, function(err, data) {
|
RDB.hget('user:' + uid, field, function(err, data) {
|
||||||
if(err === null)
|
if(err === null)
|
||||||
callback(data);
|
callback(data);
|
||||||
else
|
else
|
||||||
@@ -20,7 +20,7 @@ var utils = require('./../public/src/utils.js'),
|
|||||||
}
|
}
|
||||||
|
|
||||||
User.getUserFields = function(uid, fields, callback) {
|
User.getUserFields = function(uid, fields, callback) {
|
||||||
RDB.hmget('user:'+uid, fields, function(err, data) {
|
RDB.hmget('user:' + uid, fields, function(err, data) {
|
||||||
if(err === null) {
|
if(err === null) {
|
||||||
var returnData = {};
|
var returnData = {};
|
||||||
|
|
||||||
|
|||||||
@@ -312,8 +312,13 @@ var express = require('express'),
|
|||||||
/*posts.getPostsByUid(1, 0, 10, function(data) {
|
/*posts.getPostsByUid(1, 0, 10, function(data) {
|
||||||
res.send(data);
|
res.send(data);
|
||||||
});*/
|
});*/
|
||||||
topics.getTopicById(1, 1, function(data) {
|
|
||||||
|
/*topics.getTopicById(1, 1, function(data) {
|
||||||
res.send(data);
|
res.send(data);
|
||||||
|
});*/
|
||||||
|
|
||||||
|
categories.getCategoryById(12, 0, function(returnData) {
|
||||||
|
res.send(returnData);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user