From f3e207d0b0eae4e16af129c595dcdcf2e2060977 Mon Sep 17 00:00:00 2001 From: Evan Hahn <69474926+EvanHahn-Signal@users.noreply.github.com> Date: Wed, 19 May 2021 11:17:51 -0500 Subject: [PATCH] Use timestamp instead of full model for tap-to-view age outs --- js/expiring_tap_to_view_messages.js | 9 ++------- ts/sql/Client.ts | 15 +++------------ ts/sql/Interface.ts | 5 +---- ts/sql/Server.ts | 16 +++++++++------- 4 files changed, 15 insertions(+), 30 deletions(-) diff --git a/js/expiring_tap_to_view_messages.js b/js/expiring_tap_to_view_messages.js index 32cc027db5e7..54d29bdfa120 100644 --- a/js/expiring_tap_to_view_messages.js +++ b/js/expiring_tap_to_view_messages.js @@ -50,16 +50,11 @@ const HOUR = 60 * MINUTE; const THIRTY_DAYS = 30 * 24 * HOUR; - const toAgeOut = await window.Signal.Data.getNextTapToViewMessageToAgeOut({ - Message: Whisper.Message, - }); - - if (!toAgeOut) { + const receivedAt = await window.Signal.Data.getNextTapToViewMessageTimestampToAgeOut(); + if (!receivedAt) { return; } - const receivedAt = - toAgeOut.get('received_at_ms') || toAgeOut.get('received_at'); const nextCheck = receivedAt + THIRTY_DAYS; Whisper.TapToViewMessagesListener.nextCheck = nextCheck; diff --git a/ts/sql/Client.ts b/ts/sql/Client.ts index fce1dff4048e..2e280a0d0612 100644 --- a/ts/sql/Client.ts +++ b/ts/sql/Client.ts @@ -188,7 +188,7 @@ const dataInterface: ClientInterface = { getExpiredMessages, getOutgoingWithoutExpiresAt, getNextExpiringMessage, - getNextTapToViewMessageToAgeOut, + getNextTapToViewMessageTimestampToAgeOut, getTapToViewMessagesNeedingErase, getOlderMessagesByConversation, getNewerMessagesByConversation, @@ -1324,17 +1324,8 @@ async function getNextExpiringMessage({ return null; } -async function getNextTapToViewMessageToAgeOut({ - Message, -}: { - Message: typeof MessageModel; -}) { - const message = await channels.getNextTapToViewMessageToAgeOut(); - if (!message) { - return null; - } - - return new Message(message); +async function getNextTapToViewMessageTimestampToAgeOut() { + return channels.getNextTapToViewMessageTimestampToAgeOut(); } async function getTapToViewMessagesNeedingErase({ MessageCollection, diff --git a/ts/sql/Interface.ts b/ts/sql/Interface.ts index 7a39d44c0c03..9e8569b474f8 100644 --- a/ts/sql/Interface.ts +++ b/ts/sql/Interface.ts @@ -229,6 +229,7 @@ export type DataInterface = { obsoleteId: string, currentId: string ) => Promise; + getNextTapToViewMessageTimestampToAgeOut: () => Promise; getUnprocessedCount: () => Promise; getAllUnprocessed: () => Promise>; @@ -359,7 +360,6 @@ export type ServerInterface = DataInterface & { ourConversationId: string; }) => Promise; getNextExpiringMessage: () => Promise; - getNextTapToViewMessageToAgeOut: () => Promise; getOutgoingWithoutExpiresAt: () => Promise>; getTapToViewMessagesNeedingErase: () => Promise>; getUnreadCountForConversation: (conversationId: string) => Promise; @@ -497,9 +497,6 @@ export type ClientInterface = DataInterface & { getNextExpiringMessage: (options: { Message: typeof MessageModel; }) => Promise; - getNextTapToViewMessageToAgeOut: (options: { - Message: typeof MessageModel; - }) => Promise; getOutgoingWithoutExpiresAt: (options: { MessageCollection: typeof MessageModelCollectionType; }) => Promise; diff --git a/ts/sql/Server.ts b/ts/sql/Server.ts index 88298284407b..8a379754b128 100644 --- a/ts/sql/Server.ts +++ b/ts/sql/Server.ts @@ -178,7 +178,7 @@ const dataInterface: ServerInterface = { getExpiredMessages, getOutgoingWithoutExpiresAt, getNextExpiringMessage, - getNextTapToViewMessageToAgeOut, + getNextTapToViewMessageTimestampToAgeOut, getTapToViewMessagesNeedingErase, getOlderMessagesByConversation, getNewerMessagesByConversation, @@ -3924,11 +3924,11 @@ async function getNextExpiringMessage(): Promise { return jsonToObject(rows[0].json); } -async function getNextTapToViewMessageToAgeOut(): Promise< - MessageType | undefined +async function getNextTapToViewMessageTimestampToAgeOut(): Promise< + undefined | number > { const db = getInstance(); - const rows = db + const row = db .prepare( ` SELECT json FROM messages @@ -3939,13 +3939,15 @@ async function getNextTapToViewMessageToAgeOut(): Promise< LIMIT 1; ` ) - .all(); + .get(); - if (!rows || rows.length < 1) { + if (!row) { return undefined; } - return jsonToObject(rows[0].json); + const data = jsonToObject(row.json); + const result = data.received_at_ms || data.received_at; + return isNormalNumber(result) ? result : undefined; } async function getTapToViewMessagesNeedingErase(): Promise> {