mirror of
https://github.com/jkingsman/Remote-Terminal-for-MeshCore.git
synced 2026-07-05 17:32:10 +02:00
Cleanups: Normalize pub keys, prefix message claiming, cursor + null timestamp DB cleanups
This commit is contained in:
@@ -138,6 +138,8 @@ export const api = {
|
||||
offset?: number;
|
||||
type?: 'PRIV' | 'CHAN';
|
||||
conversation_key?: string;
|
||||
before?: number;
|
||||
before_id?: number;
|
||||
},
|
||||
signal?: AbortSignal
|
||||
) => {
|
||||
@@ -146,6 +148,8 @@ export const api = {
|
||||
if (params?.offset) searchParams.set('offset', params.offset.toString());
|
||||
if (params?.type) searchParams.set('type', params.type);
|
||||
if (params?.conversation_key) searchParams.set('conversation_key', params.conversation_key);
|
||||
if (params?.before !== undefined) searchParams.set('before', params.before.toString());
|
||||
if (params?.before_id !== undefined) searchParams.set('before_id', params.before_id.toString());
|
||||
const query = searchParams.toString();
|
||||
return fetchJson<Message[]>(`/messages${query ? `?${query}` : ''}`, { signal });
|
||||
},
|
||||
|
||||
@@ -102,7 +102,7 @@ export function useConversationMessages(
|
||||
[activeConversation]
|
||||
);
|
||||
|
||||
// Fetch older messages (pagination)
|
||||
// Fetch older messages (cursor-based pagination)
|
||||
const fetchOlderMessages = useCallback(async () => {
|
||||
if (
|
||||
!activeConversation ||
|
||||
@@ -112,13 +112,18 @@ export function useConversationMessages(
|
||||
)
|
||||
return;
|
||||
|
||||
// Get the oldest message as cursor for the next page
|
||||
const oldestMessage = messages[messages.length - 1];
|
||||
if (!oldestMessage) return;
|
||||
|
||||
setLoadingOlder(true);
|
||||
try {
|
||||
const data = await api.getMessages({
|
||||
type: activeConversation.type === 'channel' ? 'CHAN' : 'PRIV',
|
||||
conversation_key: activeConversation.id,
|
||||
limit: MESSAGE_PAGE_SIZE,
|
||||
offset: messages.length,
|
||||
before: oldestMessage.received_at,
|
||||
before_id: oldestMessage.id,
|
||||
});
|
||||
|
||||
if (data.length > 0) {
|
||||
@@ -139,7 +144,7 @@ export function useConversationMessages(
|
||||
} finally {
|
||||
setLoadingOlder(false);
|
||||
}
|
||||
}, [activeConversation, loadingOlder, hasOlderMessages, messages.length]);
|
||||
}, [activeConversation, loadingOlder, hasOlderMessages, messages]);
|
||||
|
||||
// Fetch messages when conversation changes, with proper cancellation
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user