fix: Fixed group and channel mention notifications

This commit is contained in:
Igor Sirotin 2022-10-28 17:25:48 +03:00 committed by Igor Sirotin
parent 9327b483a4
commit 82bc21b4ff
9 changed files with 199 additions and 127 deletions

View File

@ -71,3 +71,6 @@ method switchTo*(self: AccessInterface, sectionId, chatId, messageId: string) {.
method getDetails*(self: AccessInterface, sectionId: string, chatId: string): string {.base.} = method getDetails*(self: AccessInterface, sectionId: string, chatId: string): string {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method getChatDetailsAsJson*(self: AccessInterface, chatId: string): string {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -1,6 +1,7 @@
import strformat, stint import strformat, stint
import ../../shared_models/message_item_qobject import ../../shared_models/message_item_qobject
import ../../../../app_service/service/activity_center/dto/notification import ../../../../app_service/service/activity_center/dto/notification
import ../../../../app_service/service/chat/dto/chat
const CONTACT_REQUEST_PENDING_STATE = 1 const CONTACT_REQUEST_PENDING_STATE = 1
@ -19,6 +20,7 @@ type Item* = ref object
accepted: bool accepted: bool
messageItem: MessageItem messageItem: MessageItem
repliedMessageItem: MessageItem repliedMessageItem: MessageItem
chatType: ChatType
proc initItem*( proc initItem*(
id: string, id: string,
@ -34,7 +36,8 @@ proc initItem*(
dismissed: bool, dismissed: bool,
accepted: bool, accepted: bool,
messageItem: MessageItem, messageItem: MessageItem,
repliedMessageItem: MessageItem repliedMessageItem: MessageItem,
chatType: ChatType
): Item = ): Item =
result = Item() result = Item()
result.id = id result.id = id
@ -51,6 +54,7 @@ proc initItem*(
result.accepted = accepted result.accepted = accepted
result.messageItem = messageItem result.messageItem = messageItem
result.repliedMessageItem = repliedMessageItem result.repliedMessageItem = repliedMessageItem
result.chatType = chatType
proc `$`*(self: Item): string = proc `$`*(self: Item): string =
result = fmt"""StickerItem( result = fmt"""StickerItem(
@ -82,6 +86,10 @@ proc author*(self: Item): string =
proc chatId*(self: Item): string = proc chatId*(self: Item): string =
return self.chatId return self.chatId
proc chatType*(self: Item): ChatType =
return self.chatType
proc communityId*(self: Item): string = proc communityId*(self: Item): string =
return self.communityId return self.communityId

View File

@ -17,6 +17,7 @@ type
Accepted Accepted
Author Author
RepliedMessage RepliedMessage
ChatType
QtObject: QtObject:
type type
@ -70,23 +71,24 @@ QtObject:
if index.row < 0 or index.row >= self.activityCenterNotifications.len: if index.row < 0 or index.row >= self.activityCenterNotifications.len:
return return
let acitivityNotificationItem = self.activityCenterNotifications[index.row] let activityNotificationItem = self.activityCenterNotifications[index.row]
let communityItemRole = role.NotifRoles let communityItemRole = role.NotifRoles
case communityItemRole: case communityItemRole:
of NotifRoles.Id: result = newQVariant(acitivityNotificationItem.id) of NotifRoles.Id: result = newQVariant(activityNotificationItem.id)
of NotifRoles.ChatId: result = newQVariant(acitivityNotificationItem.chatId) of NotifRoles.ChatId: result = newQVariant(activityNotificationItem.chatId)
of NotifRoles.CommunityId: result = newQVariant(acitivityNotificationItem.communityId) of NotifRoles.CommunityId: result = newQVariant(activityNotificationItem.communityId)
of NotifRoles.MembershipStatus: result = newQVariant(acitivityNotificationItem.membershipStatus.int) of NotifRoles.MembershipStatus: result = newQVariant(activityNotificationItem.membershipStatus.int)
of NotifRoles.SectionId: result = newQVariant(acitivityNotificationItem.sectionId) of NotifRoles.SectionId: result = newQVariant(activityNotificationItem.sectionId)
of NotifRoles.Name: result = newQVariant(acitivityNotificationItem.name) of NotifRoles.Name: result = newQVariant(activityNotificationItem.name)
of NotifRoles.Author: result = newQVariant(acitivityNotificationItem.author) of NotifRoles.Author: result = newQVariant(activityNotificationItem.author)
of NotifRoles.NotificationType: result = newQVariant(acitivityNotificationItem.notificationType.int) of NotifRoles.NotificationType: result = newQVariant(activityNotificationItem.notificationType.int)
of NotifRoles.Message: result = newQVariant(acitivityNotificationItem.messageItem) of NotifRoles.Message: result = newQVariant(activityNotificationItem.messageItem)
of NotifRoles.Timestamp: result = newQVariant(acitivityNotificationItem.timestamp) of NotifRoles.Timestamp: result = newQVariant(activityNotificationItem.timestamp)
of NotifRoles.Read: result = newQVariant(acitivityNotificationItem.read.bool) of NotifRoles.Read: result = newQVariant(activityNotificationItem.read.bool)
of NotifRoles.Dismissed: result = newQVariant(acitivityNotificationItem.dismissed.bool) of NotifRoles.Dismissed: result = newQVariant(activityNotificationItem.dismissed.bool)
of NotifRoles.Accepted: result = newQVariant(acitivityNotificationItem.accepted.bool) of NotifRoles.Accepted: result = newQVariant(activityNotificationItem.accepted.bool)
of NotifRoles.RepliedMessage: result = newQVariant(acitivityNotificationItem.repliedMessageItem) of NotifRoles.RepliedMessage: result = newQVariant(activityNotificationItem.repliedMessageItem)
of NotifRoles.ChatType: result = newQVariant(activityNotificationItem.chatType.int)
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 ("")
@ -105,6 +107,7 @@ QtObject:
of "read": result = $(notif.read) of "read": result = $(notif.read)
of "dismissed": result = $(notif.dismissed) of "dismissed": result = $(notif.dismissed)
of "accepted": result = $(notif.accepted) of "accepted": result = $(notif.accepted)
of "chatType": result = $(notif.chatType)
else: result = ("") else: result = ("")
method roleNames(self: Model): Table[int, string] = method roleNames(self: Model): Table[int, string] =
@ -122,7 +125,8 @@ QtObject:
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" NotifRoles.RepliedMessage.int: "repliedMessage",
NotifRoles.ChatType.int: "chatType"
}.toTable }.toTable
proc markActivityCenterNotificationUnread*(self: Model, notificationId: string) = proc markActivityCenterNotificationUnread*(self: Model, notificationId: string) =

View File

@ -138,7 +138,8 @@ method convertToItems*(
n.dismissed, n.dismissed,
n.accepted, n.accepted,
messageItem, messageItem,
repliedMessageItem repliedMessageItem,
chatDetails.chatType
) )
) )
@ -247,3 +248,12 @@ method getDetails*(self: Module, sectionId: string, chatId: string): string =
jsonObject["cColor"] = %* c.color jsonObject["cColor"] = %* c.color
jsonObject["cEmoji"] = %* c.emoji jsonObject["cEmoji"] = %* c.emoji
return $jsonObject return $jsonObject
method getChatDetailsAsJson*(self: Module, chatId: string): string =
let chatDto = self.controller.getChatDetails(chatId)
var jsonObject = newJObject()
jsonObject["name"] = %* chatDto.name
jsonObject["icon"] = %* chatDto.icon
jsonObject["color"] = %* chatDto.color
jsonObject["emoji"] = %* chatDto.emoji
return $jsonObject

View File

@ -126,3 +126,6 @@ QtObject:
proc getDetails*(self: View, sectionId: string, chatId: string): string {.slot.} = proc getDetails*(self: View, sectionId: string, chatId: string): string {.slot.} =
return self.delegate.getDetails(sectionId, chatId) return self.delegate.getDetails(sectionId, chatId)
proc getChatDetailsAsJson*(self: View, chatId: string): string {.slot.} =
return self.delegate.getChatDetailsAsJson(chatId)

View File

@ -348,10 +348,9 @@ QtObject {
} }
function getCommunityDetailsAsJson(id) { function getCommunityDetailsAsJson(id) {
let jsonObj = communitiesModuleInst.getCommunityDetails(id) const jsonObj = communitiesModuleInst.getCommunityDetails(id)
try { try {
let obj = JSON.parse(jsonObj) return JSON.parse(jsonObj)
return obj
} }
catch (e) { catch (e) {
console.warn("error parsing community by id: ", id, " error: ", e.message) console.warn("error parsing community by id: ", id, " error: ", e.message)
@ -359,6 +358,17 @@ QtObject {
} }
} }
function getChatDetails(id) {
const jsonObj = activityCenterModule.getChatDetailsAsJson(id)
try {
return JSON.parse(jsonObj)
}
catch (e) {
console.warn("error parsing chat by id: ", id, " error: ", e.message)
return {}
}
}
function getLinkTitleAndCb(link) { function getLinkTitleAndCb(link) {
const result = { const result = {
title: "Status", title: "Status",

View File

@ -6,54 +6,67 @@ import Qt.labs.platform 1.1
import utils 1.0 import utils 1.0
import shared 1.0 import shared 1.0
import shared.panels 1.0 import shared.panels 1.0
import shared.controls 1.0
import StatusQ.Components 0.1 import StatusQ.Components 0.1
import StatusQ.Core 0.1 import StatusQ.Core 0.1
import StatusQ.Core.Utils 0.1 as StatusQUtils import StatusQ.Core.Utils 0.1 as StatusQUtils
import StatusQ.Core.Theme 0.1
Badge { Badge {
id: root id: root
signal channelNameClicked() signal channelNameClicked()
property int realChatType: -1 property int chatType: -1
property string name: "channelName" property string name: "channelName"
property color textColor property color textColor
property string profileImage: ""
SVGImage { property StatusAssetSettings asset: StatusAssetSettings {
id: channelIcon
width: 16 width: 16
height: 16 height: 16
fillMode: Image.PreserveAspectFit letterSize: 11
source: Style.svg("channel-icon-" + (realChatType === Constants.chatType.publicChat ? "public-chat" : "group")) }
anchors.left: parent.left
anchors.verticalCenter:parent.verticalCenter implicitWidth: layout.implicitWidth + layout.anchors.leftMargin + layout.anchors.rightMargin
implicitHeight: layout.implicitHeight + layout.anchors.topMargin + layout.anchors.bottomMargin
RowLayout {
id: layout
anchors {
fill: parent
leftMargin: 8
rightMargin: 8
topMargin: 3
bottomMargin: 3
}
spacing: 4
StatusIcon {
Layout.preferredWidth: 16
Layout.preferredHeight: 16
icon: chatType === Constants.chatType.publicChat ? "tiny/public-chat"
: "tiny/group"
color: Theme.palette.baseColor1
} }
StatusSmartIdenticon { StatusSmartIdenticon {
id: contactImage Layout.alignment: Qt.AlignVCenter
anchors.left: channelIcon.right asset: root.asset
anchors.leftMargin: 4
anchors.verticalCenter: parent.verticalCenter
asset.name: profileImage
asset.isImage: profileImage !== ""
asset.width: 16
asset.height: 16
asset.letterSize: 11
name: root.name name: root.name
} }
StyledText { StyledText {
id: contactInfo Layout.alignment: Qt.AlignVCenter
text: realChatType !== Constants.chatType.publicChat ? text: chatType !== Constants.chatType.publicChat ?
StatusQUtils.Emoji.parse(Utils.removeStatusEns(StatusQUtils.Utils.filterXSS(name))) : StatusQUtils.Emoji.parse(Utils.removeStatusEns(StatusQUtils.Utils.filterXSS(name))) :
"#" + StatusQUtils.Utils.filterXSS(name) "#" + StatusQUtils.Utils.filterXSS(name)
anchors.left: contactImage.right
anchors.leftMargin: 4 color: Theme.palette.baseColor1
color: textColor
font.weight: Font.Medium font.weight: Font.Medium
font.pixelSize: 13 font.pixelSize: 13
anchors.verticalCenter: parent.verticalCenter
} }
} }
}

View File

@ -1,6 +1,9 @@
import QtQuick 2.3 import QtQuick 2.3
import QtQuick.Layouts 1.3
import QtGraphicalEffects 1.13 import QtGraphicalEffects 1.13
import StatusQ.Core.Theme 0.1
import StatusQ.Core 0.1
import StatusQ.Components 0.1 import StatusQ.Components 0.1
import utils 1.0 import utils 1.0
@ -22,74 +25,80 @@ Badge {
signal communityNameClicked() signal communityNameClicked()
signal channelNameClicked() signal channelNameClicked()
SVGImage { implicitWidth: layout.implicitWidth + layout.anchors.leftMargin + layout.anchors.rightMargin
id: communityIcon implicitHeight: layout.implicitHeight + layout.anchors.topMargin + layout.anchors.bottomMargin
anchors.left: parent.left
anchors.leftMargin: Style.current.smallPadding RowLayout {
anchors.verticalCenter:parent.verticalCenter id: layout
width: 16
height: 16 anchors {
source: Style.svg("communities") fill: parent
leftMargin: 8
rightMargin: 8
topMargin: 3
bottomMargin: 3
}
spacing: 4
StatusIcon {
Layout.preferredWidth: 16
Layout.preferredHeight: 16
icon: "tiny/community"
color: Theme.palette.baseColor1
} }
StatusSmartIdenticon { StatusSmartIdenticon {
id: identicon Layout.alignment: Qt.AlignVCenter
anchors.left: communityIcon.right
anchors.leftMargin: Style.current.smallPadding
anchors.verticalCenter: parent.verticalCenter
name: root.communityName name: root.communityName
asset.width: 16 asset.width: 16
asset.height: 16 asset.height: 16
asset.letterSize: 11
asset.color: root.communityColor asset.color: root.communityColor
asset.letterSize: width / 2.4
asset.name: root.communityImage asset.name: root.communityImage
asset.isImage: true asset.isImage: true
} }
RowLayout {
Layout.alignment: Qt.AlignVCenter
spacing: 0
StyledTextEdit { StyledTextEdit {
id: communityNameText Layout.maximumWidth: 300
width: implicitWidth > 300 ? 300 : implicitWidth Layout.alignment: Qt.AlignVCenter
height: 18 text: Utils.getLinkStyle(root.communityName, hoveredLink, Theme.palette.baseColor1)
anchors.left: identicon.right
anchors.leftMargin: 4
anchors.verticalCenter: parent.verticalCenter
text: Utils.getLinkStyle(root.communityName, hoveredLink, root.communityColor)
readOnly: true readOnly: true
textFormat: Text.RichText textFormat: Text.RichText
clip: true clip: true
color: root.communityColor color: Theme.palette.baseColor1
font.pixelSize: 13 font.pixelSize: 13
onLinkActivated: root.communityNameClicked() font.weight: Font.Medium
onLinkActivated: {
root.communityNameClicked()
}
} }
SVGImage { StatusIcon {
id: caretImage Layout.preferredWidth: 16
source: Style.svg("show-category") Layout.preferredHeight: 16
width: 16 icon: "tiny/chevron-right"
height: 16 color: Theme.palette.baseColor1
visible: root.channelName.length
anchors.left: communityNameText.right
anchors.verticalCenter: parent.verticalCenter
ColorOverlay {
anchors.fill: parent
source: parent
color: root.communityColor
}
} }
StyledTextEdit { StyledTextEdit {
id: channelNameText Layout.maximumWidth: 300
width: implicitWidth > 300 ? 300 : implicitWidth Layout.alignment: Qt.AlignVCenter
height: 18 text: Utils.getLinkStyle("#" + root.channelName, hoveredLink, Theme.palette.baseColor1)
anchors.left: caretImage.right
anchors.verticalCenter: parent.verticalCenter
text: Utils.getLinkStyle(root.channelName || name, hoveredLink, root.channelColor)
readOnly: true readOnly: true
textFormat: Text.RichText textFormat: Text.RichText
clip: true clip: true
color: root.communityColor color: Theme.palette.baseColor1
font.pixelSize: 13 font.pixelSize: 13
onLinkActivated: root.channelNameClicked() font.weight: Font.Medium
onLinkActivated: {
root.channelNameClicked()
}
}
}
} }
} }

View File

@ -13,7 +13,17 @@ import "../controls"
ActivityNotificationMessage { ActivityNotificationMessage {
id: root id: root
badgeComponent: notification.message.communityId ? communityBadgeComponent : notification.chatId ? groupChatBadgeComponent : null badgeComponent: {
switch (notification.chatType)
{
case Constants.chatType.communityChat:
return communityBadgeComponent
case Constants.chatType.privateGroupChat:
return groupChatBadgeComponent
default:
return null
}
}
Component { Component {
id: communityBadgeComponent id: communityBadgeComponent
@ -22,14 +32,12 @@ ActivityNotificationMessage {
id: communityBadge id: communityBadge
property var community: root.store.getCommunityDetailsAsJson(notification.message.communityId) property var community: root.store.getCommunityDetailsAsJson(notification.message.communityId)
// TODO: here i need chanel property var channel: root.store.getChatDetails(notification.chatId)
// property var channel: root.store.getItemAsJson(notification.chatId)
communityName: community.name communityName: community.name
communityImage: community.image communityImage: community.image
communityColor: community.color communityColor: community.color
channelName: channel.name
// channelName: channel.name
onCommunityNameClicked: { onCommunityNameClicked: {
root.store.setActiveCommunity(notification.message.communityId) root.store.setActiveCommunity(notification.message.communityId)
@ -45,10 +53,14 @@ ActivityNotificationMessage {
id: groupChatBadgeComponent id: groupChatBadgeComponent
ChannelBadge { ChannelBadge {
realChatType: root.realChatType property var group: root.store.getChatDetails(notification.chatId)
textColor: Utils.colorForPubkey(notification.message.senderId)
name: root.name chatType: notification.chatType
profileImage: Global.getProfileImage(notification.message.chatId) name: group.name
asset.isImage: asset.name != ""
asset.name: group.icon
asset.emoji: group.emoji
asset.color: group.color
} }
} }
} }