try a fix to prevent window from jumping with low number of messages

pull/2190/head
Audric Ackermann 3 years ago
parent 2e200df933
commit 75c7c7c27f
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -2286,6 +2286,9 @@ function getMessagesByConversation(conversationId, { messageId = null } = {}) {
// If messageId is null, it means we are just opening the convo to the last unread message, or at the bottom
const firstUnread = getFirstUnreadMessageIdInConversation(conversationId);
const numberOfMessagesInConvo = getMessagesCountByConversation(globalInstance, conversationId);
const floorLoadAllMessagesInConvo = 70;
if (messageId || firstUnread) {
const messageFound = getMessageById(messageId || firstUnread);
@ -2310,7 +2313,10 @@ function getMessagesByConversation(conversationId, { messageId = null } = {}) {
.all({
conversationId,
messageId: messageId || firstUnread,
limit: absLimit,
limit:
numberOfMessagesInConvo < floorLoadAllMessagesInConvo
? floorLoadAllMessagesInConvo
: absLimit,
});
return map(rows, row => jsonToObject(row.json));
@ -2320,7 +2326,10 @@ function getMessagesByConversation(conversationId, { messageId = null } = {}) {
);
}
const limit = 2 * absLimit;
const limit =
numberOfMessagesInConvo < floorLoadAllMessagesInConvo
? floorLoadAllMessagesInConvo
: 2 * absLimit;
const rows = globalInstance
.prepare(

@ -329,6 +329,8 @@ async function getMessages({
conversationKey: string;
messageId: string | null;
}): Promise<Array<MessageModelPropsWithoutConvoProps>> {
const beforeTimestamp = Date.now();
const conversation = getConversationController().get(conversationKey);
if (!conversation) {
// no valid conversation, early return
@ -343,6 +345,8 @@ async function getMessages({
const messageProps: Array<MessageModelPropsWithoutConvoProps> = messageSet.models.map(m =>
m.getMessageModelProps()
);
const time = Date.now() - beforeTimestamp;
window?.log?.info(`Loading ${messageProps.length} messages took ${time}ms to load.`);
return messageProps;
}
@ -373,13 +377,10 @@ export const fetchTopMessagesForConversation = createAsyncThunk(
window.log.info('fetchTopMessagesForConversation: we are already at the top');
return null;
}
const beforeTimestamp = Date.now();
const messagesProps = await getMessages({
conversationKey,
messageId: oldTopMessageId,
});
const time = Date.now() - beforeTimestamp;
window?.log?.info(`Loading ${messagesProps.length} messages took ${time}ms to load.`);
return {
conversationKey,
@ -405,7 +406,6 @@ export const fetchBottomMessagesForConversation = createAsyncThunk(
conversationKey: string;
oldBottomMessageId: string | null;
}): Promise<FetchedBottomMessageResults> => {
const beforeTimestamp = Date.now();
// no need to load more bottom if we are already at the bottom
const mostRecentMessage = await getLastMessageInConversation(conversationKey);
@ -417,8 +417,6 @@ export const fetchBottomMessagesForConversation = createAsyncThunk(
conversationKey,
messageId: oldBottomMessageId,
});
const time = Date.now() - beforeTimestamp;
window?.log?.info(`Loading ${messagesProps.length} messages took ${time}ms to load.`);
return {
conversationKey,

Loading…
Cancel
Save