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

@ -70,4 +70,7 @@ method switchTo*(self: AccessInterface, sectionId, chatId, messageId: string) {.
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
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")
method getChatDetailsAsJson*(self: AccessInterface, chatId: string): string {.base.} =
raise newException(ValueError, "No implementation available") 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

@ -125,4 +125,7 @@ QtObject:
self.delegate.switchTo(sectionId, chatId, messageId) self.delegate.switchTo(sectionId, chatId, messageId)
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
} }
StatusSmartIdenticon { implicitWidth: layout.implicitWidth + layout.anchors.leftMargin + layout.anchors.rightMargin
id: contactImage implicitHeight: layout.implicitHeight + layout.anchors.topMargin + layout.anchors.bottomMargin
anchors.left: channelIcon.right
anchors.leftMargin: 4 RowLayout {
anchors.verticalCenter: parent.verticalCenter id: layout
asset.name: profileImage
asset.isImage: profileImage !== "" anchors {
asset.width: 16 fill: parent
asset.height: 16 leftMargin: 8
asset.letterSize: 11 rightMargin: 8
name: root.name 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 {
Layout.alignment: Qt.AlignVCenter
asset: root.asset
name: root.name
}
StyledText {
Layout.alignment: Qt.AlignVCenter
text: chatType !== Constants.chatType.publicChat ?
StatusQUtils.Emoji.parse(Utils.removeStatusEns(StatusQUtils.Utils.filterXSS(name))) :
"#" + StatusQUtils.Utils.filterXSS(name)
color: Theme.palette.baseColor1
font.weight: Font.Medium
font.pixelSize: 13
}
} }
StyledText {
id: contactInfo
text: realChatType !== Constants.chatType.publicChat ?
StatusQUtils.Emoji.parse(Utils.removeStatusEns(StatusQUtils.Utils.filterXSS(name))) :
"#" + StatusQUtils.Utils.filterXSS(name)
anchors.left: contactImage.right
anchors.leftMargin: 4
color: textColor
font.weight: Font.Medium
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
anchors.verticalCenter:parent.verticalCenter
width: 16
height: 16
source: Style.svg("communities")
}
StatusSmartIdenticon { RowLayout {
id: identicon id: layout
anchors.left: communityIcon.right
anchors.leftMargin: Style.current.smallPadding
anchors.verticalCenter: parent.verticalCenter
name: root.communityName
asset.width: 16
asset.height: 16
asset.color: root.communityColor
asset.letterSize: width / 2.4
asset.name: root.communityImage
asset.isImage: true
}
StyledTextEdit { anchors {
id: communityNameText fill: parent
width: implicitWidth > 300 ? 300 : implicitWidth leftMargin: 8
height: 18 rightMargin: 8
anchors.left: identicon.right topMargin: 3
anchors.leftMargin: 4 bottomMargin: 3
anchors.verticalCenter: parent.verticalCenter }
text: Utils.getLinkStyle(root.communityName, hoveredLink, root.communityColor)
readOnly: true
textFormat: Text.RichText
clip: true
color: root.communityColor
font.pixelSize: 13
onLinkActivated: root.communityNameClicked()
}
SVGImage { spacing: 4
id: caretImage
source: Style.svg("show-category")
width: 16
height: 16
visible: root.channelName.length
anchors.left: communityNameText.right
anchors.verticalCenter: parent.verticalCenter
ColorOverlay { StatusIcon {
anchors.fill: parent Layout.preferredWidth: 16
source: parent Layout.preferredHeight: 16
color: root.communityColor icon: "tiny/community"
color: Theme.palette.baseColor1
}
StatusSmartIdenticon {
Layout.alignment: Qt.AlignVCenter
name: root.communityName
asset.width: 16
asset.height: 16
asset.letterSize: 11
asset.color: root.communityColor
asset.name: root.communityImage
asset.isImage: true
}
RowLayout {
Layout.alignment: Qt.AlignVCenter
spacing: 0
StyledTextEdit {
Layout.maximumWidth: 300
Layout.alignment: Qt.AlignVCenter
text: Utils.getLinkStyle(root.communityName, hoveredLink, Theme.palette.baseColor1)
readOnly: true
textFormat: Text.RichText
clip: true
color: Theme.palette.baseColor1
font.pixelSize: 13
font.weight: Font.Medium
onLinkActivated: {
root.communityNameClicked()
}
}
StatusIcon {
Layout.preferredWidth: 16
Layout.preferredHeight: 16
icon: "tiny/chevron-right"
color: Theme.palette.baseColor1
}
StyledTextEdit {
Layout.maximumWidth: 300
Layout.alignment: Qt.AlignVCenter
text: Utils.getLinkStyle("#" + root.channelName, hoveredLink, Theme.palette.baseColor1)
readOnly: true
textFormat: Text.RichText
clip: true
color: Theme.palette.baseColor1
font.pixelSize: 13
font.weight: Font.Medium
onLinkActivated: {
root.channelNameClicked()
}
}
} }
} }
StyledTextEdit {
id: channelNameText
width: implicitWidth > 300 ? 300 : implicitWidth
height: 18
anchors.left: caretImage.right
anchors.verticalCenter: parent.verticalCenter
text: Utils.getLinkStyle(root.channelName || name, hoveredLink, root.channelColor)
readOnly: true
textFormat: Text.RichText
clip: true
color: root.communityColor
font.pixelSize: 13
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
} }
} }
} }