Baris Usakli 12 years ago
commit 8a2499a423

@ -48,7 +48,7 @@
<div class="block-header">
Recent Replies
</div>
<div class="block-content">
<div class="block-content" id="category_recent_replies">
</div>
</div>
@ -82,6 +82,7 @@
<script type="text/javascript">
(function() {
var cid = '{category_id}';
var room = 'category_' + '{category_id}';
app.enter_room(room);
@ -129,9 +130,10 @@
//socket.emit('api:topics.getRecentReplies', tid);
socket.on('api:topics.getRecentReplies', function(replies) {
socket.emit('api:categories.getRecentReplies', cid);
socket.on('api:categories.getRecentReplies', function(replies) {
console.log(replies);
jQuery('#category_recent_replies')
});
})();

@ -259,7 +259,11 @@ var RDB = require('./redis.js'),
});
}
Categories.getRecentReplies = function(cid, callback) {
RDB.zrange('categories:recent_posts:cid:' + cid, 0, -1, function(err, replies) {
callback(replies);
});
}
Categories.getCategories = function(cids, callback, current_user) {
if (cids.length === 0) {

@ -23,74 +23,87 @@ marked.setOptions({
}
topics.markAsRead(tid, current_user);
Posts.getPostsByPids(pids, current_user, function(posts) {
callback(posts);
})
var content = [], uid = [], timestamp = [], pid = [], post_rep = [], editor = [], editTime = [], deleted = [];
for (var i=0, ii=pids.length; i<ii; i++) {
content.push('pid:' + pids[i] + ':content');
uid.push('pid:' + pids[i] + ':uid');
timestamp.push('pid:' + pids[i] + ':timestamp');
post_rep.push('pid:' + pids[i] + ':rep');
editor.push('pid:' + pids[i] + ':editor');
editTime.push('pid:' + pids[i] + ':edited');
deleted.push('pid:' + pids[i] + ':deleted');
pid.push(pids[i]);
}
});
}
// todo, getPostsByPids has duplicated stuff, have that call this fn.
Posts.getPostSummaryByPids = function(pids, callback) {
var content = [], uid = [], timestamp = [];
};
Posts.getPostsByPids = function(pids, current_user, callback) {
var content = [], uid = [], timestamp = [], post_rep = [], editor = [], editTime = [], deleted = [];
for (var i=0, ii=pids.length; i<ii; i++) {
content.push('pid:' + pids[i] + ':content');
uid.push('pid:' + pids[i] + ':uid');
timestamp.push('pid:' + pids[i] + ':timestamp');
post_rep.push('pid:' + pids[i] + ':rep');
editor.push('pid:' + pids[i] + ':editor');
editTime.push('pid:' + pids[i] + ':edited');
deleted.push('pid:' + pids[i] + ':deleted');
}
function getFavouritesData(next) {
favourites.getFavouritesByPostIDs(pids, current_user, function(fav_data) {
next(null, fav_data);
}); // to be moved
}
function getPostData(next) {
RDB.multi()
.mget(content)
.mget(uid)
.mget(timestamp)
.mget(post_rep)
.mget(editor)
.mget(editTime)
.mget(deleted)
.exec(function(err, replies) {
post_data = {
pid: pids,
content: replies[0],
uid: replies[1],
timestamp: replies[2],
reputation: replies[3],
editor: replies[4],
editTime: replies[5],
deleted: replies[6]
};
// below, to be deprecated
// Add any editors to the user_data object
for(var x = 0, numPosts = post_data.editor.length; x < numPosts; x++) {
if (post_data.editor[x] !== null && post_data.uid.indexOf(post_data.editor[x]) === -1) {
post_data.uid.push(post_data.editor[x]);
}
function getFavouritesData(next) {
favourites.getFavouritesByPostIDs(pids, current_user, function(fav_data) {
next(null, fav_data);
}); // to be moved
}
function getPostData(next) {
RDB.multi()
.mget(content)
.mget(uid)
.mget(timestamp)
.mget(post_rep)
.mget(editor)
.mget(editTime)
.mget(deleted)
.exec(function(err, replies) {
post_data = {
pid: pids,
content: replies[0],
uid: replies[1],
timestamp: replies[2],
reputation: replies[3],
editor: replies[4],
editTime: replies[5],
deleted: replies[6]
};
// below, to be deprecated
// Add any editors to the user_data object
for(var x = 0, numPosts = post_data.editor.length; x < numPosts; x++) {
if (post_data.editor[x] !== null && post_data.uid.indexOf(post_data.editor[x]) === -1) {
post_data.uid.push(post_data.editor[x]);
}
}
user.getMultipleUserFields(post_data.uid, ['username','reputation','picture', 'signature'], function(user_details) {
next(null, {
users: user_details,
posts: post_data
});
user.getMultipleUserFields(post_data.uid, ['username','reputation','picture', 'signature'], function(user_details) {
next(null, {
users: user_details,
posts: post_data
});
// above, to be deprecated
});
}
async.parallel([getFavouritesData, getPostData], function(err, results) {
callback({
'voteData' : results[0], // to be moved
'userData' : results[1].users, // to be moved
'postData' : results[1].posts
// above, to be deprecated
});
});
}
async.parallel([getFavouritesData, getPostData], function(err, results) {
callback({
'voteData' : results[0], // to be moved
'userData' : results[1].users, // to be moved
'postData' : results[1].posts
});
});
}
@ -127,8 +140,8 @@ marked.setOptions({
return;
}
user.getUserField(uid, 'lastposttime', function(lastposttime) {
user.getUserField(uid, 'lastposttime', function(lastposttime) {
if(new Date().getTime() - lastposttime < config.post_delay) {
socket.emit('event:alert', {
title: 'Too many posts!',

@ -37,4 +37,29 @@
});
};
/*
* A lot of redis calls come back like this:
* [key, value, key, value, key, value]
* this is a simple utility fn to turn this into an object.
*/
RedisDB.exports.objectify = function(arr) {
var obj = {};
for (var i = 0; i < arr.length; i += 2) {
obj[arr[i]] = arr[i+1];
}
return obj;
};
/*
* Similar to .objectify, this utility function splits the data array into two arrays
*/
RedisDB.exports.splitify = function(arr) {
var arr1 = [], arr2 = [];
for (var i = 0; i < arr.length; i += 2) {
arr1.push(arr[i]);
arr2.push(arr[i+1]);
}
return [arr1,arr2];
};
}(module));

@ -273,11 +273,6 @@ marked.setOptions({
});
}
Topics.getRecentReplies = function(tid, callback) {
RDB.zrange('topics:recent_posts:tid:' + tid, 0, -1, 'WITHSCORES', function(err, replies) {
callback(replies);
});
}
Topics.post = function(socket, uid, title, content, category_id) {
if (!category_id) throw new Error('Attempted to post without a category_id');

@ -263,10 +263,9 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
notifications.mark_read(nid, uid);
});
socket.on('api:topics.getRecentReplies', function(tid) {
console.log('test');
topics.getRecentReplies(tid, function(replies) {
socket.emit('api:topics.getRecentReplies', replies);
socket.on('api:categories.getRecentReplies', function(tid) {
categories.getRecentReplies(tid, function(replies) {
socket.emit('api:categories.getRecentReplies', replies);
});
});

Loading…
Cancel
Save