DRY up ConversationView callbacks

This commit is contained in:
Evan Hahn 2021-04-20 09:46:09 -05:00 committed by Scott Nonnenberg
parent 86d2a4b5dd
commit 814255c10e

View file

@ -620,49 +620,22 @@ Whisper.ConversationView = Whisper.View.extend({
micCellEl,
attachmentListEl,
onAccept: () => {
this.longRunningTaskWrapper({
name: 'onAccept',
task: this.model.syncMessageRequestResponse.bind(
this.model,
messageRequestEnum.ACCEPT
),
});
this.syncMessageRequestResponse('onAccept', messageRequestEnum.ACCEPT);
},
onBlock: () => {
this.longRunningTaskWrapper({
name: 'onBlock',
task: this.model.syncMessageRequestResponse.bind(
this.model,
messageRequestEnum.BLOCK
),
});
this.syncMessageRequestResponse('onBlock', messageRequestEnum.BLOCK);
},
onUnblock: () => {
this.longRunningTaskWrapper({
name: 'onUnblock',
task: this.model.syncMessageRequestResponse.bind(
this.model,
messageRequestEnum.ACCEPT
),
});
this.syncMessageRequestResponse('onUnblock', messageRequestEnum.ACCEPT);
},
onDelete: () => {
this.longRunningTaskWrapper({
name: 'onDelete',
task: this.model.syncMessageRequestResponse.bind(
this.model,
messageRequestEnum.DELETE
),
});
this.syncMessageRequestResponse('onDelete', messageRequestEnum.DELETE);
},
onBlockAndDelete: () => {
this.longRunningTaskWrapper({
name: 'onBlockAndDelete',
task: this.model.syncMessageRequestResponse.bind(
this.model,
messageRequestEnum.BLOCK_AND_DELETE
),
});
this.syncMessageRequestResponse(
'onBlockAndDelete',
messageRequestEnum.BLOCK_AND_DELETE
);
},
onStartGroupMigration: () => this.startMigrationToGV2(),
onCancelJoinRequest: async () => {
@ -1421,6 +1394,17 @@ Whisper.ConversationView = Whisper.View.extend({
}
},
syncMessageRequestResponse(
name: string,
messageRequestType: number
): Promise<void> {
const { model }: { model: ConversationModel } = this;
return this.longRunningTaskWrapper({
name,
task: model.syncMessageRequestResponse.bind(model, messageRequestType),
});
},
getPropsForAttachmentList() {
const draftAttachments = this.model.get('draftAttachments') || [];
@ -3075,13 +3059,7 @@ Whisper.ConversationView = Whisper.View.extend({
};
const onBlock = () => {
this.longRunningTaskWrapper({
name: 'onBlock',
task: this.model.syncMessageRequestResponse.bind(
this.model,
messageRequestEnum.BLOCK
),
});
this.syncMessageRequestResponse('onBlock', messageRequestEnum.BLOCK);
};
const ACCESS_ENUM = window.textsecure.protobuf.AccessControl.AccessRequired;