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.image,
m.containsContactMentions(), m.containsContactMentions(),
m.seen, m.seen,
m.timestamp, m.whisperTimestamp,
m.contentType.ContentType, m.contentType.ContentType,
m.messageType, m.messageType,
sticker = self.controller.decodeContentHash(m.sticker.hash), sticker = self.controller.decodeContentHash(m.sticker.hash),
@ -271,7 +271,7 @@ method messageAdded*(self: Module, message: MessageDto) =
message.image, message.image,
message.containsContactMentions(), message.containsContactMentions(),
message.seen, message.seen,
message.timestamp, message.whisperTimestamp,
message.contentType.ContentType, message.contentType.ContentType,
message.messageType, message.messageType,
sticker = self.controller.decodeContentHash(message.sticker.hash), sticker = self.controller.decodeContentHash(message.sticker.hash),

View File

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

View File

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

View File

@ -349,11 +349,11 @@ Item {
} }
} }
StatusSmartIdenticon {
UserImage {
id: chatImage id: chatImage
active: isMessage && headerRepeatCondition property int imageHeight: 36
property int imageWidth: 36
anchors.left: parent.left anchors.left: parent.left
anchors.leftMargin: Style.current.padding anchors.leftMargin: Style.current.padding
@ -361,11 +361,35 @@ Item {
pinnedRectangleLoader.active ? pinnedRectangleLoader.bottom : parent.top pinnedRectangleLoader.active ? pinnedRectangleLoader.bottom : parent.top
anchors.topMargin: chatReply.active || pinnedRectangleLoader.active ? 4 : Style.current.smallPadding anchors.topMargin: chatReply.active || pinnedRectangleLoader.active ? 4 : Style.current.smallPadding
image: root.senderIcon active: isMessage && headerRepeatCondition
pubkey: senderId
name: senderDisplayName
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 { UsernameLabel {