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,66 +115,24 @@ var RDB = require('./redis.js'),
|
||||
|
||||
// not the permanent location for this function
|
||||
Categories.getTopicsByTids = function(tids, current_user, callback, category_id /*temporary*/) {
|
||||
var title = [],
|
||||
uid = [],
|
||||
timestamp = [],
|
||||
lastposttime = [],
|
||||
slug = [],
|
||||
postcount = [],
|
||||
locked = [],
|
||||
deleted = [],
|
||||
pinned = [];
|
||||
|
||||
for (var i=0, ii=tids.length; i<ii; i++) {
|
||||
title.push('tid:' + tids[i] + ':title');
|
||||
uid.push('tid:' + tids[i] + ':uid');
|
||||
timestamp.push('tid:' + tids[i] + ':timestamp');
|
||||
lastposttime.push('tid:' + tids[i] + ':lastposttime');
|
||||
slug.push('tid:' + tids[i] + ':slug');
|
||||
postcount.push('tid:' + tids[i] + ':postcount');
|
||||
locked.push('tid:' + tids[i] + ':locked');
|
||||
deleted.push('tid:' + tids[i] + ':deleted');
|
||||
pinned.push('tid:' + tids[i] + ':pinned');
|
||||
}
|
||||
|
||||
|
||||
RDB.multi()
|
||||
.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];
|
||||
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 getTopicInfoMoar(topicData, callback) {
|
||||
|
||||
function getUserNames(next) {
|
||||
user.get_usernames_by_uids(uid, function(userNames) {
|
||||
next(null, userNames);
|
||||
user.getUserField(topicData.uid, 'username', function(username) {
|
||||
next(null, username);
|
||||
});
|
||||
}
|
||||
|
||||
function hasReadTopics(next) {
|
||||
topics.hasReadTopics(tids, current_user, function(hasRead) {
|
||||
topics.hasReadTopics([topicData.tid], current_user, function(hasRead) {
|
||||
next(null, hasRead);
|
||||
});
|
||||
}
|
||||
|
||||
function getTeaserInfo(next) {
|
||||
topics.get_teasers(tids, function(teasers) {
|
||||
topics.get_teasers([topicData.tid], function(teasers) {
|
||||
next(null, teasers);
|
||||
});
|
||||
}
|
||||
@@ -187,41 +145,63 @@ var RDB = require('./redis.js'),
|
||||
}
|
||||
|
||||
async.parallel([getUserNames, hasReadTopics, getTeaserInfo, getPrivileges], function(err, results) {
|
||||
var usernames = results[0],
|
||||
hasReadTopics = results[1],
|
||||
var username = results[0],
|
||||
hasReadTopic = results[1],
|
||||
teaserInfo = results[2],
|
||||
privileges = results[3];
|
||||
|
||||
for (var i=0, ii=tids.length; i<ii; i++) {
|
||||
if (!deleted[i] || (deleted[i] && privileges.view_deleted) || uid[i] === current_user) {
|
||||
retrieved_topics.push({
|
||||
'tid' : tids[i],
|
||||
'title' : title[i],
|
||||
'uid' : uid[i],
|
||||
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],
|
||||
'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)
|
||||
});*/
|
||||
//}
|
||||
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for(var i=0; i<tids.length; ++i) {
|
||||
|
||||
topics.getTopicData(tids[i], function(topicData) {
|
||||
|
||||
getTopicInfoMoar(topicData, function(topicInfo) {
|
||||
console.log(topicInfo);
|
||||
|
||||
topicData['pin-icon'] = topicData.pinned === '1' ? 'icon-pushpin' : 'none';
|
||||
topicData['lock-icon'] = topicData.locked === '1' ? 'icon-lock' : 'none';
|
||||
topicData['deleted-class'] = topicData.deleted === '1' ? 'deleted' : '';
|
||||
|
||||
topicData.relativeTime = utils.relativeTime(topicData.timestamp);
|
||||
|
||||
topicData.username = topicInfo.username;
|
||||
topicData.badgeclass = (topicInfo.hasread && current_user != 0) ? '' : 'badge-important';
|
||||
topicData.teaser_text = topicInfo.teaserInfo.text,
|
||||
topicData.teaser_username = topicInfo.teaserInfo.username;
|
||||
topicData.teaser_timestamp = utils.relativeTime(topicInfo.teaserInfo.timestamp);
|
||||
|
||||
retrieved_topics.push(topicData);
|
||||
|
||||
if(retrieved_topics.length === tids.length)
|
||||
callback(retrieved_topics);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Categories.getAllCategories = function(callback, current_user) {
|
||||
RDB.lrange('categories:cid', 0, -1, function(err, cids) {
|
||||
RDB.handle(err);
|
||||
|
||||
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.getPostField(pid, 'tid', function(tid) {
|
||||
|
||||
@@ -303,11 +303,9 @@ marked.setOptions({
|
||||
Topics.get_teaser = function(tid, callback) {
|
||||
Topics.get_latest_undeleted_pid(tid, function(pid) {
|
||||
if (pid !== null) {
|
||||
RDB.mget([
|
||||
'pid:' + pid + ':content',
|
||||
'pid:' + pid + ':uid',
|
||||
'pid:' + pid + ':timestamp'
|
||||
], function(err, content) {
|
||||
|
||||
posts.getPostFields(pid, ['content', 'uid', 'timestamp'], function(content) {
|
||||
|
||||
user.getUserField(content[1], 'username', function(username) {
|
||||
var stripped = content[0],
|
||||
timestamp = content[2];
|
||||
|
||||
@@ -312,8 +312,13 @@ var express = require('express'),
|
||||
/*posts.getPostsByUid(1, 0, 10, function(data) {
|
||||
res.send(data);
|
||||
});*/
|
||||
topics.getTopicById(1, 1, function(data) {
|
||||
|
||||
/*topics.getTopicById(1, 1, function(data) {
|
||||
res.send(data);
|
||||
});*/
|
||||
|
||||
categories.getCategoryById(12, 0, function(returnData) {
|
||||
res.send(returnData);
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user