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