diff --git a/ts/data/opengroups.ts b/ts/data/opengroups.ts index 6a85d856a..05f74541c 100644 --- a/ts/data/opengroups.ts +++ b/ts/data/opengroups.ts @@ -15,6 +15,10 @@ export type OpenGroupV2Room = { * This value represents the rowId of the last message deleted. Not the id of the last message ID */ lastMessageDeletedServerID?: number; + /** + * This value is set with the current timestamp whenever we get new messages. + */ + lastFetchTimestamp?: number; token?: string; // currently, the token is on a per room basis }; diff --git a/ts/opengroup/opengroupV2/OpenGroupAPIV2CompactPoll.ts b/ts/opengroup/opengroupV2/OpenGroupAPIV2CompactPoll.ts index 52e3fe0a9..25d38bf0e 100644 --- a/ts/opengroup/opengroupV2/OpenGroupAPIV2CompactPoll.ts +++ b/ts/opengroup/opengroupV2/OpenGroupAPIV2CompactPoll.ts @@ -188,6 +188,7 @@ const getCompactPollRequest = async ( try { const { lastMessageFetchedServerID, + lastFetchTimestamp, lastMessageDeletedServerID, token, roomId, @@ -197,7 +198,13 @@ const getCompactPollRequest = async ( auth_token: token || '', }; roomRequestContent.from_deletion_server_id = lastMessageDeletedServerID; - roomRequestContent.from_message_server_id = lastMessageFetchedServerID; + if (Date.now() - (lastFetchTimestamp || 0) <= DURATION.DAYS * 14) { + roomRequestContent.from_message_server_id = lastMessageFetchedServerID; + } else { + window?.log?.info( + "We've been away for a long time... Only fetching last messages of room" + ); + } return roomRequestContent; } catch (e) { @@ -276,7 +283,7 @@ async function sendOpenGroupV2RequestCompactPoll( roomDetails.token = undefined; // we might need to retry doing the request here, but how to make sure we don't retry indefinetely? await saveV2OpenGroupRoom(roomDetails); - // do not await for that. We have a only one at a time logic on a per room basis + // we should not await for that. We have a only one at a time logic on a per room basis await getAuthToken({ serverUrl, roomId }); }) ); diff --git a/ts/opengroup/opengroupV2/OpenGroupServerPoller.ts b/ts/opengroup/opengroupV2/OpenGroupServerPoller.ts index b0cece56e..e71c82780 100644 --- a/ts/opengroup/opengroupV2/OpenGroupServerPoller.ts +++ b/ts/opengroup/opengroupV2/OpenGroupServerPoller.ts @@ -410,6 +410,7 @@ const handleNewMessages = async ( if (roomInfos && roomInfos.lastMessageFetchedServerID !== maxNewMessageId) { roomInfos.lastMessageFetchedServerID = maxNewMessageId; + roomInfos.lastFetchTimestamp = Date.now(); await saveV2OpenGroupRoom(roomInfos); } } catch (e) {