diff --git a/src/app/modules/main/chat_section/chat_content/messages/io_interface.nim b/src/app/modules/main/chat_section/chat_content/messages/io_interface.nim index 2430d966ff..ccb9d741d0 100644 --- a/src/app/modules/main/chat_section/chat_content/messages/io_interface.nim +++ b/src/app/modules/main/chat_section/chat_content/messages/io_interface.nim @@ -143,5 +143,8 @@ method didIJoinedChat*(self: AccessInterface): bool {.base.} = method getMessages*(self: AccessInterface): seq[message_item.Item] = raise newException(ValueError, "No implementation available") +method getMessageById*(self: AccessInterface, messageId: string): message_item.Item {.base.} = + raise newException(ValueError, "No implementation available") + method onMailserverSynced*(self: AccessInterface, syncedFrom: int64) = raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/chat_section/chat_content/messages/module.nim b/src/app/modules/main/chat_section/chat_content/messages/module.nim index f378117cae..c31984c0e1 100644 --- a/src/app/modules/main/chat_section/chat_content/messages/module.nim +++ b/src/app/modules/main/chat_section/chat_content/messages/module.nim @@ -536,6 +536,58 @@ method onChatMemberUpdated*(self: Module, publicKey: string, admin: bool, joined method getMessages*(self: Module): seq[message_item.Item] = return self.view.model().items +method getMessageById*(self: Module, messageId: string): message_item.Item = + let (m, _, err) = self.controller.getMessageDetails(messageId) + if(err.len == 0): + let sender = self.controller.getContactDetails(m.`from`) + + let renderedMessageText = self.controller.getRenderedText(m.parsedText) + var transactionContract = m.transactionParameters.contract + var transactionValue = m.transactionParameters.value + var isCurrentUser = sender.isCurrentUser + if(m.contentType.ContentType == ContentType.Transaction): + (transactionContract, transactionValue) = self.controller.getTransactionDetails(m) + if m.transactionParameters.fromAddress != "": + isCurrentUser = self.currentUserWalletContainsAddress(m.transactionParameters.fromAddress) + var item = initItem( + m.id, + m.communityId, + m.responseTo, + m.`from`, + sender.defaultDisplayName, + sender.optionalName, + sender.icon, + (isCurrentUser and m.contentType.ContentType != ContentType.DiscordMessage), + sender.details.added, + m.outgoingStatus, + renderedMessageText, + m.image, + m.containsContactMentions(), + m.seen, + timestamp = m.whisperTimestamp, + clock = m.clock, + m.contentType.ContentType, + m.messageType, + m.contactRequestState, + sticker = m.sticker.url, + m.sticker.pack, + m.links, + newTransactionParametersItem(m.transactionParameters.id, + m.transactionParameters.fromAddress, + m.transactionParameters.address, + transactionContract, + transactionValue, + m.transactionParameters.transactionHash, + m.transactionParameters.commandState, + m.transactionParameters.signature), + m.mentionedUsersPks(), + sender.details.trustStatus, + sender.details.ensVerified, + m.discordMessage + ) + return item + return nil + method onMailserverSynced*(self: Module, syncedFrom: int64) = let chatDto = self.controller.getChatDetails() if (not chatDto.hasMoreMessagesToRequest(syncedFrom)): diff --git a/src/app/modules/main/chat_section/chat_content/messages/view.nim b/src/app/modules/main/chat_section/chat_content/messages/view.nim index 7ade9daf39..8b517e3a22 100644 --- a/src/app/modules/main/chat_section/chat_content/messages/view.nim +++ b/src/app/modules/main/chat_section/chat_content/messages/view.nim @@ -1,5 +1,6 @@ import NimQml, json import ../../../../shared_models/message_model +import ../../../../shared_models/message_item import io_interface QtObject: @@ -56,6 +57,19 @@ QtObject: return "" return $jsonObj + proc getReplyMessageByIdAsJson*(self: View, messageId: string): string {.slot.} = + var jsonObj = self.model.getMessageByIdAsJson(messageId) + if(jsonObj.isNil): + # trying to get message from status-go + let messageItem = self.delegate.getMessageById(messageId) + if messageItem == nil: + return "" + + jsonObj = messageItem.toJsonNode(); + if(jsonObj.isNil): + return "" + return $jsonObj + proc getSectionId*(self: View): string {.slot.} = return self.delegate.getSectionId() diff --git a/src/app/modules/shared_models/message_model.nim b/src/app/modules/shared_models/message_model.nim index 2d8f767fa1..d57030935e 100644 --- a/src/app/modules/shared_models/message_model.nim +++ b/src/app/modules/shared_models/message_model.nim @@ -12,7 +12,6 @@ type NextMsgIndex CommunityId ResponseToMessageWithId - ResponseToExistingMessage SenderId SenderDisplayName SenderOptionalName @@ -83,12 +82,6 @@ QtObject: method rowCount(self: Model, index: QModelIndex = nil): int = return self.items.len - proc doesMessageExist(self: Model, messageId: string): bool = - for i in 0 ..< self.items.len: - if(self.items[i].id == messageId): - return true - return false - method roleNames(self: Model): Table[int, string] = { ModelRole.Id.int:"id", @@ -97,7 +90,6 @@ QtObject: ModelRole.NextMsgIndex.int:"nextMsgIndex", ModelRole.CommunityId.int:"communityId", ModelRole.ResponseToMessageWithId.int:"responseToMessageWithId", - ModelRole.ResponseToExistingMessage.int:"responseToExistingMessage", ModelRole.SenderId.int:"senderId", ModelRole.SenderDisplayName.int:"senderDisplayName", ModelRole.SenderOptionalName.int:"senderOptionalName", @@ -156,8 +148,6 @@ QtObject: result = newQVariant(item.communityId) of ModelRole.ResponseToMessageWithId: result = newQVariant(item.responseToMessageWithId) - of ModelRole.ResponseToExistingMessage: - result = newQVariant(self.doesMessageExist(item.responseToMessageWithId)) of ModelRole.SenderId: result = newQVariant(item.senderId) of ModelRole.SenderDisplayName: @@ -341,12 +331,14 @@ QtObject: if position + 1 < self.items.len: self.updateItemAtIndex(position + 1) self.countChanged() + + proc replyDeleted*(self: Model, messageIndex: int) {.signal.} proc updateMessagesWithResponseTo(self: Model, messageId: string) = for i in 0 ..< self.items.len: if(self.items[i].responseToMessageWithId == messageId): let ind = self.createIndex(i, 0, nil) - self.dataChanged(ind, ind, @[ModelRole.ResponseToExistingMessage.int]) + self.replyDeleted(i) proc removeItem*(self: Model, messageId: string) = let ind = self.findIndexForMessageId(messageId) diff --git a/ui/app/AppLayouts/Chat/stores/MessageStore.qml b/ui/app/AppLayouts/Chat/stores/MessageStore.qml index 4a01dba338..42bf7910d0 100644 --- a/ui/app/AppLayouts/Chat/stores/MessageStore.qml +++ b/ui/app/AppLayouts/Chat/stores/MessageStore.qml @@ -49,6 +49,28 @@ QtObject { return obj } + function getReplyMessageByIdAsJson(messageId: string) { + if (!messageModule) { + console.warn("getReplyMessageByIdAsJson: Failed to parse message, because messageModule is not set") + return false + } + + const jsonObj = messageModule.getReplyMessageByIdAsJson(messageId) + if (jsonObj === "") { + console.warn("getReplyMessageByIdAsJson: Failed to get message, returned json is empty") + return undefined + } + + const obj = JSON.parse(jsonObj) + if (obj.error) { + // This log is available only in debug mode, if it's annoying we can remove it + console.debug("getReplyMessageByIdAsJson: Failed to parse message for index: ", messageId, " error: ", obj.error) + return false + } + + return obj + } + function getMessageByIndexAsJson (index) { if(!messageModule) return false diff --git a/ui/app/AppLayouts/Chat/views/ChatMessagesView.qml b/ui/app/AppLayouts/Chat/views/ChatMessagesView.qml index 9e196def77..3167257dfd 100644 --- a/ui/app/AppLayouts/Chat/views/ChatMessagesView.qml +++ b/ui/app/AppLayouts/Chat/views/ChatMessagesView.qml @@ -251,6 +251,13 @@ Item { } } } + + onReplyDeleted: { + let item = chatLogView.itemAtIndex(messageIndex) + if (item) { + item.replyDeleted() + } + } } delegate: MessageView { @@ -277,7 +284,6 @@ Item { messageId: model.id communityId: model.communityId responseToMessageWithId: model.responseToMessageWithId - responseToExistingMessage: model.responseToExistingMessage senderId: model.senderId senderDisplayName: model.senderDisplayName senderOptionalName: model.senderOptionalName diff --git a/ui/imports/shared/views/chat/MessageView.qml b/ui/imports/shared/views/chat/MessageView.qml index 2e0212dd9e..e4ff293759 100644 --- a/ui/imports/shared/views/chat/MessageView.qml +++ b/ui/imports/shared/views/chat/MessageView.qml @@ -39,7 +39,6 @@ Loader { property string messageId: "" property string communityId: "" property string responseToMessageWithId: "" - property bool responseToExistingMessage: false property string senderId: "" property string senderDisplayName: "" @@ -231,6 +230,10 @@ Loader { } } + function replyDeleted() { + item.replyDeleted() + } + QtObject { id: d @@ -373,6 +376,10 @@ Loader { delegate.replyMessage = delegate.getReplyMessage() } + function replyDeleted() { + delegate.replyMessage = null + } + StatusDateGroupLabel { id: dateGroupLabel Layout.fillWidth: true @@ -422,7 +429,9 @@ Loader { readonly property string replySenderId: replyMessage ? replyMessage.senderId : "" function getReplyMessage() { - return root.messageStore && isReply && root.responseToExistingMessage ? root.messageStore.getMessageByIdAsJson(root.responseToMessageWithId) : null + return root.messageStore && isReply + ? root.messageStore.getReplyMessageByIdAsJson(root.responseToMessageWithId) + : null } function editCompletedHandler(newMessageText) {