Reset last message after message has expired

Fixes #980.
This commit is contained in:
Daniel Gasienica 2018-04-11 19:23:30 -04:00
parent ad05efb7a0
commit 0902c94093

View file

@ -9,7 +9,7 @@
'use strict'; 'use strict';
window.Whisper = window.Whisper || {}; window.Whisper = window.Whisper || {};
const { Attachment, Message } = window.Signal.Types; const { Attachment, Conversation, Message } = window.Signal.Types;
const { upgradeMessageSchema, loadAttachmentData } = window.Signal.Migrations; const { upgradeMessageSchema, loadAttachmentData } = window.Signal.Migrations;
// TODO: Factor out private and group subclasses of Conversation // TODO: Factor out private and group subclasses of Conversation
@ -669,31 +669,28 @@
)); ));
}); });
}, },
/* jshint ignore:end */
/* eslint-disable */
updateLastMessage: function() { async updateLastMessage() {
var collection = new Whisper.MessageCollection(); const collection = new Whisper.MessageCollection();
return collection.fetchConversation(this.id, 1).then(function() { await collection.fetchConversation(this.id, 1);
var lastMessage = collection.at(0); const lastMessage = collection.at(0);
if (lastMessage) {
var type = lastMessage.get('type'); const lastMessageUpdate = Conversation.createLastMessageUpdate({
var shouldSkipUpdate = type === 'verified-change' || lastMessage.get('expirationTimerUpdate'); currentLastMessageText: this.get('lastMessage') || null,
if (shouldSkipUpdate) { currentTimestamp: this.get('timestamp') || null,
return; lastMessage: lastMessage ? lastMessage.toJSON() : null,
} lastMessageNotificationText: lastMessage
this.set({ ? lastMessage.getNotificationText() : null,
lastMessage : lastMessage.getNotificationText(),
timestamp : lastMessage.get('sent_at')
}); });
} else {
this.set({ lastMessage: '', timestamp: null }); this.set(lastMessageUpdate);
}
if (this.hasChanged('lastMessage') || this.hasChanged('timestamp')) { if (this.hasChanged('lastMessage') || this.hasChanged('timestamp')) {
this.save(); this.save();
} }
}.bind(this));
}, },
/* jshint ignore:end */
/* eslint-disable */
updateExpirationTimer: function(expireTimer, source, received_at, options) { updateExpirationTimer: function(expireTimer, source, received_at, options) {
options = options || {}; options = options || {};