Skip to content

Commit

Permalink
Bring lastMessage and lastMessageStatus back to conversation
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnonnenberg-signal committed Mar 13, 2019
1 parent dcd1677 commit 812f895
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
8 changes: 7 additions & 1 deletion js/conversation_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,13 @@

this._initialFetchComplete = true;
await Promise.all(
conversations.map(conversation => conversation.updateLastMessage())
conversations.map(conversation => {
if (!conversation.get('lastMessage')) {
return conversation.updateLastMessage();
}

return null;
})
);
window.log.info('ConversationController: done with initial fetch');
} catch (error) {
Expand Down
23 changes: 4 additions & 19 deletions js/models/conversations.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@
this.unset('unidentifiedDeliveryUnrestricted');
this.unset('hasFetchedProfile');
this.unset('tokens');
this.unset('lastMessage');
this.unset('lastMessageStatus');

this.typingRefreshTimer = null;
this.typingPauseTimer = null;
Expand Down Expand Up @@ -323,8 +321,8 @@

isTyping: typingKeys.length > 0,
lastMessage: {
status: this.lastMessageStatus,
text: this.lastMessage,
status: this.get('lastMessageStatus'),
text: this.get('lastMessage'),
},

onClick: () => this.trigger('select', this),
Expand Down Expand Up @@ -879,10 +877,10 @@
});

const message = this.addSingleMessage(messageWithSchema);
this.lastMessage = message.getNotificationText();
this.lastMessageStatus = 'sending';

this.set({
lastMessage: message.getNotificationText(),
lastMessageStatus: 'sending',
active_at: now,
timestamp: now,
});
Expand Down Expand Up @@ -1154,17 +1152,6 @@
: null,
});

let hasChanged = false;
const { lastMessage, lastMessageStatus } = lastMessageUpdate;
delete lastMessageUpdate.lastMessage;
delete lastMessageUpdate.lastMessageStatus;

hasChanged = hasChanged || lastMessage !== this.lastMessage;
this.lastMessage = lastMessage;

hasChanged = hasChanged || lastMessageStatus !== this.lastMessageStatus;
this.lastMessageStatus = lastMessageStatus;

// Because we're no longer using Backbone-integrated saves, we need to manually
// clear the changed fields here so our hasChanged() check below is useful.
this.changed = {};
Expand All @@ -1174,8 +1161,6 @@
await window.Signal.Data.updateConversation(this.id, this.attributes, {
Conversation: Whisper.Conversation,
});
} else if (hasChanged) {
this.trigger('change');
}
},

Expand Down

0 comments on commit 812f895

Please sign in to comment.