Comment Threads: Fix sometimes missing top message
This commit is contained in:
parent
f26f30ccb9
commit
a70efbbd08
@ -103,26 +103,11 @@ export async function fetchMessages({
|
||||
const chats = result.chats.map((c) => buildApiChatFromPreview(c)).filter<ApiChat>(Boolean as any);
|
||||
const threadInfos = messages.map(({ threadInfo }) => threadInfo).filter<ApiThreadInfo>(Boolean as any);
|
||||
|
||||
// Not sure if there is an easier way to do this
|
||||
let firstMessageId: number | undefined;
|
||||
if (result.messages.length) {
|
||||
if (result instanceof GramJs.messages.Messages) {
|
||||
firstMessageId = result.messages[result.messages.length - 1].id;
|
||||
} else if (pagination.offsetId && result.offsetIdOffset) {
|
||||
const offsetIdIndex = result.messages.findIndex((m) => m.id === pagination.offsetId);
|
||||
const lastIndex = result.messages.length - offsetIdIndex;
|
||||
if (lastIndex + result.offsetIdOffset >= result.count) {
|
||||
firstMessageId = result.messages[result.messages.length - 1].id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
messages,
|
||||
users,
|
||||
chats,
|
||||
threadInfos,
|
||||
firstMessageId,
|
||||
};
|
||||
}
|
||||
|
||||
@ -702,6 +687,8 @@ export async function requestThreadInfoUpdate({
|
||||
invokeRequest(new GramJs.messages.GetReplies({
|
||||
peer: buildInputPeer(chat.id, chat.accessHash),
|
||||
msgId: threadId,
|
||||
offsetId: 1,
|
||||
addOffset: -1,
|
||||
limit: 1,
|
||||
})),
|
||||
]);
|
||||
@ -724,6 +711,9 @@ export async function requestThreadInfoUpdate({
|
||||
lastReadInboxMessageId: topMessageResult.readInboxMaxId,
|
||||
messagesCount: (repliesResult instanceof GramJs.messages.ChannelMessages) ? repliesResult.count : undefined,
|
||||
},
|
||||
firstMessageId: repliesResult && 'messages' in repliesResult && repliesResult.messages.length
|
||||
? repliesResult.messages[0].id
|
||||
: undefined,
|
||||
});
|
||||
|
||||
const chats = topMessageResult.chats.map((c) => buildApiChatFromPreview(c)).filter<ApiChat>(Boolean as any);
|
||||
|
||||
@ -174,6 +174,7 @@ export type ApiUpdateThreadInfo = {
|
||||
chatId: number;
|
||||
threadId: number;
|
||||
threadInfo: Partial<ApiThreadInfo>;
|
||||
firstMessageId?: number;
|
||||
};
|
||||
|
||||
export type ApiUpdateScheduledMessageSendSucceeded = {
|
||||
|
||||
@ -576,7 +576,7 @@ async function loadViewportMessages(
|
||||
}
|
||||
|
||||
const {
|
||||
messages, users, chats, threadInfos, firstMessageId,
|
||||
messages, users, chats, threadInfos,
|
||||
} = result;
|
||||
|
||||
const byId = buildCollectionByKey(messages, 'id');
|
||||
@ -592,10 +592,6 @@ async function loadViewportMessages(
|
||||
global = addChats(global, buildCollectionByKey(chats, 'id'));
|
||||
global = updateThreadInfos(global, chatId, threadInfos);
|
||||
|
||||
if (firstMessageId) {
|
||||
global = replaceThreadParam(global, chatId, threadId, 'firstMessageId', firstMessageId);
|
||||
}
|
||||
|
||||
let listedIds = selectListedIds(global, chatId, threadId);
|
||||
const outlyingIds = selectOutlyingIds(global, chatId, threadId);
|
||||
|
||||
|
||||
@ -210,7 +210,9 @@ addReducer('apiUpdate', (global, actions, update: ApiUpdate) => {
|
||||
}
|
||||
|
||||
case 'updateThreadInfo': {
|
||||
const { chatId, threadId, threadInfo } = update;
|
||||
const {
|
||||
chatId, threadId, threadInfo, firstMessageId,
|
||||
} = update;
|
||||
|
||||
const currentThreadInfo = selectThreadInfo(global, chatId, threadId);
|
||||
const newTheadInfo = {
|
||||
@ -223,6 +225,11 @@ addReducer('apiUpdate', (global, actions, update: ApiUpdate) => {
|
||||
}
|
||||
|
||||
global = updateThreadInfo(global, chatId, threadId, newTheadInfo as ApiThreadInfo);
|
||||
|
||||
if (firstMessageId) {
|
||||
global = replaceThreadParam(global, chatId, threadId, 'firstMessageId', firstMessageId);
|
||||
}
|
||||
|
||||
setGlobal(global);
|
||||
|
||||
break;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user