From 46ab397a0fe3c35dd0fb18058e34e176f7aae8b6 Mon Sep 17 00:00:00 2001 From: William Grant Date: Mon, 3 Apr 2023 14:09:06 +0200 Subject: [PATCH] fix: read receipt messages now show expireTimer correctly --- ts/models/message.ts | 1 - ts/session/apis/snode_api/expire.ts | 14 +++++++------- ts/util/readReceipts.ts | 7 +++---- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/ts/models/message.ts b/ts/models/message.ts index 07508bb8e..92d24fdc5 100644 --- a/ts/models/message.ts +++ b/ts/models/message.ts @@ -1190,7 +1190,6 @@ export class MessageModel extends Backbone.Model { await this.commit(); // the line below makes sure that getNextExpiringMessage will find this message as expiring. // getNextExpiringMessage is used on app start to clean already expired messages which should have been removed already, but are not - await this.setToExpire(); const convo = this.getConversation(); diff --git a/ts/session/apis/snode_api/expire.ts b/ts/session/apis/snode_api/expire.ts index 99336c01a..4e0d482b5 100644 --- a/ts/session/apis/snode_api/expire.ts +++ b/ts/session/apis/snode_api/expire.ts @@ -31,7 +31,7 @@ async function generateSignature({ // "expire" || ShortenOrExtend || expiry || messages[0] || ... || messages[N] const verificationString = `expire${shortenOrExtend}${timestamp}${messageHashes.join('')}`; const verificationData = StringUtils.encode(verificationString, 'utf8'); - // console.log(`WIP: generateSignature verificationString ${verificationString}`); + // window.log.info(`WIP: generateSignature verificationString ${verificationString}`); const message = new Uint8Array(verificationData); const sodium = await getSodiumRenderer(); @@ -91,7 +91,7 @@ async function verifySignature({ const verificationString = `${pubkey.key}${expiryApplied}${hashes.join('')}`; const verificationData = StringUtils.encode(verificationString, 'utf8'); - // console.log(`WIP: verifySignature verificationString`, verificationString); + // window.log.info(`WIP: verifySignature verificationString`, verificationString); const sodium = await getSodiumRenderer(); try { @@ -120,10 +120,10 @@ async function processExpirationResults( // TODO need proper typing for swarm and results const results: Record; expiry: number }> = {}; - // console.log(`WIP: processExpirationResults start`, swarm, messageHashes); + // window.log.info(`WIP: processExpirationResults start`, swarm, messageHashes); for (const nodeKey of Object.keys(swarm)) { - // console.log(`WIP: processExpirationResults processing nodeKey`, nodeKey, swarm[nodeKey]); + // window.log.info(`WIP: processExpirationResults processing nodeKey`, nodeKey, swarm[nodeKey]); if (!isEmpty(swarm[nodeKey].failed)) { const reason = 'Unknown'; const statusCode = '404'; @@ -197,7 +197,7 @@ async function expireOnNodes(targetNode: Snode, params: ExpireParams) { // parsed.swarm, // params.messages // ); - // console.log(`WIP: expireOnNodes attempt complete. Here are the results`, expirationResults); + // window.log.info(`WIP: expireOnNodes attempt complete. Here are the results`, expirationResults); return true; } catch (e) { @@ -223,7 +223,7 @@ type ExpireMessageOnSnodeProps = { export async function expireMessageOnSnode(props: ExpireMessageOnSnodeProps) { const { messageHash, expireTimer, extend, shorten } = props; - console.log(`WIP: expireMessageOnSnode running!`); + window.log.info(`WIP: expireMessageOnSnode running!`); if (extend && shorten) { window.log.info( @@ -289,7 +289,7 @@ export async function expireMessageOnSnode(props: ExpireMessageOnSnodeProps) { try { const firstSuccessSnode = await firstTrue(promises); snode = firstSuccessSnode; - console.log(`WIP: expireMessageOnSnode firstSuccessSnode`, firstSuccessSnode); + window.log.info(`WIP: expireMessageOnSnode firstSuccessSnode`, firstSuccessSnode); } catch (e) { const snodeStr = snode ? `${snode.ip}:${snode.port}` : 'null'; window?.log?.warn( diff --git a/ts/util/readReceipts.ts b/ts/util/readReceipts.ts index b6674eaca..2404e12f9 100644 --- a/ts/util/readReceipts.ts +++ b/ts/util/readReceipts.ts @@ -45,9 +45,7 @@ async function onReadReceipt(receipt: { source: string; timestamp: number; readA // readBy is only used for private conversations // we do not care of who read it. If the length is > 0 , it is read and false otherwise let readBy = message.get('read_by') || []; - // TODO Fix this with read receipts - // tslint:disable-next-line: no-unnecessary-initializer - const expirationStartTimestamp = undefined; + const expirationStartTimestamp = message.get('expirationStartTimestamp') || undefined; if (!readBy.length) { readBy.push(receipt.source); @@ -62,7 +60,8 @@ async function onReadReceipt(receipt: { source: string; timestamp: number; readA sent: true, }); - if (message.isExpiring() && !expirationStartTimestamp) { + // I think this is redundent since expirationStartTimestamp is always undefined and this the function will null return + if (message.isExpiring() && expirationStartTimestamp) { // This will save the message for us while starting the timer await message.setToExpire(); } else {