2021-09-02 17:44:54 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import * as log from '../logging/log';
|
2021-12-10 22:51:54 +00:00
|
|
|
import type { MessageAttributesType } from '../model-types.d';
|
2021-09-02 17:44:54 +00:00
|
|
|
import * as Errors from '../types/errors';
|
2023-10-04 00:12:57 +00:00
|
|
|
import type { MessageModel } from '../models/messages';
|
2021-09-02 17:44:54 +00:00
|
|
|
|
2023-10-04 00:12:57 +00:00
|
|
|
export async function __DEPRECATED$getMessageById(
|
2021-09-02 17:44:54 +00:00
|
|
|
messageId: string
|
|
|
|
): Promise<MessageModel | undefined> {
|
2023-10-04 00:12:57 +00:00
|
|
|
const message = window.MessageCache.__DEPRECATED$getById(messageId);
|
2021-09-02 17:44:54 +00:00
|
|
|
if (message) {
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
2021-12-10 22:51:54 +00:00
|
|
|
let found: MessageAttributesType | undefined;
|
2021-09-02 17:44:54 +00:00
|
|
|
try {
|
2021-12-10 22:51:54 +00:00
|
|
|
found = await window.Signal.Data.getMessageById(messageId);
|
2021-09-02 17:44:54 +00:00
|
|
|
} catch (err: unknown) {
|
|
|
|
log.error(
|
|
|
|
`failed to load message with id ${messageId} ` +
|
|
|
|
`due to error ${Errors.toLogFormat(err)}`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-12-10 22:51:54 +00:00
|
|
|
if (!found) {
|
2021-09-02 17:44:54 +00:00
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2023-10-04 00:12:57 +00:00
|
|
|
return window.MessageCache.__DEPRECATED$register(
|
|
|
|
found.id,
|
|
|
|
found,
|
|
|
|
'__DEPRECATED$getMessageById'
|
|
|
|
);
|
2021-09-02 17:44:54 +00:00
|
|
|
}
|