mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
closes #1993
This commit is contained in:
15
src/posts.js
15
src/posts.js
@@ -522,13 +522,20 @@ var async = require('async'),
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Posts.getPidIndex = function(pid, callback) {
|
Posts.getPidIndex = function(pid, uid, callback) {
|
||||||
Posts.getPostField(pid, 'tid', function(err, tid) {
|
async.parallel({
|
||||||
|
settings: function(next) {
|
||||||
|
user.getSettings(uid, next);
|
||||||
|
},
|
||||||
|
tid: function(next) {
|
||||||
|
Posts.getPostField(pid, 'tid', next);
|
||||||
|
}
|
||||||
|
}, function(err, results) {
|
||||||
if(err) {
|
if(err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
var set = results.settings.topicPostSort === 'most_votes' ? 'tid:' + results.tid + ':posts:votes' : 'tid:' + results.tid + ':posts';
|
||||||
db.sortedSetRank('tid:' + tid + ':posts', pid, function(err, index) {
|
db.sortedSetRank(set, pid, function(err, index) {
|
||||||
if (!utils.isNumber(index)) {
|
if (!utils.isNumber(index)) {
|
||||||
return callback(err, 1);
|
return callback(err, 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,8 +110,6 @@ SocketPosts.sendNotificationToPostOwner = function(pid, fromuid, notification) {
|
|||||||
|
|
||||||
async.parallel({
|
async.parallel({
|
||||||
username: async.apply(user.getUserField, fromuid, 'username'),
|
username: async.apply(user.getUserField, fromuid, 'username'),
|
||||||
slug: async.apply(topics.getTopicField, postData.tid, 'slug'),
|
|
||||||
index: async.apply(posts.getPidIndex, pid),
|
|
||||||
postContent: function(next) {
|
postContent: function(next) {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
async.apply(posts.getPostField, pid, 'content'),
|
async.apply(posts.getPostField, pid, 'content'),
|
||||||
@@ -128,7 +126,7 @@ SocketPosts.sendNotificationToPostOwner = function(pid, fromuid, notification) {
|
|||||||
notifications.create({
|
notifications.create({
|
||||||
bodyShort: '[[' + notification + ', ' + results.username + ']]',
|
bodyShort: '[[' + notification + ', ' + results.username + ']]',
|
||||||
bodyLong: results.postContent,
|
bodyLong: results.postContent,
|
||||||
path: nconf.get('relative_path') + '/topic/' + results.slug + '/' + results.index,
|
pid: pid,
|
||||||
uniqueId: 'post:' + pid + ':uid:' + fromuid,
|
uniqueId: 'post:' + pid + ':uid:' + fromuid,
|
||||||
from: fromuid
|
from: fromuid
|
||||||
}, function(err, nid) {
|
}, function(err, nid) {
|
||||||
@@ -274,7 +272,6 @@ SocketPosts.flag = function(socket, pid, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var message = '',
|
var message = '',
|
||||||
path = '',
|
|
||||||
post;
|
post;
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
@@ -293,21 +290,13 @@ SocketPosts.flag = function(socket, pid, callback) {
|
|||||||
},
|
},
|
||||||
function(postData, next) {
|
function(postData, next) {
|
||||||
post = postData;
|
post = postData;
|
||||||
topics.getTopicField(postData.tid, 'slug', next);
|
|
||||||
},
|
|
||||||
function(topicSlug, next) {
|
|
||||||
path = nconf.get('relative_path') + '/topic/' + topicSlug;
|
|
||||||
posts.getPidIndex(pid, next);
|
|
||||||
},
|
|
||||||
function(postIndex, next) {
|
|
||||||
path += '/' + postIndex;
|
|
||||||
groups.get('administrators', {}, next);
|
groups.get('administrators', {}, next);
|
||||||
},
|
},
|
||||||
function(adminGroup, next) {
|
function(adminGroup, next) {
|
||||||
notifications.create({
|
notifications.create({
|
||||||
bodyShort: message,
|
bodyShort: message,
|
||||||
bodyLong: post.content,
|
bodyLong: post.content,
|
||||||
path: path,
|
pid: pid,
|
||||||
uniqueId: 'post_flag:' + pid,
|
uniqueId: 'post_flag:' + pid,
|
||||||
from: socket.uid
|
from: socket.uid
|
||||||
}, function(err, nid) {
|
}, function(err, nid) {
|
||||||
|
|||||||
@@ -206,6 +206,7 @@ function toggleFollow(method, uid, theiruid, callback) {
|
|||||||
fromUid: uid,
|
fromUid: uid,
|
||||||
toUid: theiruid
|
toUid: theiruid
|
||||||
});
|
});
|
||||||
|
callback();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -386,7 +386,7 @@ var async = require('async'),
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Topics.getTeaser = function(tid, callback) {
|
Topics.getTeaser = function(tid, uid, callback) {
|
||||||
Topics.getLatestUndeletedPid(tid, function(err, pid) {
|
Topics.getLatestUndeletedPid(tid, function(err, pid) {
|
||||||
if (err || !pid) {
|
if (err || !pid) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
@@ -411,7 +411,7 @@ var async = require('async'),
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
postIndex: function(next) {
|
postIndex: function(next) {
|
||||||
posts.getPidIndex(pid, next);
|
posts.getPidIndex(pid, uid, next);
|
||||||
}
|
}
|
||||||
}, function(err, results) {
|
}, function(err, results) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|||||||
@@ -226,7 +226,7 @@ module.exports = function(Topics) {
|
|||||||
if (settings.followTopicsOnReply) {
|
if (settings.followTopicsOnReply) {
|
||||||
threadTools.follow(postData.tid, uid);
|
threadTools.follow(postData.tid, uid);
|
||||||
}
|
}
|
||||||
posts.getPidIndex(postData.pid, next);
|
posts.getPidIndex(postData.pid, uid, next);
|
||||||
},
|
},
|
||||||
function(index, next) {
|
function(index, next) {
|
||||||
postData.index = index - 1;
|
postData.index = index - 1;
|
||||||
|
|||||||
@@ -37,9 +37,8 @@ module.exports = function(Topics) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async.parallel({
|
async.parallel({
|
||||||
topicData: async.apply(Topics.getTopicFields, tid, ['title', 'slug']),
|
title: async.apply(Topics.getTopicField, tid, 'title'),
|
||||||
username: async.apply(user.getUserField, exceptUid, 'username'),
|
username: async.apply(user.getUserField, exceptUid, 'username'),
|
||||||
postIndex: async.apply(posts.getPidIndex, pid),
|
|
||||||
postContent: function(next) {
|
postContent: function(next) {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
async.apply(posts.getPostField, pid, 'content'),
|
async.apply(posts.getPostField, pid, 'content'),
|
||||||
@@ -54,9 +53,9 @@ module.exports = function(Topics) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
notifications.create({
|
notifications.create({
|
||||||
bodyShort: '[[notifications:user_posted_to, ' + results.username + ', ' + results.topicData.title + ']]',
|
bodyShort: '[[notifications:user_posted_to, ' + results.username + ', ' + results.title + ']]',
|
||||||
bodyLong: results.postContent,
|
bodyLong: results.postContent,
|
||||||
path: nconf.get('relative_path') + '/topic/' + results.topicData.slug + '/' + results.postIndex,
|
pid: pid,
|
||||||
uniqueId: 'topic:' + tid + ':uid:' + exceptUid,
|
uniqueId: 'topic:' + tid + ':uid:' + exceptUid,
|
||||||
tid: tid,
|
tid: tid,
|
||||||
from: exceptUid
|
from: exceptUid
|
||||||
|
|||||||
@@ -130,21 +130,74 @@ var async = require('async'),
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
notifications = notifications.map(function(notification, index) {
|
var pids = notifications.map(function(notification) {
|
||||||
if (!notification) {
|
return notification ? notification.pid : null;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
notification.read = hasRead[index];
|
|
||||||
notification.datetimeISO = utils.toISOString(notification.datetime);
|
|
||||||
notification.readClass = !notification.read ? 'label-warning' : '';
|
|
||||||
return notification;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
callback(null, notifications);
|
generatePostPaths(pids, uid, function(err, paths) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
notifications = notifications.map(function(notification, index) {
|
||||||
|
if (!notification) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
notification.read = hasRead[index];
|
||||||
|
notification.path = paths[index] || notification.path || '';
|
||||||
|
notification.datetimeISO = utils.toISOString(notification.datetime);
|
||||||
|
notification.readClass = !notification.read ? 'label-warning' : '';
|
||||||
|
return notification;
|
||||||
|
});
|
||||||
|
|
||||||
|
callback(null, notifications);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function generatePostPaths(pids, uid, callback) {
|
||||||
|
var postKeys = pids.map(function(pid) {
|
||||||
|
return 'post:' + pid;
|
||||||
|
});
|
||||||
|
|
||||||
|
db.getObjectsFields(postKeys, ['pid', 'tid'], function(err, postData) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
var topicKeys = postData.map(function(post) {
|
||||||
|
return post ? 'topic:' + post.tid : null;
|
||||||
|
});
|
||||||
|
|
||||||
|
async.parallel({
|
||||||
|
indices: function(next) {
|
||||||
|
posts.getPostIndices(postData, uid, next);
|
||||||
|
},
|
||||||
|
topics: function(next) {
|
||||||
|
db.getObjectsFields(topicKeys, ['slug'], next);
|
||||||
|
}
|
||||||
|
}, function(err, results) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
var paths = [];
|
||||||
|
pids.forEach(function(pid, index) {
|
||||||
|
var slug = results.topics[index] ? results.topics[index].slug : null;
|
||||||
|
var postIndex = results.indices[index] ? parseInt(results.indices[index], 10) + 1 : null;
|
||||||
|
if (slug && postIndex) {
|
||||||
|
paths.push(nconf.get('relative_path') + '/topic/' + slug + '/' + postIndex);
|
||||||
|
} else {
|
||||||
|
paths.push(null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
callback(null, paths);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
UserNotifications.getDailyUnread = function(uid, callback) {
|
UserNotifications.getDailyUnread = function(uid, callback) {
|
||||||
var now = Date.now(),
|
var now = Date.now(),
|
||||||
yesterday = now - (1000*60*60*24); // Approximate, can be more or less depending on time changes, makes no difference really.
|
yesterday = now - (1000*60*60*24); // Approximate, can be more or less depending on time changes, makes no difference really.
|
||||||
@@ -221,8 +274,7 @@ var async = require('async'),
|
|||||||
|
|
||||||
async.parallel({
|
async.parallel({
|
||||||
username: async.apply(user.getUserField, uid, 'username'),
|
username: async.apply(user.getUserField, uid, 'username'),
|
||||||
topic: async.apply(topics.getTopicFields, tid, ['slug', 'cid', 'title']),
|
topic: async.apply(topics.getTopicFields, tid, ['cid', 'title']),
|
||||||
postIndex: async.apply(posts.getPidIndex, pid),
|
|
||||||
postContent: function(next) {
|
postContent: function(next) {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
async.apply(posts.getPostField, pid, 'content'),
|
async.apply(posts.getPostField, pid, 'content'),
|
||||||
@@ -246,7 +298,7 @@ var async = require('async'),
|
|||||||
notifications.create({
|
notifications.create({
|
||||||
bodyShort: '[[notifications:user_posted_to, ' + results.username + ', ' + results.topic.title + ']]',
|
bodyShort: '[[notifications:user_posted_to, ' + results.username + ', ' + results.topic.title + ']]',
|
||||||
bodyLong: results.postContent,
|
bodyLong: results.postContent,
|
||||||
path: nconf.get('relative_path') + '/topic/' + results.topic.slug + '/' + results.postIndex,
|
pid: pid,
|
||||||
uniqueId: 'topic:' + tid + ':uid:' + uid,
|
uniqueId: 'topic:' + tid + ':uid:' + uid,
|
||||||
tid: tid,
|
tid: tid,
|
||||||
from: uid
|
from: uid
|
||||||
|
|||||||
Reference in New Issue
Block a user