Retry outbound "normal" messages for up to a day

This commit is contained in:
Evan Hahn
2021-08-31 15:58:39 -05:00
committed by GitHub
parent 62cf51c060
commit a85dd1be36
30 changed files with 1414 additions and 603 deletions

View File

@@ -59,6 +59,8 @@ export const isDelivered = (status: SendStatus): boolean =>
STATUS_NUMBERS[status] >= STATUS_NUMBERS[SendStatus.Delivered];
export const isSent = (status: SendStatus): boolean =>
STATUS_NUMBERS[status] >= STATUS_NUMBERS[SendStatus.Sent];
export const isFailed = (status: SendStatus): boolean =>
status === SendStatus.Failed;
/**
* `SendState` combines `SendStatus` and a timestamp. You can use it to show things to the

View File

@@ -0,0 +1,46 @@
// 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 type { MessageAttributesType } from '../model-types.d';
import * as Errors from '../types/errors';
export async function getMessagesById(
messageIds: ReadonlyArray<string>
): Promise<Array<MessageModel>> {
const messagesFromMemory: Array<MessageModel> = [];
const messageIdsToLookUpInDatabase: Array<string> = [];
messageIds.forEach(messageId => {
const message = window.MessageController.getById(messageId);
if (message) {
messagesFromMemory.push(message);
} else {
messageIdsToLookUpInDatabase.push(messageId);
}
});
let rawMessagesFromDatabase: Array<MessageAttributesType>;
try {
rawMessagesFromDatabase = await window.Signal.Data.getMessagesById(
messageIdsToLookUpInDatabase
);
} catch (err: unknown) {
log.error(
`failed to load ${
messageIdsToLookUpInDatabase.length
} message(s) from database. ${Errors.toLogFormat(err)}`
);
return [];
}
const messagesFromDatabase = rawMessagesFromDatabase.map(rawMessage => {
// We use `window.Whisper.Message` instead of `MessageModel` here to avoid a circular
// import.
const message = new window.Whisper.Message(rawMessage);
return window.MessageController.register(message.id, message);
});
return [...messagesFromMemory, ...messagesFromDatabase];
}