summaryrefslogtreecommitdiffstats
path: root/js
diff options
context:
space:
mode:
authorDaniel Calviño Sánchez <danxuliu@gmail.com>2017-11-15 18:53:45 +0100
committerDaniel Calviño Sánchez <danxuliu@gmail.com>2017-11-16 13:13:08 +0100
commitbc501ba53c72b1dcce74e0ed7ad5fe8aa5f4eeff (patch)
treef5864cbff32bcb1be0a7e781b81fc3539deb3465 /js
parent06b62d8c56c377515d3323dd7a1a2a73725941d5 (diff)
Group temporary near messages by same participant
When two or more consecutive messages were sent by the same participant with a difference of less than 120 seconds between each message those messages are now shown grouped (the participant name is not shown for the intermediate messages and each message is pushed closer to the previous message). Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'js')
-rw-r--r--js/views/chatview.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/js/views/chatview.js b/js/views/chatview.js
index fce132128..1ff77ec38 100644
--- a/js/views/chatview.js
+++ b/js/views/chatview.js
@@ -97,6 +97,8 @@
},
render: function() {
+ delete this._lastAddedMessageModel;
+
this.$el.html(this.template({
emptyResultLabel: t('spreed', 'No messages yet, start the conversation!')
}));
@@ -147,9 +149,41 @@
this.$container.prepend($el);
}
+ if (this._modelsHaveSameActor(this._lastAddedMessageModel, model) &&
+ this._modelsAreTemporaryNear(this._lastAddedMessageModel, model)) {
+ $el.next().addClass('grouped');
+ }
+
+ // Keeping the model for the last added message is not only
+ // practical, but needed, as the models for previous messages are
+ // removed from the collection each time a new set of messages is
+ // received.
+ this._lastAddedMessageModel = model;
+
this._postRenderItem($el);
},
+ _modelsHaveSameActor: function(model1, model2) {
+ if (!model1 || !model2) {
+ return false;
+ }
+
+ return model1.get('actorId') === model2.get('actorId') &&
+ model1.get('actorType') === model2.get('actorType');
+ },
+
+ _modelsAreTemporaryNear: function(model1, model2, secondsThreshold) {
+ if (!model1 || !model2) {
+ return false;
+ }
+
+ if (_.isUndefined(secondsThreshold)) {
+ secondsThreshold = 120;
+ }
+
+ return Math.abs(model1.get('timestamp') - model2.get('timestamp')) <= secondsThreshold;
+ },
+
_postRenderItem: function($el) {
$el.find('.has-tooltip').tooltip();
$el.find('.avatar').each(function() {