2023-01-03 11:55:46 -08:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
2020-10-30 15:34:04 -05:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2025-01-10 08:18:32 +10:00
|
|
|
import type { MessageAttributesType } from '../model-types.d';
|
|
|
|
import type { CallbackResultType } from '../textsecure/Types.d';
|
2021-09-17 14:27:53 -04:00
|
|
|
import * as log from '../logging/log';
|
2023-10-03 20:12:57 -04:00
|
|
|
|
2025-01-10 08:18:32 +10:00
|
|
|
type StringKey<T> = keyof T & string;
|
2023-10-03 20:12:57 -04:00
|
|
|
|
2025-01-10 08:18:32 +10:00
|
|
|
export class MessageModel {
|
|
|
|
public get id(): string {
|
2025-01-14 11:11:52 -08:00
|
|
|
return this.#_attributes.id;
|
2021-06-17 10:15:10 -07:00
|
|
|
}
|
|
|
|
|
2025-01-10 08:18:32 +10:00
|
|
|
public get<keyName extends StringKey<MessageAttributesType>>(
|
|
|
|
key: keyName
|
|
|
|
): MessageAttributesType[keyName] {
|
|
|
|
return this.attributes[key];
|
2022-08-25 10:16:37 -06:00
|
|
|
}
|
2025-01-10 08:18:32 +10:00
|
|
|
public set(
|
|
|
|
attributes: Partial<MessageAttributesType>,
|
|
|
|
{ noTrigger }: { noTrigger?: boolean } = {}
|
|
|
|
): void {
|
2025-01-14 11:11:52 -08:00
|
|
|
this.#_attributes = {
|
2025-01-10 08:18:32 +10:00
|
|
|
...this.attributes,
|
|
|
|
...attributes,
|
2020-09-24 13:57:54 -07:00
|
|
|
};
|
2021-07-19 17:44:49 -05:00
|
|
|
|
2025-01-10 08:18:32 +10:00
|
|
|
if (noTrigger) {
|
2021-07-15 16:48:09 -07:00
|
|
|
return;
|
|
|
|
}
|
2020-09-24 13:57:54 -07:00
|
|
|
|
2025-01-10 08:18:32 +10:00
|
|
|
window.MessageCache._updateCaches(this);
|
2020-09-24 13:57:54 -07:00
|
|
|
}
|
|
|
|
|
2025-01-10 08:18:32 +10:00
|
|
|
public get attributes(): Readonly<MessageAttributesType> {
|
2025-01-14 11:11:52 -08:00
|
|
|
return this.#_attributes;
|
2021-03-22 11:51:53 -07:00
|
|
|
}
|
2025-01-14 11:11:52 -08:00
|
|
|
#_attributes: MessageAttributesType;
|
2021-03-22 11:51:53 -07:00
|
|
|
|
2025-01-10 08:18:32 +10:00
|
|
|
constructor(attributes: MessageAttributesType) {
|
2025-01-14 11:11:52 -08:00
|
|
|
this.#_attributes = attributes;
|
2025-01-10 08:18:32 +10:00
|
|
|
|
|
|
|
this.set(
|
|
|
|
window.Signal.Types.Message.initializeSchemaVersion({
|
|
|
|
message: attributes,
|
|
|
|
logger: log,
|
|
|
|
}),
|
|
|
|
{ noTrigger: true }
|
2022-11-02 16:48:38 -07:00
|
|
|
);
|
2020-09-24 13:57:54 -07:00
|
|
|
}
|
|
|
|
|
2025-01-10 08:18:32 +10:00
|
|
|
// --- Other housekeeping:
|
2020-09-24 13:57:54 -07:00
|
|
|
|
2025-01-10 08:18:32 +10:00
|
|
|
// Set when sending some sync messages, so we get the functionality of
|
|
|
|
// send(), without zombie messages going into the database.
|
|
|
|
doNotSave?: boolean;
|
|
|
|
// Set when sending stories, so we get the functionality of send() but we are
|
|
|
|
// able to send the sync message elsewhere.
|
|
|
|
doNotSendSyncMessage?: boolean;
|
2021-03-03 11:03:11 -08:00
|
|
|
|
2025-01-10 08:18:32 +10:00
|
|
|
deletingForEveryone?: boolean;
|
2023-07-19 20:17:13 -04:00
|
|
|
|
2025-01-10 08:18:32 +10:00
|
|
|
pendingMarkRead?: number;
|
2023-07-19 20:17:13 -04:00
|
|
|
|
2025-01-10 08:18:32 +10:00
|
|
|
syncPromise?: Promise<CallbackResultType | void>;
|
2020-09-24 13:57:54 -07:00
|
|
|
}
|