fix(replies): Get original message from status-go for replies

Fixes: #7248
This commit is contained in:
Boris Melnik 2022-11-21 15:27:17 +03:00 committed by r4bbit.eth
parent 3d4cb12d0c
commit bff6b22fc4
7 changed files with 112 additions and 14 deletions

View File

@ -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")

View File

@ -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)):

View File

@ -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()

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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) {