From 6f4950964511de35d07925a657f4f4526a2f2053 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Wed, 8 Mar 2017 15:09:58 +0300 Subject: [PATCH] fix newSet on redis --- public/src/client/chats/messages.js | 4 +++- src/messaging.js | 2 +- src/messaging/data.js | 6 ++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/public/src/client/chats/messages.js b/public/src/client/chats/messages.js index c8300c485c..987ac46c79 100644 --- a/public/src/client/chats/messages.js +++ b/public/src/client/chats/messages.js @@ -57,8 +57,10 @@ define('forum/chats/messages', ['components', 'sounds', 'translator'], function messages.appendChatMessage = function (chatContentEl, data) { var lastSpeaker = parseInt(chatContentEl.find('.chat-message').last().attr('data-uid'), 10); + var lasttimestamp = parseInt(chatContentEl.find('.chat-message').last().attr('data-timestamp'), 10); if (!Array.isArray(data)) { - data.newSet = lastSpeaker !== data.fromuid; + data.newSet = lastSpeaker !== parseInt(data.fromuid, 10) || + parseInt(data.timestamp, 10) > parseInt(lasttimestamp, 10) + (1000 * 60 * 3); } messages.parseMessage(data, function (html) { diff --git a/src/messaging.js b/src/messaging.js index e141adff4f..e507609d81 100644 --- a/src/messaging.js +++ b/src/messaging.js @@ -102,7 +102,7 @@ Messaging.isNewSet = function (uid, roomId, timestamp, callback) { }, function (messages, next) { if (messages && messages.length) { - next(null, parseInt(timestamp, 10) > parseInt(messages[0].score, 10) + (1000 * 60 * 5)); + next(null, parseInt(timestamp, 10) > parseInt(messages[0].score, 10) + Messaging.newMessageCutoff); } else { next(null, true); } diff --git a/src/messaging/data.js b/src/messaging/data.js index e3cb67fbd8..98d4dcded8 100644 --- a/src/messaging/data.js +++ b/src/messaging/data.js @@ -8,6 +8,8 @@ var user = require('../user'); var utils = require('../../public/src/utils'); module.exports = function (Messaging) { + Messaging.newMessageCutoff = 1000 * 60 * 3; + Messaging.getMessageField = function (mid, field, callback) { Messaging.getMessageFields(mid, [field], function (err, fields) { callback(err, fields ? fields[field] : null); @@ -80,7 +82,7 @@ module.exports = function (Messaging) { // Add a spacer in between messages with time gaps between them messages = messages.map(function (message, index) { // Compare timestamps with the previous message, and check if a spacer needs to be added - if (index > 0 && parseInt(message.timestamp, 10) > parseInt(messages[index - 1].timestamp, 10) + (1000 * 60 * 5)) { + if (index > 0 && parseInt(message.timestamp, 10) > parseInt(messages[index - 1].timestamp, 10) + Messaging.newMessageCutoff) { // If it's been 5 minutes, this is a new set of messages message.newSet = true; } else if (index > 0 && message.fromuid !== messages[index - 1].fromuid) { @@ -115,7 +117,7 @@ module.exports = function (Messaging) { } if ( - (parseInt(messages[0].timestamp, 10) > parseInt(fields.timestamp, 10) + (1000 * 60 * 5)) || + (parseInt(messages[0].timestamp, 10) > parseInt(fields.timestamp, 10) + Messaging.newMessageCutoff) || (parseInt(messages[0].fromuid, 10) !== parseInt(fields.fromuid, 10)) ) { // If it's been 5 minutes, this is a new set of messages