more work

v1.18.x
Baris Usakli 12 years ago
parent 1a992b7147
commit 9dbaf9fef9

@ -115,111 +115,91 @@ 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');
var retrieved_topics = [];
function getTopicInfoMoar(topicData, callback) {
function getUserNames(next) {
user.getUserField(topicData.uid, 'username', function(username) {
next(null, username);
});
}
function hasReadTopics(next) {
topics.hasReadTopics([topicData.tid], current_user, function(hasRead) {
next(null, hasRead);
});
}
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()
.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 = [];
for(var i=0; i<tids.length; ++i) {
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 getUserNames(next) {
user.get_usernames_by_uids(uid, function(userNames) {
next(null, userNames);
});
}
topics.getTopicData(tids[i], function(topicData) {
function hasReadTopics(next) {
topics.hasReadTopics(tids, current_user, function(hasRead) {
next(null, hasRead);
});
}
getTopicInfoMoar(topicData, function(topicInfo) {
console.log(topicInfo);
function getTeaserInfo(next) {
topics.get_teasers(tids, function(teasers) {
next(null, teasers);
});
}
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' : '';
// 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);
});
}
topicData.relativeTime = utils.relativeTime(topicData.timestamp);
async.parallel([getUserNames, hasReadTopics, getTeaserInfo, getPrivileges], function(err, results) {
var usernames = results[0],
hasReadTopics = 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],
'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)
});
}
}
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);
callback(retrieved_topics);
if(retrieved_topics.length === tids.length)
callback(retrieved_topics);
});
});
}
}
Categories.getAllCategories = function(callback, current_user) {

@ -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];

@ -11,7 +11,7 @@ var utils = require('./../public/src/utils.js'),
(function(User) {
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)
callback(data);
else
@ -20,7 +20,7 @@ var utils = require('./../public/src/utils.js'),
}
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) {
var returnData = {};

@ -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);
});

Loading…
Cancel
Save