Move getMessageById
next to getMessagesById
This commit is contained in:
parent
8e0b94e720
commit
01b015680b
4 changed files with 36 additions and 29 deletions
|
@ -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';
|
||||
|
|
|
@ -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';
|
||||
|
|
33
ts/messages/getMessageById.ts
Normal file
33
ts/messages/getMessageById.ts
Normal file
|
@ -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<MessageModel | undefined> {
|
||||
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;
|
||||
}
|
|
@ -3324,33 +3324,6 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
}
|
||||
}
|
||||
|
||||
export async function getMessageById(
|
||||
messageId: string
|
||||
): Promise<MessageModel | undefined> {
|
||||
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 = ({
|
||||
|
|
Loading…
Reference in a new issue