From 6aa53b83233d0a31d408b43e40fb2d1453b1eb5b Mon Sep 17 00:00:00 2001 From: barisusakli Date: Thu, 2 Oct 2014 17:46:39 -0400 Subject: [PATCH] nextStart changes, fixed move topic notification text --- public/language/en_GB/notifications.json | 4 +-- src/categories.js | 14 +++-------- src/controllers/tags.js | 1 + src/messaging.js | 8 +----- src/posts.js | 31 ++++++++++++------------ src/topics.js | 26 ++++++++++---------- src/topics/recent.js | 11 +++++++-- src/topics/unread.js | 12 +++------ 8 files changed, 49 insertions(+), 58 deletions(-) diff --git a/public/language/en_GB/notifications.json b/public/language/en_GB/notifications.json index 3cb6ac6872..6e35eac76a 100644 --- a/public/language/en_GB/notifications.json +++ b/public/language/en_GB/notifications.json @@ -13,8 +13,8 @@ "new_message_from": "New message from %1", "upvoted_your_post_in": "%1 has upvoted your post in %2.", - "moved_your_post": "%1 has moved your post.", - "moved_your_topic": "%1 has moved your topic.", + "moved_your_post": "%1 has moved your post.", + "moved_your_topic": "%1 has moved your topic.", "favourited_your_post_in": "%1 has favourited your post in %2.", "user_flagged_post_in": "%1 flagged a post in %2", "user_posted_to" : "%1 has posted a reply to: %2", diff --git a/src/categories.js b/src/categories.js index 2a80c4a67b..f6599d64ad 100644 --- a/src/categories.js +++ b/src/categories.js @@ -114,7 +114,7 @@ var db = require('./database'), topics.getTopicsByTids(tids, uid, next); }, function(topics, next) { - if (!topics || !topics.length) { + if (!Array.isArray(topics) || !topics.length) { return next(null, { topics: [], nextStart: 1 @@ -131,15 +131,9 @@ var db = require('./database'), topics[i].index = indices[topics[i].tid]; } - db.sortedSetRevRank('categories:' + cid + ':tid', topics[topics.length - 1].tid, function(err, rank) { - if(err) { - return next(err); - } - - next(null, { - topics: topics, - nextStart: parseInt(rank, 10) + 1 - }); + next(null, { + topics: topics, + nextStart: stop + 1 }); } ], callback); diff --git a/src/controllers/tags.js b/src/controllers/tags.js index 755ede4b91..53b418f6b9 100644 --- a/src/controllers/tags.js +++ b/src/controllers/tags.js @@ -42,6 +42,7 @@ tagsController.getTag = function(req, res, next) { ]; data.tag = tag; + data.nextStart = end + 1; res.render('tag', data); }); }); diff --git a/src/messaging.js b/src/messaging.js index e47270d5da..4547c1d981 100644 --- a/src/messaging.js +++ b/src/messaging.js @@ -260,13 +260,7 @@ var db = require('./database'), } }); - db.sortedSetRevRank('uid:' + uid + ':chats', results.users[results.users.length - 1].uid, function(err, rank) { - if (err) { - return callback(err); - } - - callback(null, {users: results.users, nextStart: rank + 1}); - }); + callback(null, {users: results.users, nextStart: end + 1}); }); }); }; diff --git a/src/posts.js b/src/posts.js index d9743e0642..6d6089f732 100644 --- a/src/posts.js +++ b/src/posts.js @@ -469,7 +469,12 @@ var async = require('async'), if (err) { return callback(err); } - getPostsFromSet('uid:' + uid + ':posts', pids, callerUid, callback); + getPosts(pids, callerUid, function(err, posts) { + if (err) { + return callback(err); + } + callback(null, {posts: posts, nextStart: end + 1}); + }); }); }); }; @@ -480,13 +485,18 @@ var async = require('async'), return callback(err); } - getPostsFromSet('uid:' + uid + ':favourites', pids, uid, callback); + getPosts(pids, uid, function(err, posts) { + if (err) { + return callback(err); + } + callback(null, {posts: posts, nextStart: end + 1}); + }); }); }; - function getPostsFromSet(set, pids, uid, callback) { + function getPosts(pids, uid, callback) { if (!Array.isArray(pids) || !pids.length) { - return callback(null, {posts: [], nextStart: 0}); + return callback(null, []); } Posts.getPostSummaryByPids(pids, uid, {stripTags: false}, function(err, posts) { @@ -495,19 +505,10 @@ var async = require('async'), } if (!Array.isArray(posts) || !posts.length) { - return callback(null, {posts: [], nextStart: 0}); + return callback(null, []); } - db.sortedSetRevRank(set, posts[posts.length - 1].pid, function(err, rank) { - if(err) { - return callback(err); - } - var data = { - posts: posts, - nextStart: parseInt(rank, 10) + 1 - }; - callback(null, data); - }); + callback(null, posts); }); } diff --git a/src/topics.js b/src/topics.js index da8ffb4776..3cfdd959a1 100644 --- a/src/topics.js +++ b/src/topics.js @@ -140,34 +140,34 @@ var async = require('async'), } Topics.getTopicsByTids(tids, uid, function(err, topicData) { - if(err) { + if (err) { return callback(err); } - if(!topicData || !topicData.length) { + if(!Array.isArray(topicData) || !topicData.length) { return callback(null, returnTopics); } - db.sortedSetRevRank(set, topicData[topicData.length - 1].tid, function(err, rank) { - if(err) { - return callback(err); - } - - returnTopics.nextStart = parseInt(rank, 10) + 1; - returnTopics.topics = topicData; - callback(null, returnTopics); - }); + returnTopics.topics = topicData; + callback(null, returnTopics); }); }); }; Topics.getTopicsFromSet = function(uid, set, start, end, callback) { db.getSortedSetRevRange(set, start, end, function(err, tids) { - if(err) { + if (err) { return callback(err); } - Topics.getTopics(set, uid, tids, callback); + Topics.getTopics(set, uid, tids, function(err, data) { + if (err) { + return callback(err); + } + + data.nextStart = end + 1; + callback(null, data); + }); }); }; diff --git a/src/topics/recent.js b/src/topics/recent.js index e94dbe23a8..c8b6b551bc 100644 --- a/src/topics/recent.js +++ b/src/topics/recent.js @@ -17,11 +17,18 @@ module.exports = function(Topics) { Topics.getLatestTopics = function(uid, start, end, term, callback) { Topics.getLatestTids(start, end, term, function(err, tids) { - if(err) { + if (err) { return callback(err); } - Topics.getTopics('topics:recent', uid, tids, callback); + Topics.getTopics('topics:recent', uid, tids, function(err, data) { + if (err) { + return callback(err); + } + + data.nextStart = end + 1; + callback(null, data); + }); }); }; diff --git a/src/topics/unread.js b/src/topics/unread.js index 7777f82ae5..4e8bc509d2 100644 --- a/src/topics/unread.js +++ b/src/topics/unread.js @@ -45,16 +45,10 @@ module.exports = function(Topics) { return callback(null, unreadTopics); } - db.sortedSetRevRank('topics:recent', topicData[topicData.length - 1].tid, function(err, rank) { - if (err) { - return callback(err); - } + unreadTopics.topics = topicData; + unreadTopics.nextStart = stop + 1; - unreadTopics.topics = topicData; - unreadTopics.nextStart = parseInt(rank, 10) + 1; - - callback(null, unreadTopics); - }); + callback(null, unreadTopics); }); }); };