conversation.applyMessageRequestResponse: Always save at the end

This commit is contained in:
Scott Nonnenberg 2020-11-12 12:03:07 -08:00 committed by GitHub
parent 947e9c366c
commit 0c6f4248f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1307,106 +1307,109 @@ export class ConversationModel extends window.Backbone.Model<
response: number, response: number,
{ fromSync = false, viaStorageServiceSync = false } = {} { fromSync = false, viaStorageServiceSync = false } = {}
): Promise<void> { ): Promise<void> {
const messageRequestEnum = try {
window.textsecure.protobuf.SyncMessage.MessageRequestResponse.Type; const messageRequestEnum =
const isLocalAction = !fromSync && !viaStorageServiceSync; window.textsecure.protobuf.SyncMessage.MessageRequestResponse.Type;
const ourConversationId = window.ConversationController.getOurConversationId(); const isLocalAction = !fromSync && !viaStorageServiceSync;
const ourConversationId = window.ConversationController.getOurConversationId();
const currentMessageRequestState = this.get('messageRequestResponseType'); const currentMessageRequestState = this.get('messageRequestResponseType');
const didResponseChange = response !== currentMessageRequestState; const didResponseChange = response !== currentMessageRequestState;
const wasPreviouslyAccepted = this.getAccepted(); const wasPreviouslyAccepted = this.getAccepted();
// Apply message request response locally // Apply message request response locally
this.set({ this.set({
messageRequestResponseType: response, messageRequestResponseType: response,
}); });
window.Signal.Data.updateConversation(this.attributes);
if (response === messageRequestEnum.ACCEPT) { if (response === messageRequestEnum.ACCEPT) {
this.unblock({ viaStorageServiceSync }); this.unblock({ viaStorageServiceSync });
this.enableProfileSharing({ viaStorageServiceSync }); this.enableProfileSharing({ viaStorageServiceSync });
// We really don't want to call this if we don't have to. It can take a lot of time // We really don't want to call this if we don't have to. It can take a lot of
// to go through old messages to download attachments. // time to go through old messages to download attachments.
if (didResponseChange && !wasPreviouslyAccepted) { if (didResponseChange && !wasPreviouslyAccepted) {
await this.handleReadAndDownloadAttachments({ isLocalAction }); await this.handleReadAndDownloadAttachments({ isLocalAction });
} }
if (isLocalAction) { if (isLocalAction) {
if (this.isGroupV1() || this.isPrivate()) { if (this.isGroupV1() || this.isPrivate()) {
this.sendProfileKeyUpdate(); this.sendProfileKeyUpdate();
} else if ( } else if (
ourConversationId && ourConversationId &&
this.isGroupV2() && this.isGroupV2() &&
this.isMemberPending(ourConversationId) this.isMemberPending(ourConversationId)
) { ) {
await this.modifyGroupV2({ await this.modifyGroupV2({
name: 'promotePendingMember', name: 'promotePendingMember',
createGroupChange: () => createGroupChange: () =>
this.promotePendingMember(ourConversationId), this.promotePendingMember(ourConversationId),
}); });
} else if ( } else if (
ourConversationId && ourConversationId &&
this.isGroupV2() && this.isGroupV2() &&
this.isMember(ourConversationId) this.isMember(ourConversationId)
) { ) {
window.log.info( window.log.info(
'applyMessageRequestResponse/accept: Already a member of v2 group' 'applyMessageRequestResponse/accept: Already a member of v2 group'
); );
} else { } else {
window.log.error( window.log.error(
'applyMessageRequestResponse/accept: Neither member nor pending member of v2 group' 'applyMessageRequestResponse/accept: Neither member nor pending member of v2 group'
); );
} }
} }
} else if (response === messageRequestEnum.BLOCK) { } else if (response === messageRequestEnum.BLOCK) {
// Block locally, other devices should block upon receiving the sync message // Block locally, other devices should block upon receiving the sync message
this.block({ viaStorageServiceSync }); this.block({ viaStorageServiceSync });
this.disableProfileSharing({ viaStorageServiceSync }); this.disableProfileSharing({ viaStorageServiceSync });
if (isLocalAction) { if (isLocalAction) {
if (this.isGroupV1() || this.isPrivate()) { if (this.isGroupV1() || this.isPrivate()) {
await this.leaveGroup(); await this.leaveGroup();
} else if (this.isGroupV2()) { } else if (this.isGroupV2()) {
await this.leaveGroupV2(); await this.leaveGroupV2();
} }
} }
} else if (response === messageRequestEnum.DELETE) { } else if (response === messageRequestEnum.DELETE) {
this.disableProfileSharing({ viaStorageServiceSync }); this.disableProfileSharing({ viaStorageServiceSync });
// Delete messages locally, other devices should delete upon receiving // Delete messages locally, other devices should delete upon receiving
// the sync message // the sync message
await this.destroyMessages(); await this.destroyMessages();
this.updateLastMessage(); this.updateLastMessage();
if (isLocalAction) { if (isLocalAction) {
this.trigger('unload', 'deleted from message request'); this.trigger('unload', 'deleted from message request');
if (this.isGroupV1() || this.isPrivate()) { if (this.isGroupV1() || this.isPrivate()) {
await this.leaveGroup(); await this.leaveGroup();
} else if (this.isGroupV2()) { } else if (this.isGroupV2()) {
await this.leaveGroupV2(); await this.leaveGroupV2();
} }
} }
} else if (response === messageRequestEnum.BLOCK_AND_DELETE) { } else if (response === messageRequestEnum.BLOCK_AND_DELETE) {
// Block locally, other devices should block upon receiving the sync message // Block locally, other devices should block upon receiving the sync message
this.block({ viaStorageServiceSync }); this.block({ viaStorageServiceSync });
this.disableProfileSharing({ viaStorageServiceSync }); this.disableProfileSharing({ viaStorageServiceSync });
// Delete messages locally, other devices should delete upon receiving // Delete messages locally, other devices should delete upon receiving
// the sync message // the sync message
await this.destroyMessages(); await this.destroyMessages();
this.updateLastMessage(); this.updateLastMessage();
if (isLocalAction) { if (isLocalAction) {
this.trigger('unload', 'blocked and deleted from message request'); this.trigger('unload', 'blocked and deleted from message request');
if (this.isGroupV1() || this.isPrivate()) { if (this.isGroupV1() || this.isPrivate()) {
await this.leaveGroup(); await this.leaveGroup();
} else if (this.isGroupV2()) { } else if (this.isGroupV2()) {
await this.leaveGroupV2(); await this.leaveGroupV2();
}
} }
} }
} finally {
window.Signal.Data.updateConversation(this.attributes);
} }
} }