feat: added expirationType to message model with correct typings

added to migration
pull/2660/head
William Grant 2 years ago
parent b12d086b22
commit 1303707cd7

@ -1136,6 +1136,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
public markReadNoCommit(readAt: number) { public markReadNoCommit(readAt: number) {
this.set({ unread: 0 }); this.set({ unread: 0 });
// TODO This logic needs to depend no the dm mode
if (this.get('expireTimer') && !this.get('expirationStartTimestamp')) { if (this.get('expireTimer') && !this.get('expirationStartTimestamp')) {
const expirationStartTimestamp = Math.min(Date.now(), readAt || Date.now()); const expirationStartTimestamp = Math.min(Date.now(), readAt || Date.now());
this.set({ expirationStartTimestamp }); this.set({ expirationStartTimestamp });

@ -7,13 +7,17 @@ import { Reaction, ReactionList, SortedReactionList } from '../types/Reaction';
export type MessageModelType = 'incoming' | 'outgoing'; export type MessageModelType = 'incoming' | 'outgoing';
export type MessageDeliveryStatus = 'sending' | 'sent' | 'read' | 'error'; export type MessageDeliveryStatus = 'sending' | 'sent' | 'read' | 'error';
// TODO Might need to be improved by using an enum
export const DisappearingMessageMode = ['deleteAfterRead', 'deleteAfterSend'];
// TODO might need to be improved
export type DisappearingMessageType = typeof DisappearingMessageMode[number] | null;
export interface MessageAttributes { export interface MessageAttributes {
// the id of the message // the id of the message
// this can have several uses: // this can have several uses:
id: string; id: string;
source: string; source: string;
quote?: any; quote?: any;
expireTimer: number;
received_at?: number; received_at?: number;
sent_at?: number; sent_at?: number;
preview?: any; preview?: any;
@ -21,9 +25,16 @@ export interface MessageAttributes {
reacts?: ReactionList; reacts?: ReactionList;
reactsIndex?: number; reactsIndex?: number;
body?: string; body?: string;
expirationType?: DisappearingMessageType;
expireTimer: number;
expirationStartTimestamp: number; expirationStartTimestamp: number;
read_by: Array<string>; // we actually only care about the length of this. values are not used for anything
expires_at?: number; expires_at?: number;
expirationTimerUpdate?: {
expireTimer: number;
source: string;
fromSync?: boolean;
};
read_by: Array<string>; // we actually only care about the length of this. values are not used for anything
type: MessageModelType; type: MessageModelType;
group_update?: MessageGroupUpdate; group_update?: MessageGroupUpdate;
groupInvitation?: any; groupInvitation?: any;
@ -34,11 +45,6 @@ export interface MessageAttributes {
hasAttachments: 1 | 0; hasAttachments: 1 | 0;
hasFileAttachments: 1 | 0; hasFileAttachments: 1 | 0;
hasVisualMediaAttachments: 1 | 0; hasVisualMediaAttachments: 1 | 0;
expirationTimerUpdate?: {
expireTimer: number;
source: string;
fromSync?: boolean;
};
/** /**
* 1 means unread, 0 or anything else is read. * 1 means unread, 0 or anything else is read.
*/ */
@ -157,7 +163,6 @@ export interface MessageAttributesOptionals {
id?: string; id?: string;
source: string; source: string;
quote?: any; quote?: any;
expireTimer?: number;
received_at?: number; received_at?: number;
sent_at?: number; sent_at?: number;
preview?: any; preview?: any;
@ -165,9 +170,16 @@ export interface MessageAttributesOptionals {
reacts?: ReactionList; reacts?: ReactionList;
reactsIndex?: number; reactsIndex?: number;
body?: string; body?: string;
expirationType?: DisappearingMessageType;
expireTimer?: number;
expirationStartTimestamp?: number; expirationStartTimestamp?: number;
read_by?: Array<string>; // we actually only care about the length of this. values are not used for anything
expires_at?: number; expires_at?: number;
expirationTimerUpdate?: {
expireTimer: number;
source: string;
fromSync?: boolean;
};
read_by?: Array<string>; // we actually only care about the length of this. values are not used for anything
type: MessageModelType; type: MessageModelType;
group_update?: MessageGroupUpdate; group_update?: MessageGroupUpdate;
groupInvitation?: any; groupInvitation?: any;
@ -179,11 +191,6 @@ export interface MessageAttributesOptionals {
hasAttachments?: boolean; hasAttachments?: boolean;
hasFileAttachments?: boolean; hasFileAttachments?: boolean;
hasVisualMediaAttachments?: boolean; hasVisualMediaAttachments?: boolean;
expirationTimerUpdate?: {
expireTimer: number;
source: string;
fromSync?: boolean;
};
dataExtractionNotification?: { dataExtractionNotification?: {
type: number; type: number;
source: string; source: string;

@ -1214,13 +1214,15 @@ function updateToSessionSchemaVersion30(currentVersion: number, db: BetterSqlite
console.log(`updateToSessionSchemaVersion${targetVersion}: starting...`); console.log(`updateToSessionSchemaVersion${targetVersion}: starting...`);
db.transaction(() => { db.transaction(() => {
db.exec(` // Conversation changes
ALTER TABLE ${CONVERSATIONS_TABLE} ADD COLUMN expirationType TEXT DEFAULT "off"; db.prepare(
`); `ALTER TABLE ${CONVERSATIONS_TABLE} ADD COLUMN expirationType TEXT DEFAULT "off";`
).run();
db.exec(` db.prepare(
ALTER TABLE ${CONVERSATIONS_TABLE} ADD COLUMN lastDisappearingMessageChangeTimestamp INTEGER DEFAULT 0; `ALTER TABLE ${CONVERSATIONS_TABLE} ADD COLUMN lastDisappearingMessageChangeTimestamp INTEGER DEFAULT 0;
`); `
).run();
db.prepare( db.prepare(
`UPDATE ${CONVERSATIONS_TABLE} SET `UPDATE ${CONVERSATIONS_TABLE} SET
@ -1234,14 +1236,19 @@ function updateToSessionSchemaVersion30(currentVersion: number, db: BetterSqlite
WHERE (type = 'group' AND is_medium_group = true) AND expireTimer > 0;` WHERE (type = 'group' AND is_medium_group = true) AND expireTimer > 0;`
).run({ expirationType: 'deleteAfterSend' }); ).run({ expirationType: 'deleteAfterSend' });
// TODO After testing -> renamed expireTimer column to expirationTimer everywhere. // TODO After testing -> rename expireTimer column to expirationTimer everywhere.
// Update Conversation Model expireTimer calls everywhere // Update Conversation Model expireTimer calls everywhere
// db.exec( // db.exec(
// `ALTER TABLE ${CONVERSATIONS_TABLE} RENAME COLUMN expireTimer TO expirationTimer;` // `ALTER TABLE ${CONVERSATIONS_TABLE} RENAME COLUMN expireTimer TO expirationTimer;`
// ); // );
// NOTE we won't update messages only conversations // Message changes
// TODO but we do need to add the new columns later with the defaults db.prepare(`ALTER TABLE ${MESSAGES_TABLE} ADD COLUMN expirationType TEXT;`).run();
// TODO After testing -> rename expireTimer column to expirationTimer everywhere.
// db.exec(
// `ALTER TABLE ${MESSAGES_TABLE} RENAME COLUMN expireTimer TO expirationTimer;`
// );
writeSessionSchemaVersion(targetVersion, db); writeSessionSchemaVersion(targetVersion, db);
})(); })();

Loading…
Cancel
Save