diff options
Diffstat (limited to 'js')
-rw-r--r-- | js/views/chatview.js | 34 |
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() { |