From b3d0264e93043d223c9a2c84fa591a326e396a4f Mon Sep 17 00:00:00 2001 From: Felix Hallenberg Date: Fri, 10 May 2024 10:39:51 +0300 Subject: [PATCH] Move new older-than params to front of the queue --- src/api/messages.ts | 1 + src/state/reducers/messages.ts | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/api/messages.ts b/src/api/messages.ts index b87a36f2..74663df1 100644 --- a/src/api/messages.ts +++ b/src/api/messages.ts @@ -230,6 +230,7 @@ export const getOlderThanParamsIfHasUnread = (buddyId: string): Array => { console.log('getOlderThanParamsIfHasUnread for buddyId:', buddyId); const buddyMessages = messages[buddyId] ?? {}; + const sorted = Object.keys(buddyMessages).map( msgId => buddyMessages[msgId], ); diff --git a/src/state/reducers/messages.ts b/src/state/reducers/messages.ts index 733b0005..826f9dd4 100644 --- a/src/state/reducers/messages.ts +++ b/src/state/reducers/messages.ts @@ -103,6 +103,7 @@ export const reducer: automaton.Reducer = ( // case 2: marking unread message // case 3: marking unread only for messages that are seen 100% console.log('got messages', newMessages); + const newOlderThanParams = messageApi.getParamsForUnreadMessages( newMessages, state.currentParams, @@ -132,7 +133,7 @@ export const reducer: automaton.Reducer = ( messages: RD.success(nextMessages), previousMsgId, currentParams: nextCurrent, - pollingQueue: [...nextQueue, ...newOlderThanParams], + pollingQueue: [...newOlderThanParams, ...nextQueue], }, nextCmd, );