Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group message by time, default 5min #1672

Merged
merged 1 commit into from
Dec 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-lib/server/startup/settings.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand Down
59 changes: 35 additions & 24 deletions packages/rocketchat-ui-message/message/message.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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: ->
Expand Down Expand Up @@ -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"
2 changes: 1 addition & 1 deletion packages/rocketchat-ui-message/message/message.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template name="message">
<li id="{{_id}}" class="message {{isSequential}} {{system}} {{t}} {{own}} {{isTemp}} {{chatops}}" data-username="{{u.username}}" data-groupable="{{isGroupable}}" data-date="{{date}}">
<li id="{{_id}}" class="message {{isSequential}} {{system}} {{t}} {{own}} {{isTemp}} {{chatops}}" data-username="{{u.username}}" data-groupable="{{isGroupable}}" data-date="{{date}}" data-timestamp="{{timestamp}}">
{{#if avatar}}
<a class="thumb user-card-message" href="#" data-username="{{u.username}}" tabindex="1">
<div class="avatar">
Expand Down