diff --git a/ts/background.ts b/ts/background.ts index 06fc2a853353..13e065f73e18 100644 --- a/ts/background.ts +++ b/ts/background.ts @@ -31,7 +31,7 @@ import { routineProfileRefresh } from './routineProfileRefresh'; import { isMoreRecentThan, isOlderThan } from './util/timestamp'; import { isValidReactionEmoji } from './reactions/isValidReactionEmoji'; import { ConversationModel } from './models/conversations'; -import { getMessageById } from './models/messages'; +import { getMessageById } from './messages/getMessageById'; import { createBatcher } from './util/batcher'; import { updateConversationsWithUuidLookup } from './updateConversationsWithUuidLookup'; import { initializeAllJobQueues } from './jobs/initializeAllJobQueues'; diff --git a/ts/jobs/normalMessageSendJobQueue.ts b/ts/jobs/normalMessageSendJobQueue.ts index e1d2bf0d7416..8f2a1f8c5cb2 100644 --- a/ts/jobs/normalMessageSendJobQueue.ts +++ b/ts/jobs/normalMessageSendJobQueue.ts @@ -7,7 +7,8 @@ import PQueue from 'p-queue'; import type { LoggerType } from '../logging/log'; import { exponentialBackoffMaxAttempts } from '../util/exponentialBackoff'; import { commonShouldJobContinue } from './helpers/commonShouldJobContinue'; -import { MessageModel, getMessageById } from '../models/messages'; +import type { MessageModel } from '../models/messages'; +import { getMessageById } from '../messages/getMessageById'; import type { ConversationModel } from '../models/conversations'; import { ourProfileKeyService } from '../services/ourProfileKey'; import { strictAssert } from '../util/assert'; diff --git a/ts/messages/getMessageById.ts b/ts/messages/getMessageById.ts new file mode 100644 index 000000000000..c1d327fafb88 --- /dev/null +++ b/ts/messages/getMessageById.ts @@ -0,0 +1,33 @@ +// Copyright 2021 Signal Messenger, LLC +// SPDX-License-Identifier: AGPL-3.0-only + +import * as log from '../logging/log'; +import type { MessageModel } from '../models/messages'; +import * as Errors from '../types/errors'; + +export async function getMessageById( + messageId: string +): Promise { + let message = window.MessageController.getById(messageId); + if (message) { + return message; + } + + try { + message = await window.Signal.Data.getMessageById(messageId, { + Message: window.Whisper.Message, + }); + } catch (err: unknown) { + log.error( + `failed to load message with id ${messageId} ` + + `due to error ${Errors.toLogFormat(err)}` + ); + } + + if (!message) { + return undefined; + } + + message = window.MessageController.register(message.id, message); + return message; +} diff --git a/ts/models/messages.ts b/ts/models/messages.ts index eefb9d1454c2..d79cec7fa058 100644 --- a/ts/models/messages.ts +++ b/ts/models/messages.ts @@ -3324,33 +3324,6 @@ export class MessageModel extends window.Backbone.Model { } } -export async function getMessageById( - messageId: string -): Promise { - let message = window.MessageController.getById(messageId); - if (message) { - return message; - } - - try { - message = await window.Signal.Data.getMessageById(messageId, { - Message: window.Whisper.Message, - }); - } catch (error) { - window.log.error( - `failed to load message with id ${messageId} ` + - `due to error ${error && error.stack}` - ); - } - - if (!message) { - return undefined; - } - - message = window.MessageController.register(message.id, message); - return message; -} - window.Whisper.Message = MessageModel; window.Whisper.Message.getLongMessageAttachment = ({