mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-04 21:15:55 +01:00
more fixes
This commit is contained in:
@@ -61,27 +61,25 @@
|
||||
});
|
||||
|
||||
|
||||
|
||||
socket.emit('api:categories.getRecentReplies', cid);
|
||||
socket.on('api:categories.getRecentReplies', function(replies) {
|
||||
if (replies === false) {
|
||||
socket.on('api:categories.getRecentReplies', function(posts) {
|
||||
if (!posts || posts.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
var users = replies.users,
|
||||
posts = replies.posts,
|
||||
recent_replies = document.getElementById('category_recent_replies');
|
||||
var recent_replies = document.getElementById('category_recent_replies');
|
||||
|
||||
recent_replies.innerHTML = '';
|
||||
for (var i=0, ii=posts.pids.length; i<ii; i++) {
|
||||
|
||||
for (var i=0, ii=posts.length; i<ii; i++) {
|
||||
|
||||
var a = document.createElement('a'),
|
||||
ul = document.createElement('ul'),
|
||||
username = users[posts.uid[i]].username,
|
||||
picture = users[posts.uid[i]].picture;
|
||||
username = posts[i].username,
|
||||
picture = posts[i].picture;
|
||||
|
||||
//temp until design finalized
|
||||
ul.innerHTML = '<li><img title="' + username + '" style="width: 48px; height: 48px; /*temporary*/" src="' + picture + '" class="" />'
|
||||
+ '<p><strong>' + username + '</strong>: ' + posts.content[i] + '</p><span>posted ' + utils.relativeTime(posts.timestamp[i]) + ' ago</span></li>';
|
||||
+ '<p><strong>' + username + '</strong>: ' + posts[i].content + '</p><span>posted ' + utils.relativeTime(posts[i].timestamp) + ' ago</span></li>';
|
||||
|
||||
a.appendChild(ul);
|
||||
recent_replies.appendChild(a);
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<div class="span12">
|
||||
<div class="post-block">
|
||||
<a class="main-avatar" href="/users/{main_posts.userslug}">
|
||||
<img src="{main_posts.gravatar}?s=80&default=identicon" align="left" /><br />
|
||||
<img src="{main_posts.picture}?s=80&default=identicon" align="left" /><br />
|
||||
<div class="hover-overlay">
|
||||
{main_posts.username}<br />
|
||||
<i class="icon-star"></i><span class="user_rep_{main_posts.uid}">{main_posts.user_rep}</span>
|
||||
@@ -47,7 +47,7 @@
|
||||
<div id="content_{main_posts.pid}" class="post-content">{main_posts.content}</div>
|
||||
<div class="post-signature">{main_posts.signature}</div>
|
||||
<div class="profile-block">
|
||||
<img class="hidden-desktop" src="{main_posts.gravatar}?s=10&default=identicon" align="left" /> posted by <strong><a class="" href="/users/{main_posts.userslug}">{main_posts.username}</a></strong> {main_posts.relativeTime} ago
|
||||
<img class="hidden-desktop" src="{main_posts.picture}?s=10&default=identicon" align="left" /> posted by <strong><a class="" href="/users/{main_posts.userslug}">{main_posts.username}</a></strong> {main_posts.relativeTime} ago
|
||||
<span class="{main_posts.edited-class} hidden-phone">| last edited by <strong><a href="/users/{main_posts.editor}">{main_posts.editor}</a></strong> {main_posts.relativeEditTime} ago</span>
|
||||
<span class="{main_posts.edited-class}"><i class="icon-edit visible-phone" title="edited by {main_posts.editor} {main_posts.relativeEditTime} ago"></i></span>
|
||||
<div class="post-buttons visible-phone">
|
||||
@@ -65,7 +65,7 @@
|
||||
<div class="span1 profile-image-block visible-desktop">
|
||||
<!--<i class="icon-spinner icon-spin icon-2x pull-left"></i>-->
|
||||
<a href="/users/{posts.userslug}">
|
||||
<img src="{posts.gravatar}?s=80&default=identicon" align="left" />
|
||||
<img src="{posts.picture}?s=80&default=identicon" align="left" />
|
||||
</a>
|
||||
<i class="icon-star"></i><span class="user_rep_{posts.uid} formatted-number">{posts.user_rep}</span>
|
||||
<div id="ids_{posts.pid}_{posts.uid}" class="chat hidden-phone" title="Chat"><i class="icon-comment"></i></div>
|
||||
@@ -82,7 +82,7 @@
|
||||
<div id="favs_{posts.pid}_{posts.uid}" class="favourite hidden-phone" title="Favourite"><span class="post_rep_{posts.pid}">{posts.post_rep} </span><i class="{posts.fav_star_class}"></i></div>
|
||||
<div class="post_reply" title="Reply"><i class="icon-reply"></i></div>
|
||||
</span>
|
||||
<img class="hidden-desktop" src="{posts.gravatar}?s=10&default=identicon" align="left" /> posted by <strong><a class="username-field" href="/users/{posts.userslug}">{posts.username}</a></strong> {posts.relativeTime} ago
|
||||
<img class="hidden-desktop" src="{posts.picture}?s=10&default=identicon" align="left" /> posted by <strong><a class="username-field" href="/users/{posts.userslug}">{posts.username}</a></strong> {posts.relativeTime} ago
|
||||
<span class="{posts.edited-class} hidden-phone">| last edited by <strong><a href="/users/{posts.editor}">{posts.editor}</a></strong> {posts.relativeEditTime} ago</span>
|
||||
<span class="{posts.edited-class}"><i class="icon-edit visible-phone" title="edited by {posts.editor} {posts.relativeEditTime} ago"></i></span>
|
||||
</div>
|
||||
|
||||
@@ -273,6 +273,7 @@ var RDB = require('./redis.js'),
|
||||
|
||||
Categories.getRecentReplies = function(cid, callback) {
|
||||
RDB.zrevrange('categories:recent_posts:cid:' + cid, 0, 4, function(err, pids) {
|
||||
|
||||
if (pids.length == 0) {
|
||||
callback(false);
|
||||
return;
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
});
|
||||
}
|
||||
|
||||
async.parallel([getTopicData, getPostsData], function(err, results) {
|
||||
async.parallel([getTopicData], function(err, results) {
|
||||
var topicData = results[0],
|
||||
location = '/topic/' + topicData.slug,
|
||||
xml_url = '/topic/' + tid + '.rss';
|
||||
|
||||
@@ -23,7 +23,7 @@ marked.setOptions({
|
||||
//todo: break early if one condition is true
|
||||
|
||||
function getThreadPrivileges(next) {
|
||||
posts.get_tid_by_pid(pid, function(tid) {
|
||||
posts.getPostField(pid, 'tid', function(tid) {
|
||||
threadTools.privileges(tid, uid, function(privileges) {
|
||||
next(null, privileges);
|
||||
});
|
||||
|
||||
92
src/posts.js
92
src/posts.js
@@ -31,37 +31,42 @@ marked.setOptions({
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Posts.addUserInfoToPost = function(post, callback) {
|
||||
user.getUserFields(post.uid, ['username', 'userslug', 'reputation', 'picture', 'signature'], function(userData) {
|
||||
|
||||
post.username = userData.username || 'anonymous';
|
||||
post.userslug = userData.userslug || '';
|
||||
post.user_rep = userData.reputation || 0;
|
||||
post.picture = userData.picture || 'http://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e';
|
||||
post.signature = marked(userData.signature || '');
|
||||
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
// todo, getPostsByPids has duplicated stuff, have that call this fn - after userinfo calls are pulled out.
|
||||
Posts.getPostSummaryByPids = function(pids, callback) {
|
||||
var content = [], uid = [], timestamp = [];
|
||||
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');
|
||||
}
|
||||
|
||||
RDB.multi()
|
||||
.mget(content)
|
||||
.mget(uid)
|
||||
.mget(timestamp)
|
||||
.exec(function(err, replies) {
|
||||
post_data = {
|
||||
pids: pids,
|
||||
content: replies[0],
|
||||
uid: replies[1],
|
||||
timestamp: replies[2]
|
||||
}
|
||||
|
||||
// below, to be deprecated
|
||||
user.getMultipleUserFields(post_data.uid, ['username','reputation','picture'], function(user_details) {
|
||||
callback({
|
||||
users: user_details,
|
||||
posts: post_data
|
||||
|
||||
var returnData = [];
|
||||
|
||||
var loaded = 0;
|
||||
|
||||
for(var i=0, ii=pids.length; i<ii; ++i) {
|
||||
|
||||
(function(index, pid) {
|
||||
Posts.getPostFields(pids[i], ['pid', 'content', 'uid', 'timestamp'], function(postData) {
|
||||
Posts.addUserInfoToPost(postData, function() {
|
||||
|
||||
returnData[index] = postData;
|
||||
++loaded;
|
||||
|
||||
if(loaded === pids.length) {
|
||||
callback(returnData);
|
||||
}
|
||||
});
|
||||
});
|
||||
// above, to be deprecated
|
||||
});
|
||||
}(i, pids[i]));
|
||||
}
|
||||
};
|
||||
|
||||
Posts.getPostData = function(pid, callback) {
|
||||
@@ -73,6 +78,22 @@ marked.setOptions({
|
||||
});
|
||||
}
|
||||
|
||||
Posts.getPostFields = function(uid, fields, callback) {
|
||||
RDB.hmget('post:' + uid, 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.getPostsByPids = function(pids, callback) {
|
||||
var posts = [],
|
||||
loaded = 0;
|
||||
@@ -95,7 +116,7 @@ marked.setOptions({
|
||||
}
|
||||
|
||||
Posts.getPostField = function(pid, field, callback) {
|
||||
RDB.hget('post:' + pid, field, function(data) {
|
||||
RDB.hget('post:' + pid, field, function(err, data) {
|
||||
if(err === null)
|
||||
callback(data);
|
||||
else
|
||||
@@ -171,7 +192,12 @@ marked.setOptions({
|
||||
RDB.zadd('categories:recent_posts:cid:' + cid, Date.now(), pid);
|
||||
});
|
||||
|
||||
Posts.getTopicPostStats(socket);
|
||||
|
||||
// Send notifications to users who are following this topic
|
||||
threadTools.notify_followers(tid, uid);
|
||||
|
||||
|
||||
socket.emit('event:alert', {
|
||||
title: 'Reply Successful',
|
||||
message: 'You have successfully replied. Click here to view your reply.',
|
||||
@@ -179,10 +205,6 @@ marked.setOptions({
|
||||
timeout: 2000
|
||||
});
|
||||
|
||||
Posts.getTopicPostStats(socket);
|
||||
|
||||
// Send notifications to users who are following this topic
|
||||
threadTools.notify_followers(tid, uid);
|
||||
|
||||
user.getUserFields(uid, ['username','reputation','picture','signature'], function(data) {
|
||||
|
||||
@@ -210,6 +232,8 @@ marked.setOptions({
|
||||
io.sockets.in('topic_' + tid).emit('event:new_post', socketData);
|
||||
io.sockets.in('recent_posts').emit('event:new_post', socketData);
|
||||
|
||||
|
||||
|
||||
});
|
||||
} else {
|
||||
socket.emit('event:alert', {
|
||||
@@ -255,7 +279,6 @@ marked.setOptions({
|
||||
|
||||
RDB.incr('totalpostcount');
|
||||
|
||||
//RDB.get('tid:' + tid + ':cid', function(err, cid) {
|
||||
topics.getTopicField(tid, 'cid', function(cid) {
|
||||
RDB.handle(err);
|
||||
|
||||
@@ -271,8 +294,7 @@ marked.setOptions({
|
||||
});
|
||||
});
|
||||
|
||||
user.onNewPostMade(uid, tid, pid, timestamp);
|
||||
|
||||
user.onNewPostMade(uid, tid, pid, timestamp);
|
||||
|
||||
if (callback)
|
||||
callback(pid);
|
||||
|
||||
@@ -32,25 +32,13 @@ marked.setOptions({
|
||||
});
|
||||
}
|
||||
|
||||
function addUserInfoToPost(post, callback) {
|
||||
user.getUserFields(post.uid, ['username', 'userslug', 'reputation', 'picture', 'signature'], function(userData) {
|
||||
|
||||
post.username = userData.username || 'anonymous';
|
||||
post.userslug = userData.userslug || '';
|
||||
post.user_rep = userData.reputation || 0;
|
||||
post.gravatar = userData.picture || 'http://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e';
|
||||
post.signature = marked(userData.signature || '');
|
||||
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
function constructPosts(topicPosts, callback) {
|
||||
var done = 0;
|
||||
|
||||
for(var i=0, ii=topicPosts.length; i<ii; ++i) {
|
||||
|
||||
addUserInfoToPost(topicPosts[i], function() {
|
||||
posts.addUserInfoToPost(topicPosts[i], function() {
|
||||
++done;
|
||||
if(done === topicPosts.length)
|
||||
callback();
|
||||
@@ -393,6 +381,8 @@ marked.setOptions({
|
||||
type: 'notify',
|
||||
timeout: 2000
|
||||
});
|
||||
|
||||
console.log('topic posted');
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -335,7 +335,10 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
||||
topics.get_topic(data.tid, uid, function(topicData) {
|
||||
topicData.tid = data.tid;
|
||||
if (data.body) topicData.body = data.body;
|
||||
socket.emit('api:composer.push', topicData);
|
||||
socket.emit('api:composer.push', {
|
||||
tid: data.tid,
|
||||
title: topicData.title
|
||||
});
|
||||
});
|
||||
} else if (parseInt(data.cid) > 0) {
|
||||
user.getUserField(uid, 'username', function(username) {
|
||||
|
||||
Reference in New Issue
Block a user