Notifications for a few merge-related scenarios

This commit is contained in:
Scott Nonnenberg 2022-12-05 14:46:54 -08:00 committed by GitHub
parent 78ce34b9d3
commit a49a6f2057
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
40 changed files with 2764 additions and 553 deletions

View file

@ -0,0 +1,123 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import type { Database } from 'better-sqlite3';
import type { LoggerType } from '../../types/Logging';
export default function updateToSchemaVersion71(
currentVersion: number,
db: Database,
logger: LoggerType
): void {
if (currentVersion >= 71) {
return;
}
db.transaction(() => {
db.exec(
`
--- These will be re-added below
DROP INDEX messages_preview;
DROP INDEX messages_activity;
DROP INDEX message_user_initiated;
--- Thse will also be re-added below
ALTER TABLE messages DROP COLUMN shouldAffectActivity;
ALTER TABLE messages DROP COLUMN shouldAffectPreview;
ALTER TABLE messages DROP COLUMN isUserInitiatedMessage;
--- Note: These generated columns were originally introduced in migration 47, and
--- are mostly the same
--- Based on the current list (model-types.ts), the types which DO affect activity:
--- NULL (old, malformed data)
--- call-history
--- chat-session-refreshed (deprecated)
--- delivery-issue
--- group (deprecated)
--- group-v2-change
--- incoming
--- outgoing
--- timer-notification
--- (change: added conversation-merge, keychange, and phone-number-discovery)
ALTER TABLE messages
ADD COLUMN shouldAffectActivity INTEGER
GENERATED ALWAYS AS (
type IS NULL
OR
type NOT IN (
'change-number-notification',
'conversation-merge',
'group-v1-migration',
'keychange',
'message-history-unsynced',
'phone-number-discovery',
'profile-change',
'story',
'universal-timer-notification',
'verified-change'
)
);
--- (change: added conversation-merge and phone-number-discovery
--- (now matches the above list)
ALTER TABLE messages
ADD COLUMN shouldAffectPreview INTEGER
GENERATED ALWAYS AS (
type IS NULL
OR
type NOT IN (
'change-number-notification',
'conversation-merge',
'group-v1-migration',
'keychange',
'message-history-unsynced',
'phone-number-discovery',
'profile-change',
'story',
'universal-timer-notification',
'verified-change'
)
);
--- Note: This list only differs from the above on these types:
--- group-v2-change
--- (change: added conversation-merge and phone-number-discovery
ALTER TABLE messages
ADD COLUMN isUserInitiatedMessage INTEGER
GENERATED ALWAYS AS (
type IS NULL
OR
type NOT IN (
'change-number-notification',
'conversation-merge',
'group-v1-migration',
'group-v2-change',
'keychange',
'message-history-unsynced',
'phone-number-discovery',
'profile-change',
'story',
'universal-timer-notification',
'verified-change'
)
);
CREATE INDEX messages_preview ON messages
(conversationId, shouldAffectPreview, isGroupLeaveEventFromOther, expiresAt, received_at, sent_at);
CREATE INDEX messages_activity ON messages
(conversationId, shouldAffectActivity, isTimerChangeFromSync, isGroupLeaveEventFromOther, received_at, sent_at);
CREATE INDEX message_user_initiated ON messages (isUserInitiatedMessage);
`
);
db.pragma('user_version = 71');
})();
logger.info('updateToSchemaVersion71: success!');
}

View file

@ -46,6 +46,7 @@ import updateToSchemaVersion67 from './67-add-story-to-unprocessed';
import updateToSchemaVersion68 from './68-drop-deprecated-columns';
import updateToSchemaVersion69 from './69-group-call-ring-cancellations';
import updateToSchemaVersion70 from './70-story-reply-index';
import updateToSchemaVersion71 from './71-merge-notifications';
function updateToSchemaVersion1(
currentVersion: number,
@ -1893,6 +1894,7 @@ export const SCHEMA_VERSIONS = [
updateToSchemaVersion7,
updateToSchemaVersion8,
updateToSchemaVersion9,
updateToSchemaVersion10,
updateToSchemaVersion11,
updateToSchemaVersion12,
@ -1903,6 +1905,7 @@ export const SCHEMA_VERSIONS = [
updateToSchemaVersion17,
updateToSchemaVersion18,
updateToSchemaVersion19,
updateToSchemaVersion20,
updateToSchemaVersion21,
updateToSchemaVersion22,
@ -1913,6 +1916,7 @@ export const SCHEMA_VERSIONS = [
updateToSchemaVersion27,
updateToSchemaVersion28,
updateToSchemaVersion29,
updateToSchemaVersion30,
updateToSchemaVersion31,
updateToSchemaVersion32,
@ -1923,6 +1927,7 @@ export const SCHEMA_VERSIONS = [
updateToSchemaVersion37,
updateToSchemaVersion38,
updateToSchemaVersion39,
updateToSchemaVersion40,
updateToSchemaVersion41,
updateToSchemaVersion42,
@ -1933,6 +1938,7 @@ export const SCHEMA_VERSIONS = [
updateToSchemaVersion47,
updateToSchemaVersion48,
updateToSchemaVersion49,
updateToSchemaVersion50,
updateToSchemaVersion51,
updateToSchemaVersion52,
@ -1943,6 +1949,7 @@ export const SCHEMA_VERSIONS = [
updateToSchemaVersion57,
updateToSchemaVersion58,
updateToSchemaVersion59,
updateToSchemaVersion60,
updateToSchemaVersion61,
updateToSchemaVersion62,
@ -1953,7 +1960,9 @@ export const SCHEMA_VERSIONS = [
updateToSchemaVersion67,
updateToSchemaVersion68,
updateToSchemaVersion69,
updateToSchemaVersion70,
updateToSchemaVersion71,
];
export function updateSchema(db: Database, logger: LoggerType): void {