From b6eeba365c3098676088febfbc058b7df39f94aa Mon Sep 17 00:00:00 2001 From: marlon-erler Date: Sat, 26 Sep 2026 13:31:36 +0200 Subject: [PATCH] apply filter when sending message --- src/Model/Chat/chatModel.ts | 4 +- src/ViewModel/Pages/calendarPageViewModel.ts | 1 - src/ViewModel/Pages/messagePageViewModel.ts | 211 ++++++++++--------- 3 files changed, 111 insertions(+), 105 deletions(-) diff --git a/src/Model/Chat/chatModel.ts b/src/Model/Chat/chatModel.ts index 8406e170..4850b360 100644 --- a/src/Model/Chat/chatModel.ts +++ b/src/Model/Chat/chatModel.ts @@ -198,7 +198,7 @@ export default class ChatModel { body: string, inlineReplyId?: string, fileContent?: FileContent, - ): Promise => { + ): Promise => { const nameAndChannel = this.getNameAndChannel(); if (nameAndChannel == false) return false; const [senderName, combinedChannel] = nameAndChannel; @@ -214,7 +214,7 @@ export default class ChatModel { this.addMessage(chatMessage); this.connectionModel.sendMessageOrStore(chatMessage); - return true; + return chatMessage.id; }; readonly decryptMessage = async ( diff --git a/src/ViewModel/Pages/calendarPageViewModel.ts b/src/ViewModel/Pages/calendarPageViewModel.ts index 9a967e00..ab224262 100644 --- a/src/ViewModel/Pages/calendarPageViewModel.ts +++ b/src/ViewModel/Pages/calendarPageViewModel.ts @@ -171,7 +171,6 @@ export default class CalendarPageViewModel extends TaskContainingPageViewModel { updateMonthGrid = (): void => { const today = formatISO(this.coreViewModel.todayDate.value) - console.log(today, this.coreViewModel.todayDate.value); if ( this.currentTodayDate == today ) diff --git a/src/ViewModel/Pages/messagePageViewModel.ts b/src/ViewModel/Pages/messagePageViewModel.ts index 1850a42e..a6e544a9 100644 --- a/src/ViewModel/Pages/messagePageViewModel.ts +++ b/src/ViewModel/Pages/messagePageViewModel.ts @@ -35,111 +35,118 @@ export default class MessagePageViewModel extends Context { cannotSendMessage: React.State; // methods - sendMessage = (): void => { + sendMessage = async (): Promise => { if (this.cannotSendMessage.value == true) return; - this.sendMessageFromBody(this.composingMessage.value); - this.composingMessage.value = ""; + const idPromise = this.sendMessageFromBody(this.composingMessage.value); + this.composingMessage.value = ""; + + const id = await idPromise; + if (id && this.reactionFilter.value != undefined) { + this.sendReaction(id, this.reactionFilter.value, false); + } }; - sendMessageFromBody = (body: string): void => { - let replyId: string | undefined = undefined; - if (this.replyingMessage.value) { - replyId = this.replyingMessage.value.chatMessage.id; - } - this.chatViewModel.chatModel.sendMessage(body, replyId); + sendMessageFromBody = (body: string): Promise=> { + let replyId: string | undefined = undefined; + if (this.replyingMessage.value) { + replyId = this.replyingMessage.value.chatMessage.id; + } + const id = this.chatViewModel.chatModel.sendMessage(body, replyId); - if (this.replyViewSelectedMessage.value != undefined) return; - this.replyingMessage.value = undefined; + if (this.replyViewSelectedMessage.value == undefined) + this.replyingMessage.value = undefined; + + return id; }; decryptMessage = async ( - messageViewModel: ChatMessageViewModel, + messageViewModel: ChatMessageViewModel, ): Promise => { - const chatMessage: ChatMessage = messageViewModel.chatMessage; - await this.chatViewModel.chatModel.decryptMessage(chatMessage); - this.chatViewModel.chatModel.addMessage(chatMessage); - messageViewModel.loadData(); + const chatMessage: ChatMessage = messageViewModel.chatMessage; + await this.chatViewModel.chatModel.decryptMessage(chatMessage); + this.chatViewModel.chatModel.addMessage(chatMessage); + messageViewModel.loadData(); }; sendReaction = ( - messageId: string, - content: ReactionSymbols, - isDeleting: boolean, + messageId: string, + content: ReactionSymbols, + isDeleting: boolean, ): void => { - this.chatViewModel.chatModel.sendReaction( - messageId, - content, - isDeleting, - ); + this.chatViewModel.chatModel.sendReaction( + messageId, + content, + isDeleting, + ); }; setReply = ( - chatMessageViewModel: ChatMessageViewModel | undefined, + chatMessageViewModel: ChatMessageViewModel | undefined, setFocus: boolean = true, ): void => { - this.replyingMessage.value = chatMessageViewModel; + this.replyingMessage.value = chatMessageViewModel; if (setFocus == false || chatMessageViewModel == undefined) return; - this.setFocus(); + this.setFocus(); }; resetReply = (setFocus: boolean = true): void => { - this.replyingMessage.value = undefined; + this.replyingMessage.value = undefined; if (setFocus == false) return; - this.setFocus(); + this.setFocus(); }; // view showChatMessage = (chatMessage: ChatMessage): void => { - const chatMessageViewModel = new ChatMessageViewModel( - this.coreViewModel, - this, - chatMessage, - chatMessage.sender == - this.chatViewModel.settingsViewModel.username.value, - ); + const chatMessageViewModel = new ChatMessageViewModel( + this.coreViewModel, + this, + chatMessage, + chatMessage.sender == + this.chatViewModel.settingsViewModel.username.value, + ); - const existingChatMessageViewModel: ChatMessageViewModel | undefined = - this.chatMessageViewModels.value.get(chatMessage.id); - if (existingChatMessageViewModel != undefined) { - existingChatMessageViewModel.body.value = chatMessage.body; - existingChatMessageViewModel.status.value = chatMessage.status; - } else { - this.chatMessageViewModels.set( - chatMessage.id, - chatMessageViewModel, - ); - } + const existingChatMessageViewModel: ChatMessageViewModel | undefined = + this.chatMessageViewModels.value.get(chatMessage.id); + if (existingChatMessageViewModel != undefined) { + existingChatMessageViewModel.body.value = chatMessage.body; + existingChatMessageViewModel.status.value = chatMessage.status; + } else { + this.chatMessageViewModels.set( + chatMessage.id, + chatMessageViewModel, + ); + } }; handleReaction = (reaction: ChatMessageReaction): void => { - const messageViewModel: ChatMessageViewModel | undefined = - this.chatMessageViewModels.value.get(reaction.messageId); - if (messageViewModel == undefined) return; - messageViewModel.handleReaction(reaction); + const messageViewModel: ChatMessageViewModel | undefined = + this.chatMessageViewModels.value.get(reaction.messageId); + if (messageViewModel == undefined) return; + messageViewModel.handleReaction(reaction); }; showFilterModal = (): void => { - this.isFilterModalOpen.value = true; + this.isFilterModalOpen.value = true; }; hideFilterModal = (): void => { - this.isFilterModalOpen.value = false; + this.isFilterModalOpen.value = false; }; revokeReactionFilter = (persist: boolean = true): void => { - this.reactionFilter.value = undefined; + this.reactionFilter.value = undefined; if (persist) this.chatViewModel.chatModel.storeFilter(""); }; setReactionFilter = (content: ReactionSymbols): void => { - this.reactionFilter.value = content; + this.reactionFilter.value = content; this.chatViewModel.chatModel.storeFilter(content); }; resetFilter = (): void => { - this.revokeReactionFilter(); - this.searchViewModel.search(""); + this.revokeReactionFilter(); + this.searchViewModel.search(""); }; setReplyView = (message: ChatMessageViewModel): void => { @@ -155,18 +162,18 @@ export default class MessagePageViewModel extends Context { } setFocus = (): void => { - this.focusSetter.callSubscriptions(); + this.focusSetter.callSubscriptions(); }; // load loadData = (): void => { - this.chatMessageViewModels.clear(); - for (const chatMessage of this.chatViewModel.chatModel.messages) { - this.showChatMessage(chatMessage); - } - for (const reaction of this.chatViewModel.chatModel.reactions) { - this.handleReaction(reaction); - } + this.chatMessageViewModels.clear(); + for (const chatMessage of this.chatViewModel.chatModel.messages) { + this.showChatMessage(chatMessage); + } + for (const reaction of this.chatViewModel.chatModel.reactions) { + this.handleReaction(reaction); + } }; restoreFilter = (): void => { @@ -176,49 +183,49 @@ export default class MessagePageViewModel extends Context { // init constructor( - public readonly coreViewModel: CoreViewModel, - public readonly chatViewModel: ChatViewModel, + public readonly coreViewModel: CoreViewModel, + public readonly chatViewModel: ChatViewModel, ) { - super("message-page"); + super("message-page"); this.restoreFilter(); - // states - this.cannotSendMessage = React.createProxyState( - [ - this.chatViewModel.settingsViewModel.username, - this.composingMessage, - ], - () => - this.chatViewModel.settingsViewModel.username.value == "" || - this.composingMessage.value == "", - ); + // states + this.cannotSendMessage = React.createProxyState( + [ + this.chatViewModel.settingsViewModel.username, + this.composingMessage, + ], + () => + this.chatViewModel.settingsViewModel.username.value == "" || + this.composingMessage.value == "", + ); - this.searchViewModel = new SearchViewModel( - this.chatMessageViewModels, - this.filteredMessageViewModels, - (chatMessageViewModel) => [chatMessageViewModel.body.value], - new React.ListState(), - ); + this.searchViewModel = new SearchViewModel( + this.chatMessageViewModels, + this.filteredMessageViewModels, + (chatMessageViewModel) => [chatMessageViewModel.body.value], + new React.ListState(), + ); - this.isFilterActive = React.createProxyState( - [this.searchViewModel.appliedQuery, this.reactionFilter], - () => - this.searchViewModel.appliedQuery.value != "" || - this.reactionFilter.value != undefined, - ); + this.isFilterActive = React.createProxyState( + [this.searchViewModel.appliedQuery, this.reactionFilter], + () => + this.searchViewModel.appliedQuery.value != "" || + this.reactionFilter.value != undefined, + ); - // keystrokes - this.registerKeyStroke(CommonKeys.Filter, this.showFilterModal); - this.registerKeyStroke(CommonKeys.CloseOrCancel, () => { - if (this.isFilterModalOpen.value == true) { - this.hideFilterModal(); - } else { - this.replyingMessage.value = undefined; - } - }); - this.registerKeyStroke(CommonKeys.Reset, this.resetFilter); - this.registerKeyStroke(CommonKeys.Create, this.setFocus); + // keystrokes + this.registerKeyStroke(CommonKeys.Filter, this.showFilterModal); + this.registerKeyStroke(CommonKeys.CloseOrCancel, () => { + if (this.isFilterModalOpen.value == true) { + this.hideFilterModal(); + } else { + this.replyingMessage.value = undefined; + } + }); + this.registerKeyStroke(CommonKeys.Reset, this.resetFilter); + this.registerKeyStroke(CommonKeys.Create, this.setFocus); - this.chatViewModel.registerContext(ChatPageTypes.Messages, this); + this.chatViewModel.registerContext(ChatPageTypes.Messages, this); } }