Skip to content

Commit

Permalink
Don't load more for a chat that is no longer returning additional mes…
Browse files Browse the repository at this point in the history
…sages
  • Loading branch information
EricRabil committed Apr 5, 2021
1 parent f02bccc commit d26bd98
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/components/transcript/ChatTranscriptFoundation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ export async function reload(chatID: string, before?: string) {

Log.info("Received messages for chat %s from REST", chatID);

isDoneLedger[chatID] = recentMessages.length <= 1;

receiveMessages(recentMessages);
}

const loadingLedger: Record<string, boolean | undefined> = {};
const isDoneLedger: Record<string, boolean | undefined> = {};

export function useMessages(chatID?: string, reverse = false, injectTimestamps = true): [MessageRepresentation[], () => Promise<void>] {
const allMessages = useSelector(selectMessages);
Expand All @@ -42,7 +45,7 @@ export function useMessages(chatID?: string, reverse = false, injectTimestamps =
processedMessages,
async () => {
if (!chatID) return;
if (loadingLedger[chatID]) return;
if (loadingLedger[chatID] || isDoneLedger[chatID]) return;
loadingLedger[chatID] = true;
const lastMessage = processedMessages[reverse ? (processedMessages.length - 1) : 0];
const lastMessageID = lastMessage[TIMESTAMP_ASSOCIATION] as string || lastMessage.id;
Expand Down

0 comments on commit d26bd98

Please sign in to comment.