do not fetch all messages for room if user was away for > 2 weeks

This commit is contained in:
Audric Ackermann 2021-05-24 13:17:15 +10:00
parent ab22126b45
commit eff4f490f3
No known key found for this signature in database
GPG key ID: 999F434D76324AD4
3 changed files with 14 additions and 2 deletions

View file

@ -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
};

View file

@ -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 });
})
);

View file

@ -410,6 +410,7 @@ const handleNewMessages = async (
if (roomInfos && roomInfos.lastMessageFetchedServerID !== maxNewMessageId) {
roomInfos.lastMessageFetchedServerID = maxNewMessageId;
roomInfos.lastFetchTimestamp = Date.now();
await saveV2OpenGroupRoom(roomInfos);
}
} catch (e) {