mirror of
https://github.com/jkingsman/Remote-Terminal-for-MeshCore.git
synced 2026-03-28 17:43:05 +01:00
Fix logic for oldest-message detection on new message in focused convo and then paging
This commit is contained in:
@@ -127,8 +127,13 @@ export function useConversationMessages(
|
||||
)
|
||||
return;
|
||||
|
||||
// Get the oldest message as cursor for the next page
|
||||
const oldestMessage = messages[messages.length - 1];
|
||||
// Get the true oldest message as cursor for the next page
|
||||
const oldestMessage = messages.reduce((oldest, msg) => {
|
||||
if (!oldest) return msg;
|
||||
if (msg.received_at < oldest.received_at) return msg;
|
||||
if (msg.received_at === oldest.received_at && msg.id < oldest.id) return msg;
|
||||
return oldest;
|
||||
}, null as Message | null);
|
||||
if (!oldestMessage) return;
|
||||
|
||||
setLoadingOlder(true);
|
||||
|
||||
Reference in New Issue
Block a user