fix: исправлен критический баг - метод _loadAround не возвращал результат
ПРОБЛЕМЫ: - chatDetailV2.js не передавал lastReadTimestamp в config - метод _loadAround не имел return statement - scrollIntoView скроллил родительские контейнеры ИСПРАВЛЕНИЯ: ✅ Добавлен lastReadTimestamp в readConfig() chatDetailV2.js ✅ Добавлена передача lastReadTimestamp в ChatControllerV2 ✅ Исправлен _loadAround - добавлен return loadResult ✅ Заменен scrollIntoView на ручной расчет scrollTop в _scrollToMessage ✅ Добавлено подробное логирование для отладки РЕЗУЛЬТАТ: - Чат загружается вокруг последнего прочитанного (16 сообщений вместо 30) - Скролл к правильной позиции - Header не прячется под navbar - IntersectionObserver не срабатывает при инициализации
This commit is contained in:
parent
0fe736ede8
commit
7ad2cef7cc
@ -471,6 +471,12 @@ export class MessageLoaderV2 {
|
||||
requestKey
|
||||
);
|
||||
|
||||
console.log('[MessageLoaderV2] 🔍 API response:', {
|
||||
anchor_id: result.anchor_id,
|
||||
anchor_index: result.anchor_index,
|
||||
messages_count: result.messages?.length || result.results?.length || 0
|
||||
});
|
||||
|
||||
const messages = this._extractMessages(result);
|
||||
|
||||
// ВАЖНО: Сначала добавляем в Store, затем берем границы из Store
|
||||
@ -479,7 +485,7 @@ export class MessageLoaderV2 {
|
||||
const oldestMessage = this.store.getOldestMessage(chatId);
|
||||
const newestMessage = this.store.getNewestMessage(chatId);
|
||||
|
||||
return {
|
||||
const loadResult = {
|
||||
messages,
|
||||
anchorId: result.anchor_id || aroundId,
|
||||
anchorIndex: result.anchor_index || null,
|
||||
@ -488,6 +494,14 @@ export class MessageLoaderV2 {
|
||||
oldestId: oldestMessage?.id || null,
|
||||
newestId: newestMessage?.id || null
|
||||
};
|
||||
|
||||
console.log('[MessageLoaderV2] 🔍 Returning loadResult:', {
|
||||
anchorId: loadResult.anchorId,
|
||||
anchorIndex: loadResult.anchorIndex,
|
||||
messagesCount: loadResult.messages.length
|
||||
});
|
||||
|
||||
return loadResult;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -58,7 +58,7 @@
|
||||
|
||||
const scrollContainer = document.getElementById('chatScroll');
|
||||
|
||||
return {
|
||||
const config = {
|
||||
chatId: Number(appContainer.dataset.chatId),
|
||||
userId: Number(appContainer.dataset.userId),
|
||||
userName: appContainer.dataset.userName || 'Вы',
|
||||
@ -67,12 +67,22 @@
|
||||
messagesUrl: appContainer.dataset.messagesUrl,
|
||||
markReadUrl: appContainer.dataset.markReadUrl,
|
||||
editUrlTemplate: appContainer.dataset.editUrlTemplate,
|
||||
lastReadTimestamp: Number(appContainer.dataset.lastReadTimestamp) || null,
|
||||
lastReadMessageId: appContainer.dataset.lastReadMessageId
|
||||
? Number(appContainer.dataset.lastReadMessageId)
|
||||
: null,
|
||||
profileUrl: scrollContainer?.dataset.profileUrl || '/employees/profile/',
|
||||
detailUrlTemplate: scrollContainer?.dataset.detailUrlTemplate || '/employees/detail/0/'
|
||||
};
|
||||
|
||||
console.log('[ChatDetailV2] 🔍 Config:', {
|
||||
lastReadMessageId: config.lastReadMessageId,
|
||||
lastReadTimestamp: config.lastReadTimestamp,
|
||||
rawMessageId: appContainer.dataset.lastReadMessageId,
|
||||
rawTimestamp: appContainer.dataset.lastReadTimestamp
|
||||
});
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -132,7 +142,8 @@
|
||||
wsConnection: wsApi,
|
||||
profileUrl: config.profileUrl,
|
||||
detailUrlTemplate: config.detailUrlTemplate,
|
||||
lastReadMessageId: config.lastReadMessageId
|
||||
lastReadMessageId: config.lastReadMessageId,
|
||||
lastReadTimestamp: config.lastReadTimestamp // ✅ Fallback для скролла
|
||||
});
|
||||
|
||||
await chatController.init();
|
||||
@ -195,7 +206,9 @@
|
||||
* Главная функция инициализации
|
||||
*/
|
||||
async function init() {
|
||||
console.log('[ChatDetailV2] 🚀🚀🚀 INIT STARTED - V2 FILE LOADED 🚀🚀🚀');
|
||||
const config = readConfig();
|
||||
console.log('[ChatDetailV2] 🔍 Config read result:', config);
|
||||
if (!config || !config.chatId) {
|
||||
console.error('[ChatDetailV2] Invalid configuration');
|
||||
return;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user