Skip to content

Node.js based forum software built for the modern web

closes #2052

barisusakli406660738889
diff --git a/install/data/defaults.json b/install/data/defaults.json
index 00138af35c..24918285d0 100644
--- a/install/data/defaults.json
+++ b/install/data/defaults.json
@@ -75,10 +75,6 @@
"field": "profileImageDimension",
"value": 128
},
- {
- "field": "chatMessagesToDisplay",
- "value": 50
- },
{
"field": "requireEmailConfirmation",
"value": 0
diff --git a/public/language/en_GB/modules.json b/public/language/en_GB/modules.json
index 9bf107bec6..12e6d7457f 100644
--- a/public/language/en_GB/modules.json
+++ b/public/language/en_GB/modules.json
@@ -12,6 +12,10 @@
"chat.message-history": "Message History",
"chat.pop-out": "Pop out chat",
"chat.maximize": "Maximize",
+ "chat.yesterday": "Yesterday",
+ "chat.seven_days": "7 Days",
+ "chat.thirty_days": "30 Days",
+ "chat.three_months": "3 Months",
"composer.user_said_in": "%1 said in %2:",
"composer.user_said": "%1 said:",
diff --git a/public/src/forum/chats.js b/public/src/forum/chats.js
index 110afa4473..84bf4fd4cc 100644
--- a/public/src/forum/chats.js
+++ b/public/src/forum/chats.js
@@ -78,8 +78,28 @@ define('forum/chats', ['string', 'sounds', 'forum/infinitescroll'], function(S,
loadMoreRecentChats();
}
});
+
+ $('.expanded-chat [data-since]').on('click', function() {
+ var since = $(this).attr('data-since');
+ $('.expanded-chat [data-since]').removeClass('selected');
+ $(this).addClass('selected');
+ loadChatSince(since);
+ return false;
+ });
};
+ function loadChatSince(since) {
+ var uid = Chats.getRecipientUid();
+ if (!uid) {
+ return;
+ }
+ socket.emit('modules.chats.get', {touid: uid, since: since}, function(err, messages) {
+ var chatContent = $('.expanded-chat .chat-content');
+ chatContent.find('.chat-message').remove();
+ Chats.parseMessage(messages, onMessagesParsed);
+ });
+ }
+
Chats.addGlobalEventListeners = function() {
$(window).on('resize', Chats.resizeMainWindow);
$(window).on('mousemove keypress click', function() {
@@ -93,6 +113,14 @@ define('forum/chats', ['string', 'sounds', 'forum/infinitescroll'], function(S,
});
};
+ function onMessagesParsed(html) {
+ var newMessage = $(html);
+ newMessage.insertBefore($('.user-typing'));
+ newMessage.find('span.timeago').timeago();
+ newMessage.find('img:not(".chat-user-image")').addClass('img-responsive');
+ Chats.scrollToBottom($('.expanded-chat .chat-content'));
+ }
+
Chats.addSocketListeners = function() {
socket.on('event:chats.receive', function(data) {
var typingNotifEl = $('.user-typing'),
@@ -101,13 +129,7 @@ define('forum/chats', ['string', 'sounds', 'forum/infinitescroll'], function(S,
if (Chats.isCurrentChat(data.withUid)) {
newMessage = data.self === 0;
data.message.self = data.self;
- Chats.parseMessage(data.message, function(html) {
- var newMessage = $(html);
- newMessage.insertBefore(typingNotifEl);
- newMessage.find('span.timeago').timeago();
- newMessage.find('img:not(".chat-user-image")').addClass('img-responsive');
- Chats.scrollToBottom(containerEl);
- });
+ Chats.parseMessage(data.message, onMessagesParsed);
} else {
$('.chats-list li[data-uid="' + data.withUid + '"]').addClass('unread');
app.alternatingTitle('[[modules:chat.user_has_messaged_you, ' + data.message.fromUser.username + ']]');
diff --git a/public/src/modules/chat.js b/public/src/modules/chat.js
index 24bc182716..f40dda09a2 100644
--- a/public/src/modules/chat.js
+++ b/public/src/modules/chat.js
@@ -193,9 +193,10 @@ define('chat', ['taskbar', 'string', 'sounds', 'forum/chats'], function(taskbar,
var totalHeight = chatModal.find('.modal-content').outerHeight() - chatModal.find('.modal-header').outerHeight();
var padding = parseInt(chatModal.find('.modal-body').css('padding-top'), 10) + parseInt(chatModal.find('.modal-body').css('padding-bottom'), 10);
var contentMargin = parseInt(chatModal.find('#chat-content').css('margin-top'), 10) + parseInt(chatModal.find('#chat-content').css('margin-bottom'), 10);
+ var sinceHeight = chatModal.find('.since-bar').outerHeight(true);
var inputGroupHeight = chatModal.find('.input-group').outerHeight();
- chatModal.find('#chat-content').css('height', totalHeight - padding - contentMargin - inputGroupHeight);
+ chatModal.find('#chat-content').css('height', totalHeight - padding - contentMargin - sinceHeight - inputGroupHeight);
});
chatModal.find('#chat-with-name').html(username);
@@ -220,6 +221,14 @@ define('chat', ['taskbar', 'string', 'sounds', 'forum/chats'], function(taskbar,
}
});
+ chatModal.find('[data-since]').on('click', function() {
+ var since = $(this).attr('data-since');
+ chatModal.find('[data-since]').removeClass('selected');
+ $(this).addClass('selected');
+ loadChatSince(chatModal, since);
+ return false;
+ });
+
addSendHandler(chatModal);
getChatMessages(chatModal, function() {
@@ -279,7 +288,15 @@ define('chat', ['taskbar', 'string', 'sounds', 'forum/chats'], function(taskbar,
};
function getChatMessages(chatModal, callback) {
- socket.emit('modules.chats.get', {touid: chatModal.attr('touid')}, function(err, messages) {
+ socket.emit('modules.chats.get', {touid: chatModal.attr('touid'), since: 'day'}, function(err, messages) {
+ module.appendChatMessage(chatModal, messages, callback);
+ });
+ }
+
+ function loadChatSince(chatModal, since, callback) {
+ socket.emit('modules.chats.get', {touid: chatModal.attr('touid'), since: since}, function(err, messages) {
+ var chatContent = chatModal.find('#chat-content');
+ chatContent.find('.chat-message').remove();
module.appendChatMessage(chatModal, messages, callback);
});
}
diff --git a/src/controllers/accounts.js b/src/controllers/accounts.js
index 6ce15eb073..a81f7fcd07 100644
--- a/src/controllers/accounts.js
+++ b/src/controllers/accounts.js
@@ -535,7 +535,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, false)
+ messages: async.apply(messaging.getMessages, req.user.uid, toUid, 'day', false)
}, next);
}
], function(err, data) {
diff --git a/src/messaging.js b/src/messaging.js
index 0d9d9ca3fb..e47270d5da 100644
--- a/src/messaging.js
+++ b/src/messaging.js
@@ -88,10 +88,18 @@ var db = require('./database'),
});
}
- Messaging.getMessages = function(fromuid, touid, isNew, callback) {
+ Messaging.getMessages = function(fromuid, touid, since, isNew, callback) {
var uids = sortUids(fromuid, touid);
- db.getSortedSetRevRange('messages:uid:' + uids[0] + ':to:' + uids[1], 0, (meta.config.chatMessagesToDisplay || 50) - 1, function(err, mids) {
+ 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) {
if (err) {
return callback(err);
}
diff --git a/src/socket.io/modules.js b/src/socket.io/modules.js
index 399adae0b9..a96c3ffd4b 100644
--- a/src/socket.io/modules.js
+++ b/src/socket.io/modules.js
@@ -166,7 +166,7 @@ SocketModules.chats.get = function(socket, data, callback) {
return callback(new Error('[[error:invalid-data]]'));
}
- Messaging.getMessages(socket.uid, data.touid, false, callback);
+ Messaging.getMessages(socket.uid, data.touid, data.since, false, callback);
};
SocketModules.chats.send = function(socket, data, callback) {