From f5e27c80e1ad08742c02776f30ac691f291352e6 Mon Sep 17 00:00:00 2001 From: balzack Date: Thu, 2 Mar 2023 20:51:20 -0800 Subject: [PATCH] optimizing topic load --- .../src/context/useConversationContext.hook.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/mobile/src/context/useConversationContext.hook.js b/app/mobile/src/context/useConversationContext.hook.js index d5f1b8d7..5bd2d6ce 100644 --- a/app/mobile/src/context/useConversationContext.hook.js +++ b/app/mobile/src/context/useConversationContext.hook.js @@ -61,6 +61,7 @@ export function useConversationContext() { const cardValue = cardId ? card.state.cards.get(cardId) : null; const channelValue = cardId ? cardValue?.channels.get(channelId) : channel.state.channels.get(channelId); const { topicRevision } = channelValue || {}; + let setChannel = false; if (channelValue) { if (!loaded.current) { @@ -75,6 +76,9 @@ export function useConversationContext() { curTopicMarker.current = topicMarker; loaded.current = true; } + else { + setChannel = true; + } } else { console.log("failed to load conversation"); @@ -89,20 +93,25 @@ export function useConversationContext() { await setMarkerAndSync(cardId, channelId, delta.marker, topicRevision); curTopicMarker.current = delta.marker; curSyncRevision.current = topicRevision; + updateState({ offsync: false, topics: topics.current, card: cardValue, channel: channelValue }); } - if (loadMore && marker) { + else if (loadMore && marker) { const delta = await getTopicDelta(cardId, channelId, null, COUNT, null, curTopicMarker.current); await setTopicDelta(cardId, channelId, delta.topics); await setTopicMarker(cardId, channelId, delta.marker); curTopicMarker.current = delta.marker; + updateState({ offsync: false, topics: topics.current, card: cardValue, channel: channelValue }); } - if (ignoreRevision || topicRevision !== curSyncRevision.current) { + else if (ignoreRevision || topicRevision !== curSyncRevision.current) { const delta = await getTopicDelta(cardId, channelId, curSyncRevision.current, null, curTopicMarker.current, null); await setTopicDelta(cardId, channelId, delta.topics); await setSyncRevision(cardId, channelId, topicRevision); curSyncRevision.current = topicRevision; + updateState({ offsync: false, topics: topics.current, card: cardValue, channel: channelValue }); + } + else if (setChannel) { + updateState({ offsync: false, topics: topics.current, card: cardValue, channel: channelValue }); } - updateState({ offsync: false, topics: topics.current, card: cardValue, channel: channelValue }); } catch(err) { console.log(err);