ConversationView.hasFiles: Exclude pending attachments by default

This commit is contained in:
Scott Nonnenberg 2021-09-08 16:23:44 -07:00 committed by GitHub
parent 7510be0caf
commit bd47720864
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2009,9 +2009,13 @@ export class ConversationView extends window.Backbone.View<ConversationModel> {
]); ]);
} }
hasFiles(): boolean { hasFiles(options: { includePending: boolean }): boolean {
const draftAttachments = this.model.get('draftAttachments') || []; const draftAttachments = this.model.get('draftAttachments') || [];
return draftAttachments.length > 0; if (options.includePending) {
return draftAttachments.length > 0;
}
return draftAttachments.some(item => !item.pending);
} }
async getFiles(): Promise<Array<AttachmentType>> { async getFiles(): Promise<Array<AttachmentType>> {
@ -2092,7 +2096,7 @@ export class ConversationView extends window.Backbone.View<ConversationModel> {
) )
); );
this.toggleMicrophone(); this.toggleMicrophone();
if (this.hasFiles()) { if (this.hasFiles({ includePending: true })) {
this.removeLinkPreview(); this.removeLinkPreview();
} }
} }
@ -2333,7 +2337,9 @@ export class ConversationView extends window.Backbone.View<ConversationModel> {
} }
toggleMicrophone(): void { toggleMicrophone(): void {
this.compositionApi.current?.setShowMic(!this.hasFiles()); this.compositionApi.current?.setShowMic(
!this.hasFiles({ includePending: true })
);
} }
captureAudio(e?: Event): void { captureAudio(e?: Event): void {
@ -2345,7 +2351,7 @@ export class ConversationView extends window.Backbone.View<ConversationModel> {
return; return;
} }
if (this.hasFiles()) { if (this.hasFiles({ includePending: true })) {
this.showToast(Whisper.VoiceNoteMustBeOnlyAttachmentToast); this.showToast(Whisper.VoiceNoteMustBeOnlyAttachmentToast);
return; return;
} }
@ -2388,7 +2394,7 @@ export class ConversationView extends window.Backbone.View<ConversationModel> {
}); });
} }
async handleAudioCapture(blob: Blob): Promise<void> { async handleAudioCapture(blob: Blob): Promise<void> {
if (this.hasFiles()) { if (this.hasFiles({ includePending: true })) {
throw new Error('A voice note cannot be sent with other attachments'); throw new Error('A voice note cannot be sent with other attachments');
} }
@ -4162,7 +4168,11 @@ export class ConversationView extends window.Backbone.View<ConversationModel> {
} }
try { try {
if (!message.length && !this.hasFiles() && !this.voiceNoteAttachment) { if (
!message.length &&
!this.hasFiles({ includePending: false }) &&
!this.voiceNoteAttachment
) {
return; return;
} }
@ -4255,7 +4265,7 @@ export class ConversationView extends window.Backbone.View<ConversationModel> {
return; return;
} }
// If we have attachments, don't add link preview // If we have attachments, don't add link preview
if (this.hasFiles()) { if (this.hasFiles({ includePending: true })) {
return; return;
} }
// If we're behind a user-configured proxy, we don't support link previews // If we're behind a user-configured proxy, we don't support link previews