fix: используем lastReadTimestamp как fallback для скролла к последнему прочитанному

- Проблема: lastReadMessageId часто равен 0/null
- Решение: используем lastReadTimestamp (API поддерживает оба формата)
- Добавлен this.lastReadTimestamp в ChatControllerV2
- Передаем оба параметра из chatDetail.js
- anchorValue = lastReadMessageId || lastReadTimestamp
- Исправлена поврежденная структура в chatControllerV2.js
This commit is contained in:
Игорь Надеин 2026-01-13 09:46:27 +03:00
parent 903c894349
commit ce2d1d4527
2 changed files with 6 additions and 2 deletions

View File

@ -45,6 +45,7 @@ export class ChatControllerV2 {
this.scrollElement = options.scrollElement;
this.containerId = options.containerId || 'chatScroll';
this.lastReadMessageId = options.lastReadMessageId || null;
this.lastReadTimestamp = options.lastReadTimestamp || null;
// Создаем компоненты
this.store = new MessageStoreV2({ currentUserId: this.currentUserId });
@ -114,8 +115,10 @@ export class ChatControllerV2 {
try {
// 1. Загружаем сообщения
// Используем timestamp как fallback если нет message ID (API поддерживает оба)
const anchorValue = this.lastReadMessageId || this.lastReadTimestamp;
const loadResult = await this.loader.loadInitial(this.chatId, {
aroundMessageId: this.lastReadMessageId
aroundMessageId: anchorValue
});
// 2. Скрываем контейнер для плавного рендера

View File

@ -183,7 +183,8 @@ async function initializeComponents(config, userWs) {
profileUrl: config.profileUrl || '/employees/profile/',
detailUrlTemplate: config.detailUrlTemplate || '/employees/detail/0/',
messagesUrl: config.messagesUrl,
lastReadTimestamp: config.lastReadMessageId || config.lastReadTimestamp // Используем message_id, fallback на timestamp
lastReadMessageId: config.lastReadMessageId, // ✅ Передаем message_id
lastReadTimestamp: config.lastReadTimestamp // ✅ Fallback на timestamp
});
console.log('[ChatDetail] Initializing ChatController...');