Delete Sync: Handle and send mostRecentNonExpiringMessages if needed
Co-authored-by: Scott Nonnenberg <scott@signal.org>
This commit is contained in:
parent
d1b0bd79bc
commit
50e07ec389
13 changed files with 356 additions and 46 deletions
|
@ -733,6 +733,10 @@ export type DataInterface = {
|
|||
conversationId: string,
|
||||
limit?: number
|
||||
) => Promise<Array<MessageType>>;
|
||||
getMostRecentAddressableNondisappearingMessages: (
|
||||
conversationId: string,
|
||||
limit?: number
|
||||
) => Promise<Array<MessageType>>;
|
||||
|
||||
removeSyncTaskById: (id: string) => Promise<void>;
|
||||
saveSyncTasks: (tasks: Array<SyncTaskType>) => Promise<void>;
|
||||
|
|
|
@ -372,6 +372,7 @@ const dataInterface: ServerInterface = {
|
|||
saveEditedMessage,
|
||||
saveEditedMessages,
|
||||
getMostRecentAddressableMessages,
|
||||
getMostRecentAddressableNondisappearingMessages,
|
||||
|
||||
removeSyncTaskById,
|
||||
saveSyncTasks,
|
||||
|
@ -2119,6 +2120,39 @@ export function getMostRecentAddressableMessagesSync(
|
|||
return rows.map(row => jsonToObject(row.json));
|
||||
}
|
||||
|
||||
async function getMostRecentAddressableNondisappearingMessages(
|
||||
conversationId: string,
|
||||
limit = 5
|
||||
): Promise<Array<MessageType>> {
|
||||
const db = getReadonlyInstance();
|
||||
return getMostRecentAddressableNondisappearingMessagesSync(
|
||||
db,
|
||||
conversationId,
|
||||
limit
|
||||
);
|
||||
}
|
||||
|
||||
export function getMostRecentAddressableNondisappearingMessagesSync(
|
||||
db: Database,
|
||||
conversationId: string,
|
||||
limit = 5
|
||||
): Array<MessageType> {
|
||||
const [query, parameters] = sql`
|
||||
SELECT json FROM messages
|
||||
INDEXED BY messages_by_date_addressable_nondisappearing
|
||||
WHERE
|
||||
expireTimer IS NULL AND
|
||||
conversationId IS ${conversationId} AND
|
||||
isAddressableMessage = 1
|
||||
ORDER BY received_at DESC, sent_at DESC
|
||||
LIMIT ${limit};
|
||||
`;
|
||||
|
||||
const rows = db.prepare(query).all(parameters);
|
||||
|
||||
return rows.map(row => jsonToObject(row.json));
|
||||
}
|
||||
|
||||
async function removeSyncTaskById(id: string): Promise<void> {
|
||||
const db = await getWritableInstance();
|
||||
removeSyncTaskByIdSync(db, id);
|
||||
|
|
31
ts/sql/migrations/1080-nondisappearing-addressable.ts
Normal file
31
ts/sql/migrations/1080-nondisappearing-addressable.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
// Copyright 2024 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import type { Database } from '@signalapp/better-sqlite3';
|
||||
|
||||
import type { LoggerType } from '../../types/Logging';
|
||||
|
||||
export const version = 1080;
|
||||
|
||||
export function updateToSchemaVersion1080(
|
||||
currentVersion: number,
|
||||
db: Database,
|
||||
logger: LoggerType
|
||||
): void {
|
||||
if (currentVersion >= 1080) {
|
||||
return;
|
||||
}
|
||||
|
||||
db.transaction(() => {
|
||||
db.exec(`
|
||||
CREATE INDEX messages_by_date_addressable_nondisappearing
|
||||
ON messages (
|
||||
conversationId, isAddressableMessage, received_at, sent_at
|
||||
) WHERE expireTimer IS NULL;
|
||||
`);
|
||||
})();
|
||||
|
||||
db.pragma('user_version = 1080');
|
||||
|
||||
logger.info('updateToSchemaVersion1080: success!');
|
||||
}
|
|
@ -82,10 +82,11 @@ import { updateToSchemaVersion1030 } from './1030-unblock-event';
|
|||
import { updateToSchemaVersion1040 } from './1040-undownloaded-backed-up-media';
|
||||
import { updateToSchemaVersion1050 } from './1050-group-send-endorsements';
|
||||
import { updateToSchemaVersion1060 } from './1060-addressable-messages-and-sync-tasks';
|
||||
import { updateToSchemaVersion1070 } from './1070-attachment-backup';
|
||||
import {
|
||||
updateToSchemaVersion1070,
|
||||
updateToSchemaVersion1080,
|
||||
version as MAX_VERSION,
|
||||
} from './1070-attachment-backup';
|
||||
} from './1080-nondisappearing-addressable';
|
||||
|
||||
function updateToSchemaVersion1(
|
||||
currentVersion: number,
|
||||
|
@ -2036,6 +2037,7 @@ export const SCHEMA_VERSIONS = [
|
|||
updateToSchemaVersion1050,
|
||||
updateToSchemaVersion1060,
|
||||
updateToSchemaVersion1070,
|
||||
updateToSchemaVersion1080,
|
||||
];
|
||||
|
||||
export class DBVersionFromFutureError extends Error {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue