From 163720c1c1bb2d02ba428620fe6bd83e34ffbc1c Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Tue, 15 Dec 2015 20:22:57 -0200 Subject: [PATCH] Group message by time, default 5min --- i18n/en.i18n.json | 2 + .../server/startup/settings.coffee | 1 + .../message/message.coffee | 59 +++++++++++-------- .../message/message.html | 2 +- 4 files changed, 39 insertions(+), 25 deletions(-) diff --git a/i18n/en.i18n.json b/i18n/en.i18n.json index 586023bd54de..0c59ffacfbcf 100644 --- a/i18n/en.i18n.json +++ b/i18n/en.i18n.json @@ -268,6 +268,8 @@ "Message_deleting_not_allowed" : "Message deleting not allowed", "Message_editing_blocked" : "This message cannot be edited anymore", "Message_editing_not_allowed" : "Message editing not allowed", + "Message_GroupingPeriod" : "Grouping Period (in seconds)", + "Message_GroupingPeriodDescription" : "Messages will be grouped with previous message if both are from the same user and the elapsed time was less than the informed time in seconds.", "Message_KeepHistory" : "Keep Message History", "Message_MaxAllowedSize" : "Maximum Allowed Message Size", "Message_pinned" : "Message pinned", diff --git a/packages/rocketchat-lib/server/startup/settings.coffee b/packages/rocketchat-lib/server/startup/settings.coffee index 93ffa8ae7bbe..378f12715161 100644 --- a/packages/rocketchat-lib/server/startup/settings.coffee +++ b/packages/rocketchat-lib/server/startup/settings.coffee @@ -94,6 +94,7 @@ RocketChat.settings.add 'Message_KeepHistory', false, { type: 'boolean', group: RocketChat.settings.add 'Message_MaxAllowedSize', 5000, { type: 'int', group: 'Message', public: true } RocketChat.settings.add 'Message_ShowFormattingTips', true, { type: 'boolean', group: 'Message', public: true } RocketChat.settings.add 'Message_AudioRecorderEnabled', true, { type: 'boolean', group: 'Message', public: true, i18nDescription: 'Message_AudioRecorderEnabledDescription' } +RocketChat.settings.add 'Message_GroupingPeriod', 300, { type: 'int', group: 'Message', public: true, i18nDescription: 'Message_GroupingPeriodDescription' } RocketChat.settings.addGroup 'Meta' RocketChat.settings.add 'Meta_language', '', { type: 'string', group: 'Meta' } diff --git a/packages/rocketchat-ui-message/message/message.coffee b/packages/rocketchat-ui-message/message/message.coffee index cdd07703eaee..7df5f15aea27 100644 --- a/packages/rocketchat-ui-message/message/message.coffee +++ b/packages/rocketchat-ui-message/message/message.coffee @@ -9,6 +9,8 @@ Template.message.helpers return emojione.toImage emoji own: -> return 'own' if this.u?._id is Meteor.userId() + timestamp: -> + return +this.ts chatops: -> return 'chatops-message' if this.u?.username is RocketChat.settings.get('Chatops_Username') time: -> @@ -113,29 +115,38 @@ Template.message.onCreated -> Template.message.onViewRendered = (context) -> view = this this._domrange.onAttached (domRange) -> - lastNode = domRange.lastNode() - if lastNode.previousElementSibling?.dataset?.date isnt lastNode.dataset.date - $(lastNode).addClass('new-day') - $(lastNode).removeClass('sequential') - else if lastNode.previousElementSibling?.dataset?.username isnt lastNode.dataset.username - $(lastNode).removeClass('sequential') - - if lastNode.previousElementSibling?.dataset?.groupable is 'false' - $(lastNode).removeClass('sequential') - - if lastNode.nextElementSibling?.dataset?.date is lastNode.dataset.date - $(lastNode.nextElementSibling).removeClass('new-day') - else - $(lastNode.nextElementSibling).addClass('new-day') - $(lastNode.nextElementSibling).removeClass('sequential') + currentNode = domRange.lastNode() + currentDataset = currentNode.dataset + previousNode = currentNode.previousElementSibling + nextNode = currentNode.nextElementSibling + $currentNode = $(currentNode) + $previousNode = $(previousNode) + $nextNode = $(nextNode) - if lastNode.nextElementSibling?.dataset?.username isnt lastNode.dataset.username - $(lastNode.nextElementSibling).removeClass('sequential') + if previousNode?.dataset? + previousDataset = previousNode.dataset - if not lastNode.nextElementSibling? - if lastNode.classList.contains('own') is true - view.parentView.parentView.parentView.parentView.parentView.templateInstance?().atBottom = true - else - if view.parentView.parentView.parentView.parentView.parentView.templateInstance?().atBottom isnt true - newMessage = view.parentView.parentView.parentView.parentView.parentView.templateInstance?()?.find(".new-message") - newMessage?.className = "new-message" + if previousDataset.date isnt currentDataset.date + $currentNode.addClass('new-day').removeClass('sequential') + + if previousDataset.groupable is 'false' or previousDataset.username isnt currentDataset.username or parseInt(currentDataset.timestamp) - parseInt(previousDataset.timestamp) > RocketChat.settings.get('Message_GroupingPeriod') * 1000 + $currentNode.removeClass('sequential') + + if nextNode?.dataset? + nextDataset = nextNode.dataset + + if nextDataset.date isnt currentDataset.date + $nextNode.addClass('new-day').removeClass('sequential') + + if nextDataset.username isnt currentDataset.username or parseInt(nextDataset.timestamp) - parseInt(currentDataset.timestamp) > RocketChat.settings.get('Message_GroupingPeriod') * 1000 + $nextNode.removeClass('sequential') + + if not nextNode? + templateInstance = view.parentView.parentView.parentView.parentView.parentView.templateInstance?() + + if currentNode.classList.contains('own') is true + templateInstance?.atBottom = true + else + if templateInstance?.atBottom isnt true + newMessage = templateInstance?.find(".new-message") + newMessage?.className = "new-message" diff --git a/packages/rocketchat-ui-message/message/message.html b/packages/rocketchat-ui-message/message/message.html index 998d648209e2..a2d6fd53f55e 100644 --- a/packages/rocketchat-ui-message/message/message.html +++ b/packages/rocketchat-ui-message/message/message.html @@ -1,5 +1,5 @@