No Backbone in data layer; server/client interfaces are now similar
This commit is contained in:
parent
064bbfe97a
commit
34fd945f83
31 changed files with 573 additions and 1021 deletions
|
@ -5,6 +5,7 @@ import type { MessageModel } from '../models/messages';
|
|||
import * as durations from './durations';
|
||||
import { map, filter } from './iterables';
|
||||
import { isNotNil } from './isNotNil';
|
||||
import type { MessageAttributesType } from '../model-types.d';
|
||||
|
||||
const FIVE_MINUTES = 5 * durations.MINUTE;
|
||||
|
||||
|
@ -29,9 +30,12 @@ export class MessageController {
|
|||
return instance;
|
||||
}
|
||||
|
||||
register(id: string, message: MessageModel): MessageModel {
|
||||
if (!id || !message) {
|
||||
return message;
|
||||
register(
|
||||
id: string,
|
||||
data: MessageModel | MessageAttributesType
|
||||
): MessageModel {
|
||||
if (!id || !data) {
|
||||
throw new Error('MessageController.register: Got falsey id or message');
|
||||
}
|
||||
|
||||
const existing = this.messageLookup[id];
|
||||
|
@ -43,6 +47,8 @@ export class MessageController {
|
|||
return existing.message;
|
||||
}
|
||||
|
||||
const message =
|
||||
'attributes' in data ? data : new window.Whisper.Message(data);
|
||||
this.messageLookup[id] = {
|
||||
message,
|
||||
timestamp: Date.now(),
|
||||
|
|
36
ts/util/cleanup.ts
Normal file
36
ts/util/cleanup.ts
Normal file
|
@ -0,0 +1,36 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import type { MessageAttributesType } from '../model-types.d';
|
||||
import { deletePackReference } from '../types/Stickers';
|
||||
|
||||
export async function cleanupMessage(
|
||||
message: MessageAttributesType
|
||||
): Promise<void> {
|
||||
const { id, conversationId } = message;
|
||||
|
||||
window.reduxActions?.conversations.messageDeleted(id, conversationId);
|
||||
|
||||
const parentConversation = window.ConversationController.get(conversationId);
|
||||
parentConversation?.debouncedUpdateLastMessage?.();
|
||||
|
||||
window.MessageController.unregister(id);
|
||||
|
||||
await deleteMessageData(message);
|
||||
}
|
||||
|
||||
export async function deleteMessageData(
|
||||
message: MessageAttributesType
|
||||
): Promise<void> {
|
||||
await window.Signal.Migrations.deleteExternalMessageFiles(message);
|
||||
|
||||
const { sticker } = message;
|
||||
if (!sticker) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { packId } = sticker;
|
||||
if (packId) {
|
||||
await deletePackReference(message.id, packId);
|
||||
}
|
||||
}
|
|
@ -347,9 +347,7 @@ async function getRetryConversation({
|
|||
}
|
||||
|
||||
const [messageId] = messageIds;
|
||||
const message = await window.Signal.Data.getMessageById(messageId, {
|
||||
Message: window.Whisper.Message,
|
||||
});
|
||||
const message = await window.Signal.Data.getMessageById(messageId);
|
||||
if (!message) {
|
||||
log.warn(
|
||||
`getRetryConversation/${logId}: Unable to find message ${messageId}`
|
||||
|
@ -358,7 +356,7 @@ async function getRetryConversation({
|
|||
return window.ConversationController.get(requestGroupId);
|
||||
}
|
||||
|
||||
const conversationId = message.get('conversationId');
|
||||
const { conversationId } = message;
|
||||
return window.ConversationController.get(conversationId);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue