From 8a997aab241651b3dbea708282e9f76d5bd05cdb Mon Sep 17 00:00:00 2001 From: marlon-erler Date: Wed, 1 Apr 2026 14:16:38 +0000 Subject: [PATCH] fix highlight of unread messages --- dist/index.js | 35 +++++++++++++---------------- src/Model/Chat/chatModel.ts | 9 ++++---- src/ViewModel/Chat/chatViewModel.ts | 26 ++++++++++++--------- 3 files changed, 36 insertions(+), 34 deletions(-) diff --git a/dist/index.js b/dist/index.js index ed2085ec..442a634c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1230,8 +1230,7 @@ if (chatMessage == null) return; chatMessage.status = "received" /* Received */; this.addMessage(chatMessage); - this.info.hasUnreadMessages = true; - this.storeInfo(); + this.setReadStatus(true); }; this.handleMessageSent = (chatMessage) => { chatMessage.status = "sent" /* Sent */; @@ -1301,8 +1300,8 @@ this.subscribe = () => { this.connectionModel.addChannel(this.info.primaryChannel); }; - this.markRead = () => { - this.info.hasUnreadMessages = false; + this.setReadStatus = (hasUnreadMessages) => { + this.info.hasUnreadMessages = hasUnreadMessages; this.storeInfo(); }; // storage @@ -3038,7 +3037,7 @@ // view this.open = () => { this.chatListViewModel.openChat(this); - this.markRead(); + this.setReadStatus(false); }; this.close = () => { this.chatListViewModel.closeChat(); @@ -3059,10 +3058,6 @@ const index = this.chatListViewModel.chatIndexManager.getIndex(this); this.index.value = index; }; - this.markRead = () => { - this.hasUnreadMessages.value = false; - this.chatModel.markRead(); - }; // load this.loadPageSelection = () => { const path = StorageModel.getPath( @@ -3079,12 +3074,22 @@ }); }; this.loadInfo = () => { - this.hasUnreadMessages.value = this.chatModel.info.hasUnreadMessages; + this.updateReadStatus(); this.taskBoardSuggestions.set(CALENDAR_EVENT_BOARD_ID, [ CALENDAR_EVENT_BOARD_ID, translations.chatPage.calendar.eventsBoard ]); }; + this.updateReadStatus = () => { + if (this.chatListViewModel.selectedChat.value == this) { + this.chatModel.setReadStatus(false); + } + this.hasUnreadMessages.value = this.chatModel.info.hasUnreadMessages; + }; + this.setReadStatus = (hasUnreadMessages) => { + this.chatModel.setReadStatus(hasUnreadMessages); + this.hasUnreadMessages.value = hasUnreadMessages; + }; this.storageModel = storageModel2; this.chatModel = chatModel; this.settingsViewModel = settingsViewModel2; @@ -3114,7 +3119,7 @@ chatModel.chatMessageHandlerManager.addHandler( (chatMessage) => { this.messagePageViewModel.showChatMessage(chatMessage); - this.markRead(); + this.updateReadStatus(); } ); this.loadPageSelection(); @@ -5534,14 +5539,6 @@ path: [""], body: "" }; - var counter = {}; - for (let i = 0; i < 1e3; i++) { - const token = generateRandomToken(10); - const length = token.length; - if (!counter[length]) counter[length] = 0; - counter[length]++; - } - console.log(counter); // src/View/Components/chatEntry.tsx function ChatEntry(chatViewModel) { diff --git a/src/Model/Chat/chatModel.ts b/src/Model/Chat/chatModel.ts index ec4abf46..ddcc0301 100644 --- a/src/Model/Chat/chatModel.ts +++ b/src/Model/Chat/chatModel.ts @@ -84,9 +84,8 @@ export default class ChatModel { chatMessage.status = ChatMessageStatus.Received; this.addMessage(chatMessage); - - this.info.hasUnreadMessages = true; - this.storeInfo(); + + this.setReadStatus(true); }; handleMessageSent = (chatMessage: ChatMessage): void => { @@ -177,8 +176,8 @@ export default class ChatModel { this.connectionModel.addChannel(this.info.primaryChannel); }; - markRead = (): void => { - this.info.hasUnreadMessages = false; + setReadStatus = (hasUnreadMessages: boolean): void => { + this.info.hasUnreadMessages = hasUnreadMessages; this.storeInfo(); }; diff --git a/src/ViewModel/Chat/chatViewModel.ts b/src/ViewModel/Chat/chatViewModel.ts index 4d143413..059d46ce 100644 --- a/src/ViewModel/Chat/chatViewModel.ts +++ b/src/ViewModel/Chat/chatViewModel.ts @@ -46,14 +46,14 @@ export default class ChatViewModel { // view open = (): void => { this.chatListViewModel.openChat(this); - this.markRead(); + this.setReadStatus(false); }; close = (): void => { this.chatListViewModel.closeChat(); }; - closeSubPages = (): void => {}; + closeSubPages = (): void => { }; setColor = (color: Color): void => { this.setDisplayedColor(color); @@ -74,11 +74,6 @@ export default class ChatViewModel { this.index.value = index; }; - markRead = (): void => { - this.hasUnreadMessages.value = false; - this.chatModel.markRead(); - }; - // load loadPageSelection = (): void => { const path: string[] = StorageModel.getPath( @@ -97,14 +92,25 @@ export default class ChatViewModel { }; loadInfo = (): void => { - this.hasUnreadMessages.value = this.chatModel.info.hasUnreadMessages; - + this.updateReadStatus(); this.taskBoardSuggestions.set(CALENDAR_EVENT_BOARD_ID, [ CALENDAR_EVENT_BOARD_ID, translations.chatPage.calendar.eventsBoard, ]); }; + updateReadStatus = (): void => { + if (this.chatListViewModel.selectedChat.value == this) { + this.chatModel.setReadStatus(false); + } + this.hasUnreadMessages.value = this.chatModel.info.hasUnreadMessages; + } + + setReadStatus = (hasUnreadMessages: boolean): void => { + this.chatModel.setReadStatus(hasUnreadMessages); + this.hasUnreadMessages.value = hasUnreadMessages; + } + // init constructor( public coreViewModel: CoreViewModel, @@ -148,7 +154,7 @@ export default class ChatViewModel { chatModel.chatMessageHandlerManager.addHandler( (chatMessage: ChatMessage) => { this.messagePageViewModel.showChatMessage(chatMessage); - this.markRead(); + this.updateReadStatus(); }, );