Move common utils out of conversation view
This commit is contained in:
parent
9791fa43ef
commit
9888e6d38f
4 changed files with 46 additions and 38 deletions
10
ts/util/markAllAsApproved.ts
Normal file
10
ts/util/markAllAsApproved.ts
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
// Copyright 2021 Signal Messenger, LLC
|
||||||
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
import type { ConversationModel } from '../models/conversations';
|
||||||
|
|
||||||
|
export async function markAllAsApproved(
|
||||||
|
untrusted: ReadonlyArray<ConversationModel>
|
||||||
|
): Promise<void> {
|
||||||
|
await Promise.all(untrusted.map(contact => contact.setApproved()));
|
||||||
|
}
|
18
ts/util/markAllAsVerifiedDefault.ts
Normal file
18
ts/util/markAllAsVerifiedDefault.ts
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
// Copyright 2021 Signal Messenger, LLC
|
||||||
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
import type { ConversationModel } from '../models/conversations';
|
||||||
|
|
||||||
|
export async function markAllAsVerifiedDefault(
|
||||||
|
unverified: ReadonlyArray<ConversationModel>
|
||||||
|
): Promise<void> {
|
||||||
|
await Promise.all(
|
||||||
|
unverified.map(contact => {
|
||||||
|
if (contact.isUnverified()) {
|
||||||
|
return contact.setVerifiedDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
10
ts/util/retryMessageSend.ts
Normal file
10
ts/util/retryMessageSend.ts
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
// Copyright 2021 Signal Messenger, LLC
|
||||||
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
export async function retryMessageSend(messageId: string): Promise<void> {
|
||||||
|
const message = window.MessageController.getById(messageId);
|
||||||
|
if (!message) {
|
||||||
|
throw new Error(`retryMessageSend: Message ${messageId} missing!`);
|
||||||
|
}
|
||||||
|
await message.retrySend();
|
||||||
|
}
|
|
@ -110,6 +110,9 @@ import { ToastMaxAttachments } from '../components/ToastMaxAttachments';
|
||||||
import { ToastOneNonImageAtATime } from '../components/ToastOneNonImageAtATime';
|
import { ToastOneNonImageAtATime } from '../components/ToastOneNonImageAtATime';
|
||||||
import { ToastUnableToLoadAttachment } from '../components/ToastUnableToLoadAttachment';
|
import { ToastUnableToLoadAttachment } from '../components/ToastUnableToLoadAttachment';
|
||||||
import { deleteDraftAttachment } from '../util/deleteDraftAttachment';
|
import { deleteDraftAttachment } from '../util/deleteDraftAttachment';
|
||||||
|
import { markAllAsApproved } from '../util/markAllAsApproved';
|
||||||
|
import { markAllAsVerifiedDefault } from '../util/markAllAsVerifiedDefault';
|
||||||
|
import { retryMessageSend } from '../util/retryMessageSend';
|
||||||
|
|
||||||
type AttachmentOptions = {
|
type AttachmentOptions = {
|
||||||
messageId: string;
|
messageId: string;
|
||||||
|
@ -636,9 +639,7 @@ export class ConversationView extends window.Backbone.View<ConversationModel> {
|
||||||
const replyToMessage = (messageId: string) => {
|
const replyToMessage = (messageId: string) => {
|
||||||
this.setQuoteMessage(messageId);
|
this.setQuoteMessage(messageId);
|
||||||
};
|
};
|
||||||
const retrySend = (messageId: string) => {
|
const retrySend = retryMessageSend;
|
||||||
this.retrySend(messageId);
|
|
||||||
};
|
|
||||||
const deleteMessage = (messageId: string) => {
|
const deleteMessage = (messageId: string) => {
|
||||||
this.deleteMessage(messageId);
|
this.deleteMessage(messageId);
|
||||||
};
|
};
|
||||||
|
@ -1660,28 +1661,6 @@ export class ConversationView extends window.Backbone.View<ConversationModel> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line class-methods-use-this
|
|
||||||
async markAllAsVerifiedDefault(
|
|
||||||
unverified: ReadonlyArray<ConversationModel>
|
|
||||||
): Promise<void> {
|
|
||||||
await Promise.all(
|
|
||||||
unverified.map(contact => {
|
|
||||||
if (contact.isUnverified()) {
|
|
||||||
return contact.setVerifiedDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// eslint-disable-next-line class-methods-use-this
|
|
||||||
async markAllAsApproved(
|
|
||||||
untrusted: ReadonlyArray<ConversationModel>
|
|
||||||
): Promise<void> {
|
|
||||||
await Promise.all(untrusted.map(contact => contact.setApproved()));
|
|
||||||
}
|
|
||||||
|
|
||||||
captureAudio(e?: Event): void {
|
captureAudio(e?: Event): void {
|
||||||
if (e) {
|
if (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
@ -1813,15 +1792,6 @@ export class ConversationView extends window.Backbone.View<ConversationModel> {
|
||||||
this.model.updateVerified();
|
this.model.updateVerified();
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line class-methods-use-this
|
|
||||||
async retrySend(messageId: string): Promise<void> {
|
|
||||||
const message = window.MessageController.getById(messageId);
|
|
||||||
if (!message) {
|
|
||||||
throw new Error(`retrySend: Message ${messageId} missing!`);
|
|
||||||
}
|
|
||||||
await message.retrySend();
|
|
||||||
}
|
|
||||||
|
|
||||||
async showForwardMessageModal(messageId: string): Promise<void> {
|
async showForwardMessageModal(messageId: string): Promise<void> {
|
||||||
const messageFromCache = window.MessageController.getById(messageId);
|
const messageFromCache = window.MessageController.getById(messageId);
|
||||||
if (!messageFromCache) {
|
if (!messageFromCache) {
|
||||||
|
@ -1968,10 +1938,10 @@ export class ConversationView extends window.Backbone.View<ConversationModel> {
|
||||||
let verifyPromise: Promise<void> | undefined;
|
let verifyPromise: Promise<void> | undefined;
|
||||||
let approvePromise: Promise<void> | undefined;
|
let approvePromise: Promise<void> | undefined;
|
||||||
if (unverifiedContacts.length) {
|
if (unverifiedContacts.length) {
|
||||||
verifyPromise = this.markAllAsVerifiedDefault(unverifiedContacts);
|
verifyPromise = markAllAsVerifiedDefault(unverifiedContacts);
|
||||||
}
|
}
|
||||||
if (untrustedContacts.length) {
|
if (untrustedContacts.length) {
|
||||||
approvePromise = this.markAllAsApproved(untrustedContacts);
|
approvePromise = markAllAsApproved(untrustedContacts);
|
||||||
}
|
}
|
||||||
await Promise.all([verifyPromise, approvePromise]);
|
await Promise.all([verifyPromise, approvePromise]);
|
||||||
}
|
}
|
||||||
|
@ -3249,7 +3219,7 @@ export class ConversationView extends window.Backbone.View<ConversationModel> {
|
||||||
|
|
||||||
if (options.force) {
|
if (options.force) {
|
||||||
if (unverifiedContacts.length) {
|
if (unverifiedContacts.length) {
|
||||||
await this.markAllAsVerifiedDefault(unverifiedContacts.models);
|
await markAllAsVerifiedDefault(unverifiedContacts.models);
|
||||||
// We only want force to break us through one layer of checks
|
// We only want force to break us through one layer of checks
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
options.force = false;
|
options.force = false;
|
||||||
|
@ -3262,7 +3232,7 @@ export class ConversationView extends window.Backbone.View<ConversationModel> {
|
||||||
|
|
||||||
if (options.force) {
|
if (options.force) {
|
||||||
if (untrustedContacts.length) {
|
if (untrustedContacts.length) {
|
||||||
await this.markAllAsApproved(untrustedContacts.models);
|
await markAllAsApproved(untrustedContacts.models);
|
||||||
}
|
}
|
||||||
} else if (untrustedContacts.length) {
|
} else if (untrustedContacts.length) {
|
||||||
return untrustedContacts;
|
return untrustedContacts;
|
||||||
|
|
Loading…
Add table
Reference in a new issue