mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +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.getPostField(pid, 'tid', function(err, tid) {
|
||||
Posts.getPidIndex = function(pid, uid, callback) {
|
||||
async.parallel({
|
||||
settings: function(next) {
|
||||
user.getSettings(uid, next);
|
||||
},
|
||||
tid: function(next) {
|
||||
Posts.getPostField(pid, 'tid', next);
|
||||
}
|
||||
}, function(err, results) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
db.sortedSetRank('tid:' + tid + ':posts', pid, function(err, index) {
|
||||
var set = results.settings.topicPostSort === 'most_votes' ? 'tid:' + results.tid + ':posts:votes' : 'tid:' + results.tid + ':posts';
|
||||
db.sortedSetRank(set, pid, function(err, index) {
|
||||
if (!utils.isNumber(index)) {
|
||||
return callback(err, 1);
|
||||
}
|
||||
|
||||
@@ -110,8 +110,6 @@ SocketPosts.sendNotificationToPostOwner = function(pid, fromuid, notification) {
|
||||
|
||||
async.parallel({
|
||||
username: async.apply(user.getUserField, fromuid, 'username'),
|
||||
slug: async.apply(topics.getTopicField, postData.tid, 'slug'),
|
||||
index: async.apply(posts.getPidIndex, pid),
|
||||
postContent: function(next) {
|
||||
async.waterfall([
|
||||
async.apply(posts.getPostField, pid, 'content'),
|
||||
@@ -128,7 +126,7 @@ SocketPosts.sendNotificationToPostOwner = function(pid, fromuid, notification) {
|
||||
notifications.create({
|
||||
bodyShort: '[[' + notification + ', ' + results.username + ']]',
|
||||
bodyLong: results.postContent,
|
||||
path: nconf.get('relative_path') + '/topic/' + results.slug + '/' + results.index,
|
||||
pid: pid,
|
||||
uniqueId: 'post:' + pid + ':uid:' + fromuid,
|
||||
from: fromuid
|
||||
}, function(err, nid) {
|
||||
@@ -274,7 +272,6 @@ SocketPosts.flag = function(socket, pid, callback) {
|
||||
}
|
||||
|
||||
var message = '',
|
||||
path = '',
|
||||
post;
|
||||
|
||||
async.waterfall([
|
||||
@@ -293,21 +290,13 @@ SocketPosts.flag = function(socket, pid, callback) {
|
||||
},
|
||||
function(postData, next) {
|
||||
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);
|
||||
},
|
||||
function(adminGroup, next) {
|
||||
notifications.create({
|
||||
bodyShort: message,
|
||||
bodyLong: post.content,
|
||||
path: path,
|
||||
pid: pid,
|
||||
uniqueId: 'post_flag:' + pid,
|
||||
from: socket.uid
|
||||
}, function(err, nid) {
|
||||
|
||||
@@ -206,6 +206,7 @@ function toggleFollow(method, uid, theiruid, callback) {
|
||||
fromUid: uid,
|
||||
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) {
|
||||
if (err || !pid) {
|
||||
return callback(err);
|
||||
@@ -411,7 +411,7 @@ var async = require('async'),
|
||||
});
|
||||
},
|
||||
postIndex: function(next) {
|
||||
posts.getPidIndex(pid, next);
|
||||
posts.getPidIndex(pid, uid, next);
|
||||
}
|
||||
}, function(err, results) {
|
||||
if (err) {
|
||||
|
||||
@@ -226,7 +226,7 @@ module.exports = function(Topics) {
|
||||
if (settings.followTopicsOnReply) {
|
||||
threadTools.follow(postData.tid, uid);
|
||||
}
|
||||
posts.getPidIndex(postData.pid, next);
|
||||
posts.getPidIndex(postData.pid, uid, next);
|
||||
},
|
||||
function(index, next) {
|
||||
postData.index = index - 1;
|
||||
|
||||
@@ -37,9 +37,8 @@ module.exports = function(Topics) {
|
||||
}
|
||||
|
||||
async.parallel({
|
||||
topicData: async.apply(Topics.getTopicFields, tid, ['title', 'slug']),
|
||||
title: async.apply(Topics.getTopicField, tid, 'title'),
|
||||
username: async.apply(user.getUserField, exceptUid, 'username'),
|
||||
postIndex: async.apply(posts.getPidIndex, pid),
|
||||
postContent: function(next) {
|
||||
async.waterfall([
|
||||
async.apply(posts.getPostField, pid, 'content'),
|
||||
@@ -54,9 +53,9 @@ module.exports = function(Topics) {
|
||||
}
|
||||
|
||||
notifications.create({
|
||||
bodyShort: '[[notifications:user_posted_to, ' + results.username + ', ' + results.topicData.title + ']]',
|
||||
bodyShort: '[[notifications:user_posted_to, ' + results.username + ', ' + results.title + ']]',
|
||||
bodyLong: results.postContent,
|
||||
path: nconf.get('relative_path') + '/topic/' + results.topicData.slug + '/' + results.postIndex,
|
||||
pid: pid,
|
||||
uniqueId: 'topic:' + tid + ':uid:' + exceptUid,
|
||||
tid: tid,
|
||||
from: exceptUid
|
||||
|
||||
@@ -130,11 +130,22 @@ var async = require('async'),
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
var pids = notifications.map(function(notification) {
|
||||
return notification ? notification.pid : null;
|
||||
});
|
||||
|
||||
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;
|
||||
@@ -143,8 +154,50 @@ var async = require('async'),
|
||||
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) {
|
||||
var now = Date.now(),
|
||||
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({
|
||||
username: async.apply(user.getUserField, uid, 'username'),
|
||||
topic: async.apply(topics.getTopicFields, tid, ['slug', 'cid', 'title']),
|
||||
postIndex: async.apply(posts.getPidIndex, pid),
|
||||
topic: async.apply(topics.getTopicFields, tid, ['cid', 'title']),
|
||||
postContent: function(next) {
|
||||
async.waterfall([
|
||||
async.apply(posts.getPostField, pid, 'content'),
|
||||
@@ -246,7 +298,7 @@ var async = require('async'),
|
||||
notifications.create({
|
||||
bodyShort: '[[notifications:user_posted_to, ' + results.username + ', ' + results.topic.title + ']]',
|
||||
bodyLong: results.postContent,
|
||||
path: nconf.get('relative_path') + '/topic/' + results.topic.slug + '/' + results.postIndex,
|
||||
pid: pid,
|
||||
uniqueId: 'topic:' + tid + ':uid:' + uid,
|
||||
tid: tid,
|
||||
from: uid
|
||||
|
||||
Reference in New Issue
Block a user