mirror of
https://github.com/status-im/status-desktop.git
synced 2025-01-09 22:06:25 +00:00
fix(pins): fix old messages not showing as pinned (#16897)
Fixes #16896 The problem was that we relied on the `SIGNAL_PINNED_MESSAGES_LOADED` event to apply the pinned status to messages, but that only happens at the start and a lot of messages are not loaded at start if they are not in the first 30 messages. To fix this, I just added `pinnedBy` to the Message object in status-go. This way, we can easily tell straight from the MessageDto if a message is pinned and by whom.
This commit is contained in:
parent
04e2abd3f5
commit
723dc712e3
@ -107,7 +107,7 @@ proc createMessageItemFromDto(self: Module, message: MessageDto, communityId: st
|
||||
imagesAlbum.add(msg.image)
|
||||
albumMessageIds.add(msg.id)
|
||||
|
||||
return msg_item_qobj.newMessageItem(msg_item.initItem(
|
||||
return msg_item_qobj.newMessageItem(msg_item.initMessageItem(
|
||||
message.id,
|
||||
communityId, # we don't received community id via `activityCenterNotifications` api call
|
||||
message.chatId,
|
||||
@ -144,6 +144,7 @@ proc createMessageItemFromDto(self: Module, message: MessageDto, communityId: st
|
||||
message.deleted,
|
||||
message.deletedBy,
|
||||
deletedByContactDetails = ContactDetails(),
|
||||
message.pinnedBy,
|
||||
message.mentioned,
|
||||
message.quotedMessage.`from`,
|
||||
message.quotedMessage.text,
|
||||
|
@ -60,12 +60,6 @@ proc init*(self: Controller) =
|
||||
return
|
||||
self.delegate.newMessagesLoaded(args.messages, args.reactions)
|
||||
|
||||
self.events.on(SIGNAL_PINNED_MESSAGES_LOADED) do(e:Args):
|
||||
let args = PinnedMessagesLoadedArgs(e)
|
||||
if(self.chatId != args.chatId):
|
||||
return
|
||||
self.delegate.newPinnedMessagesLoaded(args.pinnedMessages)
|
||||
|
||||
self.events.on(SIGNAL_NEW_MESSAGE_RECEIVED) do(e: Args):
|
||||
var args = MessagesArgs(e)
|
||||
if(self.chatId != args.chatId):
|
||||
|
@ -29,9 +29,6 @@ method updateChatFetchMoreMessages*(self: AccessInterface) {.base.} =
|
||||
method newMessagesLoaded*(self: AccessInterface, messages: seq[MessageDto], reactions: seq[ReactionDto]) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method newPinnedMessagesLoaded*(self: AccessInterface, pinnedMessages: seq[PinnedMessageDto]) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method onReactionAdded*(self: AccessInterface, messageId: string, emojiId: int, reactionId: string) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
|
@ -149,7 +149,7 @@ proc createMessageItemsFromMessageDtos(self: Module, messages: seq[MessageDto],
|
||||
if message.transactionParameters.fromAddress != "":
|
||||
isCurrentUser = self.currentUserWalletContainsAddress(message.transactionParameters.fromAddress)
|
||||
|
||||
var item = initItem(
|
||||
var item = initMessageItem(
|
||||
message.id,
|
||||
message.chatId,
|
||||
message.communityId,
|
||||
@ -193,6 +193,7 @@ proc createMessageItemsFromMessageDtos(self: Module, messages: seq[MessageDto],
|
||||
message.deleted,
|
||||
message.deletedBy,
|
||||
deletedByContactDetails,
|
||||
message.pinnedBy,
|
||||
message.mentioned,
|
||||
message.quotedMessage.`from`,
|
||||
message.quotedMessage.text,
|
||||
@ -238,7 +239,7 @@ proc createMessageItemsFromMessageDtos(self: Module, messages: seq[MessageDto],
|
||||
|
||||
proc createFetchMoreMessagesItem(self: Module): Item =
|
||||
let chatDto = self.controller.getChatDetails()
|
||||
result = initItem(
|
||||
result = initMessageItem(
|
||||
FETCH_MORE_MESSAGES_MESSAGE_ID,
|
||||
communityId = "",
|
||||
chatId = "",
|
||||
@ -275,6 +276,7 @@ proc createFetchMoreMessagesItem(self: Module): Item =
|
||||
deleted = false,
|
||||
deletedBy = "",
|
||||
deletedByContactDetails = ContactDetails(),
|
||||
pinnedBy = "",
|
||||
mentioned = false,
|
||||
quotedMessageFrom = "",
|
||||
quotedMessageText = "",
|
||||
@ -307,7 +309,7 @@ proc createChatIdentifierItem(self: Module): Item =
|
||||
(chatName, smallImage, chatIcon) = self.controller.getOneToOneChatNameAndImage()
|
||||
senderColorHash = sender.colorHash
|
||||
|
||||
result = initItem(
|
||||
result = initMessageItem(
|
||||
CHAT_IDENTIFIER_MESSAGE_ID,
|
||||
communityId = "",
|
||||
chatId = "",
|
||||
@ -344,6 +346,7 @@ proc createChatIdentifierItem(self: Module): Item =
|
||||
deleted = false,
|
||||
deletedBy = "",
|
||||
deletedByContactDetails = ContactDetails(),
|
||||
pinnedBy = "",
|
||||
mentioned = false,
|
||||
quotedMessageFrom = "",
|
||||
quotedMessageText = "",
|
||||
@ -420,10 +423,6 @@ method newMessagesLoaded*(self: Module, messages: seq[MessageDto], reactions: se
|
||||
self.initialMessagesLoaded = true
|
||||
self.reevaluateViewLoadingState()
|
||||
|
||||
method newPinnedMessagesLoaded*(self: Module, pinnedMessages: seq[PinnedMessageDto]) =
|
||||
for p in pinnedMessages:
|
||||
self.onPinMessage(p.message.id, p.pinnedBy)
|
||||
|
||||
method messagesAdded*(self: Module, messages: seq[MessageDto]) =
|
||||
let items = self.createMessageItemsFromMessageDtos(messages)
|
||||
|
||||
|
@ -175,7 +175,7 @@ proc buildPinnedMessageItem(self: Module, message: MessageDto, actionInitiatedBy
|
||||
(transactionContract, transactionValue) = self.controller.getTransactionDetails(message)
|
||||
if message.transactionParameters.fromAddress != "":
|
||||
isCurrentUser = self.currentUserWalletContainsAddress(message.transactionParameters.fromAddress)
|
||||
item = pinned_msg_item.initItem(
|
||||
item = pinned_msg_item.initMessageItem(
|
||||
message.id,
|
||||
message.communityId,
|
||||
message.chatId,
|
||||
@ -219,6 +219,7 @@ proc buildPinnedMessageItem(self: Module, message: MessageDto, actionInitiatedBy
|
||||
message.deleted,
|
||||
message.deletedBy,
|
||||
deletedByContactDetails = ContactDetails(),
|
||||
message.pinnedBy,
|
||||
message.mentioned,
|
||||
message.quotedMessage.`from`,
|
||||
message.quotedMessage.text,
|
||||
|
@ -156,7 +156,7 @@ proc buildCommunityMemberMessageItem(self: Module, message: MessageDto): member_
|
||||
(transactionContract, transactionValue) = self.controller.getTransactionDetails(message)
|
||||
if message.transactionParameters.fromAddress != "":
|
||||
isCurrentUser = self.currentUserWalletContainsAddress(message.transactionParameters.fromAddress)
|
||||
return member_msg_item.initItem(
|
||||
return member_msg_item.initMessageItem(
|
||||
message.id,
|
||||
message.communityId,
|
||||
message.chatId,
|
||||
@ -200,6 +200,7 @@ proc buildCommunityMemberMessageItem(self: Module, message: MessageDto): member_
|
||||
message.deleted,
|
||||
message.deletedBy,
|
||||
deletedByContactDetails = ContactDetails(),
|
||||
message.pinnedBy,
|
||||
message.mentioned,
|
||||
message.quotedMessage.`from`,
|
||||
message.quotedMessage.text,
|
||||
|
@ -76,7 +76,7 @@ type
|
||||
bridgeName: string
|
||||
paymentRequestModel: payment_request_model.Model
|
||||
|
||||
proc initItem*(
|
||||
proc initMessageItem*(
|
||||
id,
|
||||
communityId,
|
||||
chatId,
|
||||
@ -113,6 +113,7 @@ proc initItem*(
|
||||
deleted: bool,
|
||||
deletedBy: string,
|
||||
deletedByContactDetails: ContactDetails,
|
||||
pinnedBy: string,
|
||||
mentioned: bool,
|
||||
quotedMessageFrom: string,
|
||||
quotedMessageText: string,
|
||||
@ -164,6 +165,9 @@ proc initItem*(
|
||||
result.deleted = deleted
|
||||
result.deletedBy = deletedBy
|
||||
result.deletedByContactDetails = deletedByContactDetails
|
||||
result.pinnedBy = pinnedBy
|
||||
if pinnedBy != "":
|
||||
result.pinned = true
|
||||
result.links = links
|
||||
result.linkPreviewModel = newLinkPreviewModel(linkPreviews)
|
||||
result.emojiReactionsModel = newEmojiReactionsModel()
|
||||
@ -233,7 +237,7 @@ proc initItem*(
|
||||
result.bridgeName = bridgeMessage.bridgeName
|
||||
|
||||
proc initNewMessagesMarkerItem*(clock, timestamp: int64): Item =
|
||||
return initItem(
|
||||
return initMessageItem(
|
||||
id = "",
|
||||
communityId = "",
|
||||
chatId = "",
|
||||
@ -270,6 +274,7 @@ proc initNewMessagesMarkerItem*(clock, timestamp: int64): Item =
|
||||
deleted = false,
|
||||
deletedBy = "",
|
||||
deletedByContactDetails = ContactDetails(),
|
||||
pinnedBy = "",
|
||||
mentioned = false,
|
||||
quotedMessageFrom = "",
|
||||
quotedMessageText = "",
|
||||
|
@ -601,12 +601,15 @@ QtObject:
|
||||
defer: index.delete
|
||||
self.dataChanged(index, index, @[ModelRole.Reactions.int])
|
||||
|
||||
proc pinUnpinMessage*(self: Model, messageId: string, pin: bool, pinnedBy: string) =
|
||||
proc pinUnpinMessage*(self: Model, messageId: string, pinned: bool, pinnedBy: string) =
|
||||
let ind = self.findIndexForMessageId(messageId)
|
||||
if(ind == -1):
|
||||
if ind == -1:
|
||||
return
|
||||
|
||||
self.items[ind].pinned = pin
|
||||
if self.items[ind].pinned == pinned:
|
||||
return
|
||||
|
||||
self.items[ind].pinned = pinned
|
||||
self.items[ind].pinnedBy = pinnedBy
|
||||
|
||||
let index = self.createIndex(ind, 0, nil)
|
||||
|
@ -130,6 +130,7 @@ type MessageDto* = object
|
||||
deleted*: bool
|
||||
deletedBy*: string
|
||||
deletedForMe*: bool
|
||||
pinnedBy*: string
|
||||
transactionParameters*: TransactionParameters
|
||||
mentioned*: bool
|
||||
replied*: bool
|
||||
@ -277,6 +278,7 @@ proc toMessageDto*(jsonObj: JsonNode): MessageDto =
|
||||
# The message was deleted by the sender itself
|
||||
result.deletedBy = result.`from`
|
||||
discard jsonObj.getProp("deletedForMe", result.deletedForMe)
|
||||
discard jsonObj.getProp("pinnedBy", result.pinnedBy)
|
||||
discard jsonObj.getProp("mentioned", result.mentioned)
|
||||
discard jsonObj.getProp("replied", result.replied)
|
||||
|
||||
|
@ -9,7 +9,7 @@ import app/modules/shared_models/message_item
|
||||
import app/modules/shared_models/message_transaction_parameters_item
|
||||
|
||||
proc createTestMessageItem(id: string, clock: int64): Item =
|
||||
return initItem(
|
||||
return initMessageItem(
|
||||
id = id,
|
||||
communityId = "",
|
||||
chatId = "",
|
||||
@ -46,6 +46,7 @@ proc createTestMessageItem(id: string, clock: int64): Item =
|
||||
deleted = false,
|
||||
deletedBy = "",
|
||||
deletedByContactDetails = ContactDetails(),
|
||||
pinnedBy = "",
|
||||
mentioned = false,
|
||||
quotedMessageFrom = "",
|
||||
quotedMessageText = "",
|
||||
|
2
vendor/status-go
vendored
2
vendor/status-go
vendored
@ -1 +1 @@
|
||||
Subproject commit d291204473d2dcdb27062f017ffe9966463d4818
|
||||
Subproject commit f7d73be2edf5edb51e6d09599ef83a53b9500ffc
|
Loading…
x
Reference in New Issue
Block a user