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) {
this.set({ unread: 0 });
// TODO This logic needs to depend no the dm mode
if (this.get('expireTimer') && !this.get('expirationStartTimestamp')) {
const expirationStartTimestamp = Math.min(Date.now(), readAt || Date.now());
this.set({ expirationStartTimestamp });

@ -7,13 +7,17 @@ import { Reaction, ReactionList, SortedReactionList } from '../types/Reaction';
export type MessageModelType = 'incoming' | 'outgoing';
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 {
// the id of the message
// this can have several uses:
id: string;
source: string;
quote?: any;
expireTimer: number;
received_at?: number;
sent_at?: number;
preview?: any;
@ -21,9 +25,16 @@ export interface MessageAttributes {
reacts?: ReactionList;
reactsIndex?: number;
body?: string;
expirationType?: DisappearingMessageType;
expireTimer: 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;
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;
group_update?: MessageGroupUpdate;
groupInvitation?: any;
@ -34,11 +45,6 @@ export interface MessageAttributes {
hasAttachments: 1 | 0;
hasFileAttachments: 1 | 0;
hasVisualMediaAttachments: 1 | 0;
expirationTimerUpdate?: {
expireTimer: number;
source: string;
fromSync?: boolean;
};
/**
* 1 means unread, 0 or anything else is read.
*/
@ -157,7 +163,6 @@ export interface MessageAttributesOptionals {
id?: string;
source: string;
quote?: any;
expireTimer?: number;
received_at?: number;
sent_at?: number;
preview?: any;
@ -165,9 +170,16 @@ export interface MessageAttributesOptionals {
reacts?: ReactionList;
reactsIndex?: number;
body?: string;
expirationType?: DisappearingMessageType;
expireTimer?: 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;
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;
group_update?: MessageGroupUpdate;
groupInvitation?: any;
@ -179,11 +191,6 @@ export interface MessageAttributesOptionals {
hasAttachments?: boolean;
hasFileAttachments?: boolean;
hasVisualMediaAttachments?: boolean;
expirationTimerUpdate?: {
expireTimer: number;
source: string;
fromSync?: boolean;
};
dataExtractionNotification?: {
type: number;
source: string;

@ -1214,13 +1214,15 @@ function updateToSessionSchemaVersion30(currentVersion: number, db: BetterSqlite
console.log(`updateToSessionSchemaVersion${targetVersion}: starting...`);
db.transaction(() => {
db.exec(`
ALTER TABLE ${CONVERSATIONS_TABLE} ADD COLUMN expirationType TEXT DEFAULT "off";
`);
// Conversation changes
db.prepare(
`ALTER TABLE ${CONVERSATIONS_TABLE} ADD COLUMN expirationType TEXT DEFAULT "off";`
).run();
db.exec(`
ALTER TABLE ${CONVERSATIONS_TABLE} ADD COLUMN lastDisappearingMessageChangeTimestamp INTEGER DEFAULT 0;
`);
db.prepare(
`ALTER TABLE ${CONVERSATIONS_TABLE} ADD COLUMN lastDisappearingMessageChangeTimestamp INTEGER DEFAULT 0;
`
).run();
db.prepare(
`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;`
).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
// db.exec(
// `ALTER TABLE ${CONVERSATIONS_TABLE} RENAME COLUMN expireTimer TO expirationTimer;`
// );
// NOTE we won't update messages only conversations
// TODO but we do need to add the new columns later with the defaults
// Message changes
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);
})();

Loading…
Cancel
Save