From a2185625c8b9953c2c05e989f11e05387023a920 Mon Sep 17 00:00:00 2001 From: William Grant Date: Thu, 21 Sep 2023 15:30:53 +1000 Subject: [PATCH] fix: use TTL_CONFIG in retrieve request also some comment cleanup --- ts/models/message.ts | 1 - ts/receiver/contentMessage.ts | 18 +++++++----------- ts/session/apis/snode_api/retrieveRequest.ts | 4 ++-- ts/session/apis/snode_api/snodeSignatures.ts | 4 +++- .../messages/outgoing/ExpirableMessage.ts | 1 - 5 files changed, 12 insertions(+), 16 deletions(-) diff --git a/ts/models/message.ts b/ts/models/message.ts index eb852504b..efb5b6691 100644 --- a/ts/models/message.ts +++ b/ts/models/message.ts @@ -1177,7 +1177,6 @@ export class MessageModel extends Backbone.Model { const messageHash = this.get('messageHash'); if (messageHash) { - // TODO Consolidate the snode /expire logic across all the different functions that call it. await expireMessageOnSnode({ messageHash, expireTimer: this.get('expireTimer'), diff --git a/ts/receiver/contentMessage.ts b/ts/receiver/contentMessage.ts index d9270051b..2bf1435bf 100644 --- a/ts/receiver/contentMessage.ts +++ b/ts/receiver/contentMessage.ts @@ -475,22 +475,18 @@ export async function innerHandleSwarmContentMessage( content.dataMessage.profileKey = null; } - // window.log.debug( - // `WIP: innerHandleSwarmContentMessage: running checkForExpireUpdateInContentMessage for ${envelope.id}` - // ); - const expireUpdate = await checkForExpireUpdateInContentMessage( content, conversationModelForUIUpdate ); - window.log.debug( - `WIP:innerHandleSwarmContentMessage: ${ - content.dataMessage.syncTarget ? 'This is a sync message.\n' : '' - } content: ${JSON.stringify(content)} ${ - expireUpdate ? `\n\nexpireUpdate: ${JSON.stringify(expireUpdate)}` : '' - }` - ); + // window.log.debug( + // `WIP:innerHandleSwarmContentMessage: ${ + // content.dataMessage.syncTarget ? 'This is a sync message.\n' : '' + // } content: ${JSON.stringify(content)} ${ + // expireUpdate ? `\n\nexpireUpdate: ${JSON.stringify(expireUpdate)}` : '' + // }` + // ); if (expireUpdate?.isOutdated) { window.log.debug(`WIP: ExpireUpdate is outdated. Ignoring it and removing from cache.`); diff --git a/ts/session/apis/snode_api/retrieveRequest.ts b/ts/session/apis/snode_api/retrieveRequest.ts index 2502d1add..d462628f9 100644 --- a/ts/session/apis/snode_api/retrieveRequest.ts +++ b/ts/session/apis/snode_api/retrieveRequest.ts @@ -5,7 +5,7 @@ import { doSnodeBatchRequest } from './batchRequest'; import { GetNetworkTime } from './getNetworkTime'; import { SnodeNamespace, SnodeNamespaces } from './namespaces'; -import { DURATION } from '../../constants'; +import { TTL_DEFAULT } from '../../constants'; import { UserUtils } from '../../utils'; import { RetrieveLegacyClosedGroupSubRequestType, @@ -74,7 +74,7 @@ async function buildRetrieveRequest( ); if (configHashesToBump?.length) { - const expiry = GetNetworkTime.getNowWithNetworkOffset() + DURATION.DAYS * 30; + const expiry = GetNetworkTime.getNowWithNetworkOffset() + TTL_DEFAULT.TTL_CONFIG; const signResult = await SnodeSignature.generateUpdateExpirySignature({ shortenOrExtend: '', timestamp: expiry, diff --git a/ts/session/apis/snode_api/snodeSignatures.ts b/ts/session/apis/snode_api/snodeSignatures.ts index 5bc22c805..2288875a0 100644 --- a/ts/session/apis/snode_api/snodeSignatures.ts +++ b/ts/session/apis/snode_api/snodeSignatures.ts @@ -96,12 +96,14 @@ async function getSnodeSignatureParams(params: { } } +/** + * NOTE if shortenOrExtend is an empty string it means we want to hardcode the expiry to a TTL value, otherwise it's to shorten or extend the TTL + */ async function generateUpdateExpirySignature({ shortenOrExtend, timestamp, messageHashes, }: { - // NOTE empty string means we want to hardcode the expiry to a TTL value, otherwise it's a shorten or extension of the TTL shortenOrExtend: 'extend' | 'shorten' | ''; timestamp: number; messageHashes: Array; diff --git a/ts/session/messages/outgoing/ExpirableMessage.ts b/ts/session/messages/outgoing/ExpirableMessage.ts index d1e182374..348a32d9f 100644 --- a/ts/session/messages/outgoing/ExpirableMessage.ts +++ b/ts/session/messages/outgoing/ExpirableMessage.ts @@ -53,7 +53,6 @@ export class ExpirableMessage extends ContentMessage { return this.expirationType; } - // TODO legacy messages? + update expire endpoint for message after read public ttl(): number { switch (this.expirationType) { case 'deleteAfterSend':