mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2025-12-05 01:10:49 +00:00
Improve DOE behavior for poll messages
This commit is contained in:
25
ts/sql/migrations/1561-cleanup-polls.std.ts
Normal file
25
ts/sql/migrations/1561-cleanup-polls.std.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
// Copyright 2025 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import type { LoggerType } from '../../types/Logging.std.js';
|
||||
import type { WritableDB } from '../Interface.std.js';
|
||||
import { sql } from '../util.std.js';
|
||||
|
||||
// This migration was backported to earlier branches as 1541 and 1551
|
||||
export default function updateToSchemaVersion1561(
|
||||
db: WritableDB,
|
||||
logger: LoggerType
|
||||
): void {
|
||||
const [query, params] = sql`
|
||||
UPDATE messages
|
||||
SET
|
||||
json = json_remove(json, '$.poll'),
|
||||
hasUnreadPollVotes = 0
|
||||
WHERE isErased = 1 AND (
|
||||
json->'poll' IS NOT NULL OR
|
||||
hasUnreadPollVotes IS NOT 0
|
||||
)
|
||||
`;
|
||||
const result = db.prepare(query).run(params);
|
||||
logger.info(`Updated ${result.changes} poll messages`);
|
||||
}
|
||||
@@ -132,6 +132,7 @@ import updateToSchemaVersion1530 from './1530-update-expiring-index.std.js';
|
||||
import updateToSchemaVersion1540 from './1540-partial-expiring-index.std.js';
|
||||
import updateToSchemaVersion1550 from './1550-has-link-preview.std.js';
|
||||
import updateToSchemaVersion1560 from './1560-pinned-messages.std.js';
|
||||
import updateToSchemaVersion1561 from './1561-cleanup-polls.std.js';
|
||||
|
||||
import { DataWriter } from '../Server.node.js';
|
||||
|
||||
@@ -1622,6 +1623,8 @@ export const SCHEMA_VERSIONS: ReadonlyArray<SchemaUpdateType> = [
|
||||
{ version: 1540, update: updateToSchemaVersion1540 },
|
||||
{ version: 1550, update: updateToSchemaVersion1550 },
|
||||
{ version: 1560, update: updateToSchemaVersion1560 },
|
||||
// 1561, 1551, and 1541 all refer to the same migration
|
||||
{ version: 1561, update: updateToSchemaVersion1561 },
|
||||
];
|
||||
|
||||
export class DBVersionFromFutureError extends Error {
|
||||
|
||||
80
ts/test-node/sql/migration_1561_test.node.ts
Normal file
80
ts/test-node/sql/migration_1561_test.node.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
// Copyright 2025 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
import { assert } from 'chai';
|
||||
|
||||
import { type WritableDB } from '../../sql/Interface.std.js';
|
||||
import {
|
||||
createDB,
|
||||
getTableData,
|
||||
insertData,
|
||||
updateToVersion,
|
||||
} from './helpers.node.js';
|
||||
|
||||
describe('SQL/updateToSchemaVersion1561', () => {
|
||||
let db: WritableDB;
|
||||
|
||||
beforeEach(() => {
|
||||
db = createDB();
|
||||
updateToVersion(db, 1560);
|
||||
});
|
||||
afterEach(() => {
|
||||
db.close();
|
||||
});
|
||||
|
||||
it('removes json.poll and hasUnreadPollVotes', () => {
|
||||
insertData(db, 'messages', [
|
||||
{
|
||||
id: 'message-id',
|
||||
isErased: 0,
|
||||
json: {
|
||||
id: 'message-id',
|
||||
poll: {
|
||||
question: 'poll question',
|
||||
},
|
||||
},
|
||||
hasUnreadPollVotes: 1,
|
||||
},
|
||||
{
|
||||
id: 'message-id-2',
|
||||
isErased: 1,
|
||||
json: {
|
||||
id: 'message-id-2',
|
||||
poll: {
|
||||
question: 'poll question',
|
||||
},
|
||||
},
|
||||
hasUnreadPollVotes: 1,
|
||||
},
|
||||
]);
|
||||
updateToVersion(db, 1561);
|
||||
assert.deepStrictEqual(
|
||||
getTableData(db, 'messages').map(row => ({
|
||||
id: row.id,
|
||||
json: row.json,
|
||||
isErased: row.isErased,
|
||||
hasUnreadPollVotes: row.hasUnreadPollVotes,
|
||||
})),
|
||||
[
|
||||
{
|
||||
id: 'message-id',
|
||||
isErased: 0,
|
||||
json: {
|
||||
id: 'message-id',
|
||||
poll: {
|
||||
question: 'poll question',
|
||||
},
|
||||
},
|
||||
hasUnreadPollVotes: 1,
|
||||
},
|
||||
{
|
||||
id: 'message-id-2',
|
||||
isErased: 1,
|
||||
json: {
|
||||
id: 'message-id-2',
|
||||
},
|
||||
hasUnreadPollVotes: 0,
|
||||
},
|
||||
]
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -65,8 +65,10 @@ export async function eraseMessageContents(
|
||||
bodyRanges: undefined,
|
||||
contact: [],
|
||||
editHistory: undefined,
|
||||
hasUnreadPollVotes: undefined,
|
||||
isErased: true,
|
||||
preview: [],
|
||||
poll: undefined,
|
||||
quote: undefined,
|
||||
sticker: undefined,
|
||||
...additionalProperties,
|
||||
|
||||
Reference in New Issue
Block a user