fix(Reply): Add check if responsed message was deleted and add `<deleted>` to reply message

Closes: #7372
This commit is contained in:
Boris Melnik 2022-10-06 16:48:04 +03:00
parent cd5eb42c0b
commit 6a11a89ff3
3 changed files with 24 additions and 2 deletions

View File

@ -12,6 +12,7 @@ type
NextMsgIndex
CommunityId
ResponseToMessageWithId
ResponseToExistingMessage
SenderId
SenderDisplayName
SenderOptionalName
@ -82,6 +83,12 @@ 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",
@ -90,6 +97,7 @@ 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",
@ -148,6 +156,8 @@ 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:
@ -332,6 +342,12 @@ QtObject:
self.updateItemAtIndex(position + 1)
self.countChanged()
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])
proc removeItem*(self: Model, messageId: string) =
let ind = self.findIndexForMessageId(messageId)
if(ind == -1):
@ -350,6 +366,7 @@ QtObject:
self.updateItemAtIndex(ind + 1)
self.countChanged()
self.updateMessagesWithResponseTo(messageId)
proc getItemWithMessageId*(self: Model, messageId: string): Item =
let ind = self.findIndexForMessageId(messageId)

View File

@ -263,6 +263,7 @@ Item {
messageId: model.id
communityId: model.communityId
responseToMessageWithId: model.responseToMessageWithId
responseToExistingMessage: model.responseToExistingMessage
senderId: model.senderId
senderDisplayName: model.senderDisplayName
senderOptionalName: model.senderOptionalName

View File

@ -37,6 +37,8 @@ Loader {
property string messageId: ""
property string communityId: ""
property string responseToMessageWithId: ""
property bool responseToExistingMessage: false
property string senderId: ""
property string senderDisplayName: ""
property string senderOptionalName: ""
@ -394,7 +396,7 @@ Loader {
readonly property int contentType: convertContentType(root.messageContentType)
readonly property bool isReply: root.responseTo !== ""
readonly property var replyMessage: root.messageStore && isReply ? root.messageStore.getMessageByIdAsJson(root.responseTo) : null
readonly property var replyMessage: root.messageStore && isReply && root.responseToExistingMessage ? root.messageStore.getMessageByIdAsJson(root.responseTo) : null
readonly property string replySenderId: replyMessage ? replyMessage.senderId : ""
function editCompletedHandler(newMessageText) {
@ -590,7 +592,9 @@ Loader {
}
replyDetails: StatusMessageDetails {
messageText: delegate.replyMessage ? delegate.replyMessage.messageText : ""
messageText: delegate.replyMessage ? delegate.replyMessage.messageText
//: There is should be a message for reply which source message was deleted
: qsTr("&lt;deleted&gt;")
contentType: delegate.replyMessage ? delegate.convertContentType(delegate.replyMessage.contentType) : 0
messageContent: {
if (!delegate.replyMessage)