fix(@desktop/chat): Show badge and message in activity center for reply elements

Fix #5523
This commit is contained in:
Michal Iskierko 2022-05-13 17:35:14 +02:00 committed by Michał Iskierko
parent 0ee0c8ddd4
commit 2e5f1c9c4d
7 changed files with 62 additions and 35 deletions

View File

@ -117,3 +117,9 @@ proc getChannelGroups*(self: Controller): seq[ChannelGroupDto] =
proc getOneToOneChatNameAndImage*(self: Controller, chatId: string): tuple[name: string, image: string] = proc getOneToOneChatNameAndImage*(self: Controller, chatId: string): tuple[name: string, image: string] =
return self.chatService.getOneToOneChatNameAndImage(chatId) return self.chatService.getOneToOneChatNameAndImage(chatId)
proc getMessageById*(self: Controller, chatId, messageId: string): MessageDto =
let (message, _, err) = self.messageService.getDetailsForMessage(chatId, messageId)
if(err.len > 0):
return MessageDto()
return message

View File

@ -13,6 +13,7 @@ type Item* = ref object
dismissed: bool dismissed: bool
accepted: bool accepted: bool
messageItem: MessageItem messageItem: MessageItem
repliedMessageItem: MessageItem
proc initItem*( proc initItem*(
id: string, id: string,
@ -25,7 +26,8 @@ proc initItem*(
read: bool, read: bool,
dismissed: bool, dismissed: bool,
accepted: bool, accepted: bool,
messageItem: MessageItem messageItem: MessageItem,
repliedMessageItem: MessageItem
): Item = ): Item =
result = Item() result = Item()
result.id = id result.id = id
@ -39,6 +41,7 @@ proc initItem*(
result.dismissed = dismissed result.dismissed = dismissed
result.accepted = accepted result.accepted = accepted
result.messageItem = messageItem result.messageItem = messageItem
result.repliedMessageItem = repliedMessageItem
proc `$`*(self: Item): string = proc `$`*(self: Item): string =
result = fmt"""StickerItem( result = fmt"""StickerItem(
@ -53,6 +56,7 @@ proc `$`*(self: Item): string =
dismissed: {$self.dismissed}, dismissed: {$self.dismissed},
accepted: {$self.accepted}, accepted: {$self.accepted},
# messageItem: {$self.messageItem}, # messageItem: {$self.messageItem},
# repliedMessageItem: {$self.repliedMessageItem},
]""" ]"""
proc id*(self: Item): string = proc id*(self: Item): string =
@ -90,3 +94,6 @@ proc accepted*(self: Item): bool =
proc messageItem*(self: Item): MessageItem = proc messageItem*(self: Item): MessageItem =
return self.messageItem return self.messageItem
proc repliedMessageItem*(self: Item): MessageItem =
return self.repliedMessageItem

View File

@ -14,6 +14,7 @@ type
Dismissed Dismissed
Accepted Accepted
Author Author
RepliedMessage
QtObject: QtObject:
type type
@ -80,6 +81,7 @@ QtObject:
of NotifRoles.Read: result = newQVariant(acitivityNotificationItem.read.bool) of NotifRoles.Read: result = newQVariant(acitivityNotificationItem.read.bool)
of NotifRoles.Dismissed: result = newQVariant(acitivityNotificationItem.dismissed.bool) of NotifRoles.Dismissed: result = newQVariant(acitivityNotificationItem.dismissed.bool)
of NotifRoles.Accepted: result = newQVariant(acitivityNotificationItem.accepted.bool) of NotifRoles.Accepted: result = newQVariant(acitivityNotificationItem.accepted.bool)
of NotifRoles.RepliedMessage: result = newQVariant(acitivityNotificationItem.repliedMessageItem)
proc getNotificationData(self: Model, index: int, data: string): string {.slot.} = proc getNotificationData(self: Model, index: int, data: string): string {.slot.} =
if index < 0 or index >= self.activityCenterNotifications.len: return ("") if index < 0 or index >= self.activityCenterNotifications.len: return ("")
@ -110,7 +112,8 @@ QtObject:
NotifRoles.Timestamp.int: "timestamp", NotifRoles.Timestamp.int: "timestamp",
NotifRoles.Read.int: "read", NotifRoles.Read.int: "read",
NotifRoles.Dismissed.int: "dismissed", NotifRoles.Dismissed.int: "dismissed",
NotifRoles.Accepted.int: "accepted" NotifRoles.Accepted.int: "accepted",
NotifRoles.RepliedMessage.int: "repliedMessage"
}.toTable }.toTable
proc reduceUnreadCount(self: Model, numberNotifs: int) = proc reduceUnreadCount(self: Model, numberNotifs: int) =

View File

@ -68,6 +68,33 @@ method hasMoreToShow*(self: Module): bool =
method unreadActivityCenterNotificationsCount*(self: Module): int = method unreadActivityCenterNotificationsCount*(self: Module): int =
self.controller.unreadActivityCenterNotificationsCount() self.controller.unreadActivityCenterNotificationsCount()
proc createMessageItemFromDto(self: Module, message: MessageDto, chatDetails: ChatDto): MessageItem =
let contactDetails = self.controller.getContactDetails(message.`from`)
return msg_item_qobj.newMessageItem(msg_item.initItem(
message.id,
chatDetails.communityId, # we don't received community id via `activityCenterNotifications` api call
message.responseTo,
message.`from`,
contactDetails.displayName,
contactDetails.details.localNickname,
contactDetails.icon,
contactDetails.isCurrentUser,
contactDetails.details.added,
message.outgoingStatus,
self.controller.getRenderedText(message.parsedText),
message.image,
message.containsContactMentions(),
message.seen,
message.timestamp,
ContentType(message.contentType),
message.messageType,
self.controller.decodeContentHash(message.sticker.hash),
message.sticker.pack,
message.links,
newTransactionParametersItem("","","","","","",-1,""),
message.mentionedUsersPks
))
method convertToItems*( method convertToItems*(
self: Module, self: Module,
activityCenterNotifications: seq[ActivityCenterNotificationDto] activityCenterNotifications: seq[ActivityCenterNotificationDto]
@ -75,6 +102,7 @@ method convertToItems*(
result = activityCenterNotifications.map( result = activityCenterNotifications.map(
proc(n: ActivityCenterNotificationDto): notification_item.Item = proc(n: ActivityCenterNotificationDto): notification_item.Item =
var messageItem = msg_item_qobj.newMessageItem(nil) var messageItem = msg_item_qobj.newMessageItem(nil)
var repliedMessageItem = msg_item_qobj.newMessageItem(nil)
let chatDetails = self.controller.getChatDetails(n.chatId) let chatDetails = self.controller.getChatDetails(n.chatId)
# default section id is `Chat` section # default section id is `Chat` section
@ -85,31 +113,11 @@ method convertToItems*(
if (n.message.id != ""): if (n.message.id != ""):
# If there is a message in the Notification, transfer it to a MessageItem (QObject) # If there is a message in the Notification, transfer it to a MessageItem (QObject)
let contactDetails = self.controller.getContactDetails(n.message.`from`) messageItem = self.createMessageItemFromDto(n.message, chatDetails)
messageItem = msg_item_qobj.newMessageItem(msg_item.initItem(
n.message.id, if (n.notificationType == ActivityCenterNotificationType.Reply and n.message.responseTo != ""):
chatDetails.communityId, # we don't received community id via `activityCenterNotifications` api call let repliedMessage = self.controller.getMessageById(n.chatId, n.message.responseTo)
n.message.responseTo, repliedMessageItem = self.createMessageItemFromDto(repliedMessage, chatDetails)
n.message.`from`,
contactDetails.displayName,
contactDetails.details.localNickname,
contactDetails.icon,
contactDetails.isCurrentUser,
contactDetails.details.added,
n.message.outgoingStatus,
self.controller.getRenderedText(n.message.parsedText),
n.message.image,
n.message.containsContactMentions(),
n.message.seen,
n.message.timestamp,
ContentType(n.message.contentType),
n.message.messageType,
self.controller.decodeContentHash(n.message.sticker.hash),
n.message.sticker.pack,
n.message.links,
newTransactionParametersItem("","","","","","",-1,""),
n.message.mentionedUsersPks
))
return notification_item.initItem( return notification_item.initItem(
n.id, n.id,
@ -122,7 +130,8 @@ method convertToItems*(
n.read, n.read,
n.dismissed, n.dismissed,
n.accepted, n.accepted,
messageItem messageItem,
repliedMessageItem
) )
) )

View File

@ -12,11 +12,11 @@ import StatusQ.Core.Utils 0.1 as StatusQUtils
Item { Item {
id: replyComponent id: replyComponent
property int replyMessageIndex: wrapper.replyMessageIndex property int repliedMessageId: wrapper.repliedMessageId
property string repliedMessageContent: wrapper.repliedMessageContent property string repliedMessageContent: wrapper.repliedMessageContent
onReplyMessageIndexChanged: { onRepliedMessageIdChanged: {
wrapper.visible = replyMessageIndex > -1 wrapper.visible = (repliedMessageId.length > 0)
} }
SVGImage { SVGImage {

View File

@ -20,7 +20,7 @@ Rectangle {
property string communityName: "" property string communityName: ""
property string communityColor: "" property string communityColor: ""
property string communityThumbnailImage: "" property string communityThumbnailImage: ""
property int replyMessageIndex: -1 property string repliedMessageId: ""
property string repliedMessageContent: "" property string repliedMessageContent: ""
property int notificationType property int notificationType
property string profileImage: "" property string profileImage: ""
@ -56,7 +56,7 @@ Rectangle {
ActivityCenter.ReplyComponent { ActivityCenter.ReplyComponent {
width: childrenRect.width width: childrenRect.width
height: parent.height height: parent.height
replyMessageIndex: wrapper.replyMessageIndex repliedMessageId: wrapper.repliedMessageId
repliedMessageContent: wrapper.repliedMessageContent repliedMessageContent: wrapper.repliedMessageContent
} }
} }

View File

@ -43,7 +43,7 @@ Item {
function reevaluateItemBadge() { function reevaluateItemBadge() {
let details = root.store.getBadgeDetails(model.sectionId, model.chatId) let details = root.store.getBadgeDetails(model.sectionId, model.chatId)
badge.isCommunity = details.sType == "community" badge.isCommunity = (details.sType === "community")
badge.name = details.cName badge.name = details.cName
badge.channelName = details.cName badge.channelName = details.cName
badge.communityName = details.sName badge.communityName = details.sName
@ -185,6 +185,8 @@ Item {
visible: model.notificationType !== Constants.activityCenterNotificationTypeOneToOne visible: model.notificationType !== Constants.activityCenterNotificationTypeOneToOne
notificationType: model.notificationType notificationType: model.notificationType
profileImage: realChatType === Constants.chatType.oneToOne ? Global.getProfileImage(chatId) || "" : "" profileImage: realChatType === Constants.chatType.oneToOne ? Global.getProfileImage(chatId) || "" : ""
repliedMessageContent: model.repliedMessage.messageText
repliedMessageId: model.message.responseToMessageWithId
onCommunityNameClicked: { onCommunityNameClicked: {
root.store.activityCenterModuleInst.switchTo(model.sectionId, "", "") root.store.activityCenterModuleInst.switchTo(model.sectionId, "", "")