fix(@desktop/chat): messages sometimes assigned to the wrong user

Fixes #6004
This commit is contained in:
Sale Djenic 2022-06-09 20:38:08 +02:00 committed by osmaczko
parent 51aa4a6d86
commit c9fe428940
4 changed files with 61 additions and 18 deletions

View File

@ -184,7 +184,7 @@ method newMessagesLoaded*(self: Module, messages: seq[MessageDto], reactions: se
m.image,
m.containsContactMentions(),
m.seen,
m.timestamp,
m.whisperTimestamp,
m.contentType.ContentType,
m.messageType,
sticker = self.controller.decodeContentHash(m.sticker.hash),
@ -271,7 +271,7 @@ method messageAdded*(self: Module, message: MessageDto) =
message.image,
message.containsContactMentions(),
message.seen,
message.timestamp,
message.whisperTimestamp,
message.contentType.ContentType,
message.messageType,
sticker = self.controller.decodeContentHash(message.sticker.hash),

View File

@ -5,6 +5,8 @@ import message_item, message_reaction_item, message_transaction_parameters_item
type
ModelRole {.pure.} = enum
Id = UserRole + 1
PrevMsgIndex
NextMsgIndex
CommunityId
ResponseToMessageWithId
SenderId
@ -77,6 +79,8 @@ QtObject:
method roleNames(self: Model): Table[int, string] =
{
ModelRole.Id.int:"id",
ModelRole.PrevMsgIndex.int:"prevMsgIndex",
ModelRole.NextMsgIndex.int:"nextMsgIndex",
ModelRole.CommunityId.int:"communityId",
ModelRole.ResponseToMessageWithId.int:"responseToMessageWithId",
ModelRole.SenderId.int:"senderId",
@ -120,6 +124,10 @@ QtObject:
case enumRole:
of ModelRole.Id:
result = newQVariant(item.id)
of ModelRole.PrevMsgIndex:
result = newQVariant(index.row + 1)
of ModelRole.NextMsgIndex:
result = newQVariant(index.row - 1)
of ModelRole.CommunityId:
result = newQVariant(item.communityId)
of ModelRole.ResponseToMessageWithId:
@ -186,11 +194,18 @@ QtObject:
of ModelRole.MentionedUsersPks:
result = newQVariant(item.mentionedUsersPks.join(" "))
proc updateItemAtIndex(self: Model, index: int) =
let ind = self.createIndex(index, 0, nil)
self.dataChanged(ind, ind, self.allKeys)
proc findIndexForMessageId*(self: Model, messageId: string): int =
result = -1
if messageId.len == 0:
return
for i in 0 ..< self.items.len:
if(self.items[i].id == messageId):
return i
return -1
result = i
return
proc findIdsOfTheMessagesWhichRespondedToMessageWithId*(self: Model, messageId: string): seq[string] =
for i in 0 ..< self.items.len:
@ -274,6 +289,9 @@ QtObject:
self.beginInsertRows(parentModelIndex, position, position)
self.items.insert(item, position)
self.endInsertRows()
if position > 0:
self.updateItemAtIndex(position - 1)
self.countChanged()
proc removeItem*(self: Model, messageId: string) =
@ -287,6 +305,9 @@ QtObject:
self.beginRemoveRows(parentModelIndex, ind, ind)
self.items.delete(ind)
self.endRemoveRows()
if self.items.len > 0 and ind > 0 and ind < self.items.len:
self.updateItemAtIndex(ind - 1)
self.countChanged()
proc getItemWithMessageId*(self: Model, messageId: string): Item =
@ -411,6 +432,4 @@ QtObject:
let ind = self.findIndexForMessageId(messageId)
if(ind == -1):
return
let index = self.createIndex(ind, 0, nil)
self.dataChanged(index, index, self.allKeys)
self.updateItemAtIndex(ind)

View File

@ -321,10 +321,10 @@ Item {
// Also one important thing here is that messages are set in descending order
// in terms of `timestamp` of a message, that means a message with the most
// recent time is added at index 0.
prevMessageIndex: index + 1
prevMessageAsJsonObj: messageStore.getMessageByIndexAsJson(index + 1)
nextMessageIndex: index - 1
nextMessageAsJsonObj: messageStore.getMessageByIndexAsJson(index - 1)
prevMessageIndex: model.prevMsgIndex
prevMessageAsJsonObj: messageStore.getMessageByIndexAsJson(model.prevMsgIndex)
nextMessageIndex: model.nextMsgIndex
nextMessageAsJsonObj: messageStore.getMessageByIndexAsJson(model.nextMsgIndex)
onOpenStickerPackPopup: {
root.openStickerPackPopup(stickerPackId);
}

View File

@ -349,11 +349,11 @@ Item {
}
}
UserImage {
StatusSmartIdenticon {
id: chatImage
active: isMessage && headerRepeatCondition
property int imageHeight: 36
property int imageWidth: 36
anchors.left: parent.left
anchors.leftMargin: Style.current.padding
@ -361,11 +361,35 @@ Item {
pinnedRectangleLoader.active ? pinnedRectangleLoader.bottom : parent.top
anchors.topMargin: chatReply.active || pinnedRectangleLoader.active ? 4 : Style.current.smallPadding
image: root.senderIcon
pubkey: senderId
name: senderDisplayName
active: isMessage && headerRepeatCondition
onClicked: root.clickMessage(true, false, false, null, false, false, false, false, "")
width: active? imageWidth : 0
height: active? imageHeight : 0
name: senderDisplayName
image {
width: chatImage.imageWidth
height: chatImage.imageHeight
source: root.senderIcon
}
icon {
width: chatImage.imageWidth
height: chatImage.imageHeight
color: Utils.colorForPubkey(senderId)
charactersLen: 2
}
ringSettings {
ringSpecModel: Utils.getColorHashAsJson(senderId)
}
MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
hoverEnabled: true
onClicked: {
root.clickMessage(true, false, false, null, false, false, false, false, "")
}
}
}
UsernameLabel {