Skip to content

Commit

Permalink
fix(pins): fix edits not showing in the pinned messages until restart
Browse files Browse the repository at this point in the history
Fixes #16639
  • Loading branch information
jrainville committed Dec 13, 2024
1 parent d4e2d4d commit 0402861
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/app/modules/main/chat_section/chat_content/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ proc init*(self: Controller) =
return
self.delegate.onGroupChatDetailsUpdated(args.newName, args.newColor, args.newImage)

self.events.on(SIGNAL_MESSAGE_EDITED) do(e: Args):
let args = MessageEditedArgs(e)
if(self.chatId != args.chatId):
return
self.delegate.onMessageEdited(args.message)

proc getMyChatId*(self: Controller): string =
return self.chatId

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import NimQml
import ../item as chat_item
import ../../../../../app_service/service/message/dto/pinned_message
import ../../../../../app_service/service/chat/dto/chat

import ../../../../../app_service/service/message/dto/message
type
AccessInterface* {.pure inheritable.} = ref object of RootObj

Expand Down Expand Up @@ -31,7 +31,10 @@ method newPinnedMessagesLoaded*(self: AccessInterface, pinnedMessages: seq[Pinne
method onUnpinMessage*(self: AccessInterface, messageId: string) {.base.} =
raise newException(ValueError, "No implementation available")

method onPinMessage*(self: AccessInterface, mmessageId: string, actionInitiatedBy: string) {.base.} =
method onPinMessage*(self: AccessInterface, messageId: string, actionInitiatedBy: string) {.base.} =
raise newException(ValueError, "No implementation available")

method onMessageEdited*(self: AccessInterface, message: MessageDto) {.base.} =
raise newException(ValueError, "No implementation available")

method onChatMuted*(self: AccessInterface) {.base.} =
Expand Down
21 changes: 21 additions & 0 deletions src/app/modules/main/chat_section/chat_content/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,27 @@ method onPinMessage*(self: Module, messageId: string, actionInitiatedBy: string)

self.view.pinnedModel().insertItemBasedOnClock(item)

method onMessageEdited*(self: Module, message: MessageDto) =
let index = self.view.pinnedModel().findIndexForMessageId(message.id)
if index == -1:
return

let itemBeforeChange = self.view.pinnedModel().getItemWithMessageId(message.id)
let mentionedUsersPks = itemBeforeChange.mentionedUsersPks
let communityChats = self.controller.getCommunityDetails().chats

self.view.pinnedModel().updateEditedMsg(
message.id,
self.controller.getRenderedText(message.parsedText, communityChats),
message.text,
message.parsedText,
message.contentType,
message.mentioned,
message.containsContactMentions(),
message.links,
message.mentionedUsersPks
)

method getMyChatId*(self: Module): string =
self.controller.getMyChatId()

Expand Down
2 changes: 1 addition & 1 deletion src/app_service/service/message/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ QtObject:

self.events.emit(SIGNAL_PINNED_MESSAGES_LOADED, data)
except Exception as e:
error "Erorr load pinned messages for chat async", msg = e.msg
error "Error load pinned messages for chat async", msg = e.msg
# notify view, this is important
self.events.emit(SIGNAL_PINNED_MESSAGES_LOADED, PinnedMessagesLoadedArgs())

Expand Down

0 comments on commit 0402861

Please sign in to comment.