Skip to content

Node.js based forum software built for the modern web

closes #2146

barisusakli433769eb364b
diff --git a/public/src/modules/chat.js b/public/src/modules/chat.js
index 8922e90df4..30c7e163e5 100644
--- a/public/src/modules/chat.js
+++ b/public/src/modules/chat.js
@@ -295,7 +295,7 @@ define('chat', ['taskbar', 'string', 'sounds', 'forum/chats'], function(taskbar,
};
function getChatMessages(chatModal, callback) {
- socket.emit('modules.chats.get', {touid: chatModal.attr('touid'), since: 'day'}, function(err, messages) {
+ socket.emit('modules.chats.get', {touid: chatModal.attr('touid'), since: 'recent'}, function(err, messages) {
module.appendChatMessage(chatModal, messages, callback);
});
}
diff --git a/src/controllers/accounts.js b/src/controllers/accounts.js
index f211027412..867b208989 100644
--- a/src/controllers/accounts.js
+++ b/src/controllers/accounts.js
@@ -553,7 +553,7 @@ accountsController.getChats = function(req, res, next) {
function(toUid, next) {
async.parallel({
toUser: async.apply(user.getUserFields, toUid, ['uid', 'username']),
- messages: async.apply(messaging.getMessages, req.user.uid, toUid, 'day', false)
+ messages: async.apply(messaging.getMessages, req.user.uid, toUid, 'recent', false)
}, next);
}
], function(err, data) {
diff --git a/src/messaging.js b/src/messaging.js
index c696ceaeb1..e7ccbeabdc 100644
--- a/src/messaging.js
+++ b/src/messaging.js
@@ -16,6 +16,13 @@ var db = require('./database'),
(function(Messaging) {
Messaging.notifyQueue = {}; // Only used to notify a user of a new chat message, see Messaging.notifyUser
+ var terms = {
+ day: 86400000,
+ week: 604800000,
+ month: 2592000000,
+ threemonths: 7776000000
+ };
+
function sortUids(fromuid, touid) {
return [fromuid, touid].sort();
}
@@ -80,15 +87,14 @@ var db = require('./database'),
Messaging.getMessages = function(fromuid, touid, since, isNew, callback) {
var uids = sortUids(fromuid, touid);
- var terms = {
- day: 86400000,
- week: 604800000,
- month: 2592000000,
- threemonths: 7776000000
- };
- since = terms[since] || terms.day;
var count = parseInt(meta.config.chatMessageInboxSize, 10) || 250;
- db.getSortedSetRevRangeByScore('messages:uid:' + uids[0] + ':to:' + uids[1], 0, count, Infinity, Date.now() - since, function(err, mids) {
+ var min = Date.now() - (terms[since] || terms.day);
+ if (since === 'recent') {
+ count = 49;
+ min = 0;
+ }
+
+ db.getSortedSetRevRangeByScore('messages:uid:' + uids[0] + ':to:' + uids[1], 0, count, Infinity, min, function(err, mids) {
if (err) {
return callback(err);
}