fix: correctly write to db when setting changes

pull/2660/head
William Grant 2 years ago
parent ee6607b96a
commit 2745571790

@ -66,8 +66,8 @@ message MessageRequestResponse {
message Content {
enum ExpirationType {
DELETE_AFTER_SEND = 1;
DELETE_AFTER_READ = 2;
DELETE_AFTER_READ = 1;
DELETE_AFTER_SEND = 2;
}
optional DataMessage dataMessage = 1;

@ -169,6 +169,7 @@ const TimeOptions = (props: TimerOptionsProps) => {
};
export const OverlayDisappearingMessages = () => {
const dispatch = useDispatch();
const selectedConversationKey = useSelector(getSelectedConversationKey);
const disappearingModeOptions = DisappearingMessageConversationSetting;
const timerOptions = useSelector(getTimerOptions).timerOptions;
@ -221,6 +222,8 @@ export const OverlayDisappearingMessages = () => {
modeSelected,
timeSelected
);
dispatch(closeRightPanel());
dispatch(resetRightOverlayMode());
}
}}
>

@ -1048,7 +1048,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
return;
}
window?.log?.info('Updated conversation disappearing messages setting', {
window?.log?.info('WIP: Updated conversation disappearing messages setting', {
id: this.idForLogging(),
expirationType,
expireTimer,
@ -1080,9 +1080,6 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
source,
fromSync,
},
// TODO do we need this?
// expirationType,
// expireTimer,
};
let message: MessageModel | undefined;

@ -1032,14 +1032,27 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
expirationStartTimestamp: now,
});
const contentMessage = dataMessage.contentProto();
let expireUpdate = null;
if (contentMessage.expirationType && contentMessage.expirationTimer) {
expireUpdate = {
expirationType: contentMessage.expirationType,
expireTimer: contentMessage.expirationTimer,
lastDisappearingMessageChangeTimestamp:
contentMessage.lastDisappearingMessageChangeTimestamp,
};
}
await this.commit();
await this.sendSyncMessage(dataMessage, now);
await this.sendSyncMessage(dataMessage, now, expireUpdate);
}
public async sendSyncMessage(
data: DataMessage | SignalService.DataMessage,
sentTimestamp: number
sentTimestamp: number,
expireUpdate?: any
) {
if (this.get('synced') || this.get('sentSync')) {
return;
@ -1057,7 +1070,13 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
if (!conversation) {
throw new Error('Cannot trigger syncMessage with unknown convo.');
}
const syncMessage = buildSyncMessage(this.id, data, conversation.id, sentTimestamp);
const syncMessage = buildSyncMessage(
this.id,
data,
conversation.id,
sentTimestamp,
expireUpdate
);
await getMessageQueue().sendSyncMessage(syncMessage);
}
this.set({

@ -436,7 +436,10 @@ function saveConversation(data: ConversationAttributes, instance?: BetterSqlite3
profileKey,
zombies,
left,
expirationType,
// TODO rename expireTimer to expirationTimer
expireTimer,
lastDisappearingMessageChangeTimestamp,
mentionedUs,
unreadCount,
lastMessageStatus,
@ -480,7 +483,9 @@ function saveConversation(data: ConversationAttributes, instance?: BetterSqlite3
profileKey,
zombies,
left,
expirationType,
expireTimer,
lastDisappearingMessageChangeTimestamp,
mentionedUs,
unreadCount,
lastMessageStatus,
@ -513,7 +518,9 @@ function saveConversation(data: ConversationAttributes, instance?: BetterSqlite3
$profileKey,
$zombies,
$left,
$expirationType,
$expireTimer,
$lastDisappearingMessageChangeTimestamp,
$mentionedUs,
$unreadCount,
$lastMessageStatus,
@ -548,7 +555,9 @@ function saveConversation(data: ConversationAttributes, instance?: BetterSqlite3
profileKey,
zombies: zombies && zombies.length ? arrayStrToJson(zombies) : '[]',
left: toSqliteBoolean(left),
expirationType,
expireTimer,
lastDisappearingMessageChangeTimestamp,
mentionedUs: toSqliteBoolean(mentionedUs),
unreadCount,
lastMessageStatus,
@ -782,6 +791,7 @@ function saveMessage(data: any) {
source,
type,
unread,
expirationType,
expireTimer,
expirationStartTimestamp,
} = data;
@ -804,6 +814,7 @@ function saveMessage(data: any) {
conversationId,
expirationStartTimestamp,
expires_at,
expirationType,
expireTimer,
hasAttachments,
hasFileAttachments,
@ -827,6 +838,7 @@ function saveMessage(data: any) {
conversationId,
expirationStartTimestamp,
expires_at,
expirationType,
expireTimer,
hasAttachments,
hasFileAttachments,
@ -846,6 +858,7 @@ function saveMessage(data: any) {
$conversationId,
$expirationStartTimestamp,
$expires_at,
$expirationType,
$expireTimer,
$hasAttachments,
$hasFileAttachments,
@ -1454,6 +1467,7 @@ function getSeenMessagesByHashList(hashes: Array<string>) {
function getExpiredMessages() {
const now = Date.now();
// TODO probably need to update and also add functions to find specific kinds of disappearing messages
const rows = assertGlobalInstance()
.prepare(
`SELECT json FROM ${MESSAGES_TABLE} WHERE
@ -1485,6 +1499,7 @@ function getOutgoingWithoutExpiresAt() {
return map(rows, row => jsonToObject(row.json));
}
// TODO Maybe we need different queries for the different modes?
function getNextExpiringMessage() {
const rows = assertGlobalInstance()
.prepare(

@ -28,6 +28,7 @@ import {
import { ConversationTypeEnum } from '../models/conversationAttributes';
import { findCachedBlindedMatchOrLookupOnAllServers } from '../session/apis/open_group_api/sogsv3/knownBlindedkeys';
import { appendFetchAvatarAndProfileJob } from './userProfileImageUpdates';
import { DisappearingMessageConversationSetting } from '../util/expiringMessages';
export async function handleSwarmContentMessage(envelope: EnvelopePlus, messageHash: string) {
try {
@ -401,12 +402,18 @@ export async function innerHandleSwarmContentMessage(
perfStart(`handleSwarmDataMessage-${envelope.id}`);
const expirationType = DisappearingMessageConversationSetting[content.expirationType] || null;
// NOTE In the protobuf this is a long
const lastDisappearingMessageChangeTimestamp =
Number(content.lastDisappearingMessageChangeTimestamp) || null;
let expireUpdate = null;
if (content.expirationType && content.expirationTimer) {
if (expirationType && content.expirationTimer) {
expireUpdate = {
expirationType: content.expirationType,
expirationTimer: content.expirationTimer,
expirationType,
// TODO rename to expireTimer
expireTimer: content.expirationTimer,
lastDisappearingMessageChangeTimestamp,
};
}

@ -12,7 +12,7 @@ import {
import { ConversationModel } from '../../models/conversation';
import { fromBase64ToArray, fromHexToArray } from './String';
import { SignalService } from '../../protobuf';
import _ from 'lodash';
import _, { isEmpty } from 'lodash';
import {
AttachmentPointerWithUrl,
PreviewWithAttachmentUrl,
@ -323,7 +323,8 @@ export const buildSyncMessage = (
identifier: string,
data: DataMessage | SignalService.DataMessage,
syncTarget: string,
sentTimestamp: number
sentTimestamp: number,
expireUpdate?: any
): VisibleMessage | ExpirationTimerUpdateMessage => {
if (
(data as any).constructor.name !== 'DataMessage' &&
@ -332,19 +333,7 @@ export const buildSyncMessage = (
window?.log?.warn('buildSyncMessage with something else than a DataMessage');
}
// TODO Remove DataMessage expireTimer 2 weeks after the release
const dataMessage = data instanceof DataMessage ? data.dataProto() : data;
const contentMessage = data instanceof DataMessage ? data.contentProto() : null;
const expirationType =
contentMessage?.expirationType === SignalService.Content.ExpirationType.DELETE_AFTER_SEND
? 'deleteAfterSend'
: contentMessage?.expirationType === SignalService.Content.ExpirationType.DELETE_AFTER_READ
? 'deleteAfterRead'
: null;
const expireTimer = contentMessage?.expirationTimer || dataMessage.expireTimer;
const lastDisappearingMessageChangeTimestamp = contentMessage?.lastDisappearingMessageChangeTimestamp
? Number(contentMessage?.lastDisappearingMessageChangeTimestamp)
: null;
if (!sentTimestamp || !_.isNumber(sentTimestamp)) {
throw new Error('Tried to build a sync message without a sentTimestamp');
@ -352,14 +341,14 @@ export const buildSyncMessage = (
// don't include our profileKey on syncing message. This is to be done by a ConfigurationMessage now
const timestamp = _.toNumber(sentTimestamp);
if (
contentMessage?.expirationType &&
!isEmpty(expireUpdate) &&
dataMessage.flags === SignalService.DataMessage.Flags.EXPIRATION_TIMER_UPDATE
) {
return buildSyncExpireTimerMessage(
identifier,
expirationType,
expireTimer,
lastDisappearingMessageChangeTimestamp,
expireUpdate.expirationType,
expireUpdate.expireTimer,
expireUpdate.lastDisappearingMessageChangeTimestamp,
timestamp,
syncTarget
);

@ -10,7 +10,6 @@ import { getConversationController } from '../session/conversations';
// 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 const DisappearingMessageConversationSetting = ['off', ...DisappearingMessageMode];

Loading…
Cancel
Save