feat(ActivityCenter): Storing activity center group in the service level

This commit is contained in:
MishkaRogachev 2023-02-21 20:11:44 +04:00 committed by Mikhail Rogachev
parent a0647d241e
commit 0529ea4be5
10 changed files with 146 additions and 133 deletions

View File

@ -140,3 +140,9 @@ proc getMessageById*(self: Controller, chatId, messageId: string): MessageDto =
if(err.len > 0):
return MessageDto()
return message
proc setActiveNotificationGroup*(self: Controller, group: int) =
self.activityCenterService.setActiveNotificationGroup(ActivityCenterGroup(group))
proc getActiveNotificationGroup*(self: Controller): int =
return self.activityCenterService.getActiveNotificationGroup().int

View File

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

View File

@ -296,3 +296,9 @@ method getChatDetailsAsJson*(self: Module, chatId: string): string =
jsonObject["color"] = %* chatDto.color
jsonObject["emoji"] = %* chatDto.emoji
return $jsonObject
method setActiveNotificationGroup*(self: Module, group: int) =
self.controller.setActiveNotificationGroup(group)
method getActiveNotificationGroup*(self: Module): int =
return self.controller.getActiveNotificationGroup()

View File

@ -144,4 +144,18 @@ QtObject:
return self.delegate.getDetails(sectionId, chatId)
proc getChatDetailsAsJson*(self: View, chatId: string): string {.slot.} =
return self.delegate.getChatDetailsAsJson(chatId)
return self.delegate.getChatDetailsAsJson(chatId)
proc activeNotificationGroupChanged*(self: View) {.signal.}
proc setActiveNotificationGroup*(self: View, group: int) {.slot.} =
self.delegate.setActiveNotificationGroup(group)
self.activeNotificationGroupChanged()
proc getActiveNotificationGroup*(self: View): int {.slot.} =
return self.delegate.getActiveNotificationGroup()
QtProperty[int] activeNotificationGroup:
read = getActiveNotificationGroup
write = setActiveNotificationGroup
notify = activeNotificationGroupChanged

View File

@ -13,13 +13,24 @@ type ActivityCenterNotificationType* {.pure.}= enum
NewPrivateGroupChat = 2,
Mention = 3,
Reply = 4,
ContactRequest = 5
CommunityInvitation = 6
CommunityRequest = 7
CommunityMembershipRequest = 8
CommunityKicked = 9
ContactRequest = 5,
CommunityInvitation = 6,
CommunityRequest = 7,
CommunityMembershipRequest = 8,
CommunityKicked = 9,
ContactVerification = 10
type ActivityCenterGroup* {.pure.}= enum
All = 0,
Mentions = 1,
Replies = 2,
Membership = 3,
Admin = 4,
ContactRequests = 5,
IdentityVerification = 6,
Transactions = 7,
System = 8
type ActivityCenterMembershipStatus* {.pure.}= enum
Idle = 0,
Pending = 1,
@ -109,4 +120,3 @@ proc parseActivityCenterNotifications*(rpcResult: JsonNode): (string, seq[Activi
for jsonMsg in rpcResult["notifications"]:
notifs.add(jsonMsg.toActivityCenterNotificationDto())
return (rpcResult{"cursor"}.getStr, notifs)

View File

@ -57,6 +57,7 @@ QtObject:
threadpool: ThreadPool
events: EventEmitter
cursor*: string
activeGroup: ActivityCenterGroup
# Forward declaration
proc asyncActivityNotificationLoad*(self: Service)
@ -72,34 +73,41 @@ QtObject:
result.QObject.setup
result.events = events
result.threadpool = threadpool
result.cursor = ""
result.activeGroup = ActivityCenterGroup.All
proc handleNewNotificationsLoaded(self: Service, activityCenterNotifications: seq[ActivityCenterNotificationDto]) =
if (activityCenterNotifications.len < 1):
return
# if (self.activeGroup == ActivityCenterGroup.All ||
# backend. )
self.events.emit(
SIGNAL_ACTIVITY_CENTER_NOTIFICATIONS_LOADED,
ActivityCenterNotificationsArgs(activityCenterNotifications: activityCenterNotifications)
)
self.events.emit(SIGNAL_ACTIVITY_CENTER_NOTIFICATIONS_COUNT_MAY_HAVE_CHANGED, Args())
proc init*(self: Service) =
self.asyncActivityNotificationLoad()
self.events.on(SignalType.Message.event) do(e: Args):
let receivedData = MessageSignal(e)
# Handling activityCenterNotifications updates
if (receivedData.activityCenterNotifications.len > 0):
self.events.emit(
SIGNAL_ACTIVITY_CENTER_NOTIFICATIONS_LOADED,
ActivityCenterNotificationsArgs(activityCenterNotifications: receivedData.activityCenterNotifications)
)
self.events.emit(SIGNAL_ACTIVITY_CENTER_NOTIFICATIONS_COUNT_MAY_HAVE_CHANGED, Args())
self.handleNewNotificationsLoaded(receivedData.activityCenterNotifications)
proc parseActivityCenterResponse*(self: Service, response: RpcResponse[JsonNode]) =
var activityCenterNotifications: seq[ActivityCenterNotificationDto] = @[]
if response.result{"activityCenterNotifications"} != nil:
for jsonMsg in response.result["activityCenterNotifications"]:
activityCenterNotifications.add(jsonMsg.toActivityCenterNotificationDto)
self.handleNewNotificationsLoaded(activityCenterNotifications)
if (activityCenterNotifications.len > 0):
self.events.emit(
SIGNAL_ACTIVITY_CENTER_NOTIFICATIONS_LOADED,
ActivityCenterNotificationsArgs(activityCenterNotifications: activityCenterNotifications)
)
self.events.emit(SIGNAL_ACTIVITY_CENTER_NOTIFICATIONS_COUNT_MAY_HAVE_CHANGED, Args())
if response.result{"activityCenterState"} != nil:
echo response.result["activityCenterNotifications"]
proc setActiveNotificationGroup*(self: Service, group: ActivityCenterGroup) =
echo "---------------------------------- setActiveNotificationGroup >", group
self.activeGroup = group
proc getActiveNotificationGroup*(self: Service): ActivityCenterGroup =
return self.activeGroup
proc hasMoreToShow*(self: Service): bool =
return self.cursor != ""
@ -224,5 +232,3 @@ QtObject:
except Exception as e:
error "Error marking as dismissed", msg = e.msg
result = e.msg

View File

@ -1,6 +1,6 @@
import QtQuick 2.14
import QtQuick.Controls 2.14
import QtQuick.Layouts 1.14
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import utils 1.0
@ -9,7 +9,7 @@ import StatusQ.Core.Theme 0.1
import StatusQ.Controls 0.1
import StatusQ.Popups 0.1
import "../popups"
import shared 1.0
Item {
id: root
@ -24,11 +24,11 @@ Item {
property bool hideReadNotifications: false
property int unreadNotificationsCount: 0
property int currentActivityCategory: ActivityCenterPopup.ActivityCategory.All
property int activeGroup: Constants.ActivityCenterGroup.All
property alias errorText: errorText.text
signal categoryTriggered(int category)
signal groupTriggered(int group)
signal markAllReadClicked()
signal showHideReadNotifications(bool hideReadNotifications)
@ -49,24 +49,24 @@ Item {
Repeater {
// NOTE: some entries are hidden until implimentation
model: [ { text: qsTr("All"), category: ActivityCenterPopup.ActivityCategory.All, visible: true, enabled: true },
{ text: qsTr("Admin"), category: ActivityCenterPopup.ActivityCategory.Admin, visible: root.hasAdmin, enabled: root.hasAdmin },
{ text: qsTr("Mentions"), category: ActivityCenterPopup.ActivityCategory.Mentions, visible: true, enabled: root.hasMentions },
{ text: qsTr("Replies"), category: ActivityCenterPopup.ActivityCategory.Replies, visible: true, enabled: root.hasReplies },
{ text: qsTr("Contact requests"), category: ActivityCenterPopup.ActivityCategory.ContactRequests, visible: true, enabled: root.hasContactRequests },
{ text: qsTr("Identity verification"), category: ActivityCenterPopup.ActivityCategory.IdentityVerification, visible: true, enabled: root.hasIdentityRequests },
{ text: qsTr("Transactions"), category: ActivityCenterPopup.ActivityCategory.Transactions, visible: false, enabled: true },
{ text: qsTr("Membership"), category: ActivityCenterPopup.ActivityCategory.Membership, visible: true, enabled: root.hasMembership },
{ text: qsTr("System"), category: ActivityCenterPopup.ActivityCategory.System, visible: false, enabled: true } ]
model: [ { text: qsTr("All"), group: Constants.ActivityCenterGroup.All, visible: true, enabled: true },
{ text: qsTr("Admin"), group: Constants.ActivityCenterGroup.Admin, visible: root.hasAdmin, enabled: root.hasAdmin },
{ text: qsTr("Mentions"), group: Constants.ActivityCenterGroup.Mentions, visible: true, enabled: root.hasMentions },
{ text: qsTr("Replies"), group: Constants.ActivityCenterGroup.Replies, visible: true, enabled: root.hasReplies },
{ text: qsTr("Contact requests"), group: Constants.ActivityCenterGroup.ContactRequests, visible: true, enabled: root.hasContactRequests },
{ text: qsTr("Identity verification"), group: Constants.ActivityCenterGroup.IdentityVerification, visible: true, enabled: root.hasIdentityRequests },
{ text: qsTr("Transactions"), group: Constants.ActivityCenterGroup.Transactions, visible: false, enabled: true },
{ text: qsTr("Membership"), group: Constants.ActivityCenterGroup.Membership, visible: true, enabled: root.hasMembership },
{ text: qsTr("System"), group: Constants.ActivityCenterGroup.System, visible: false, enabled: true } ]
StatusFlatButton {
enabled: modelData.enabled
visible: modelData.visible
text: modelData.text
size: StatusBaseButton.Size.Small
highlighted: modelData.category === root.currentActivityCategory
onClicked: root.categoryTriggered(modelData.category)
onEnabledChanged: if (!enabled && highlighted) root.categoryTriggered(ActivityCenterPopup.ActivityCategory.All)
highlighted: modelData.group === root.activeGroup
onClicked: root.groupTriggered(modelData.group)
onEnabledChanged: if (!enabled && highlighted) root.groupTriggered(Constants.ActivityCenterGroup.All)
Layout.preferredWidth: visible ? implicitWidth : 0
}
}

View File

@ -1,7 +1,6 @@
import QtQuick 2.14
import QtQuick.Controls 2.14
import QtGraphicalEffects 1.13
import Qt.labs.qmlmodels 1.0
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtGraphicalEffects 1.15
import StatusQ.Core 0.1
import StatusQ.Controls 0.1
@ -19,64 +18,19 @@ import "../stores"
Popup {
id: root
// NOTE: temporary enum until we have different categories on UI and status-go sides
enum ActivityCategory {
All,
Admin,
Mentions,
Replies,
ContactRequests,
IdentityVerification,
Transactions,
Membership,
System
}
property int currentActivityCategory: ActivityCenterPopup.ActivityCategory.All
property int adminCount: 0
property int mentionsCount: 0
property int repliesCount: 0
property int contactRequestsCount: 0
property int identityRequestsCount: 0
property int membershipCount: 0
// FIXME: counters from service
property int adminCount: 1
property int mentionsCount: 1
property int repliesCount: 1
property int contactRequestsCount: 1
property int identityRequestsCount: 1
property int membershipCount: 1
property ActivityCenterStore activityCenterStore
property var store
readonly property int unreadNotificationsCount: root.activityCenterStore.unreadNotificationsCount
function calcNotificationType(notificationType, cnt) {
switch (notificationType) {
case Constants.activityCenterNotificationTypeMention:
root.mentionsCount += cnt;
break;
case Constants.activityCenterNotificationTypeReply:
root.repliesCount += cnt;
break;
case Constants.activityCenterNotificationTypeContactRequest:
root.contactRequestsCount += cnt;
break;
case Constants.activityCenterNotificationTypeContactVerification:
root.identityRequestsCount += cnt;
break;
case Constants.activityCenterNotificationTypeCommunityInvitation:
root.membershipCount += cnt;
break;
case Constants.activityCenterNotificationTypeCommunityMembershipRequest:
// NOTE: not a typo, membership requests are shown in both categories
root.membershipCount += cnt;
root.adminCount += cnt;
break;
case Constants.activityCenterNotificationTypeCommunityRequest:
root.membershipCount += cnt;
break;
case Constants.ActivityCenterNotificationTypeCommunityKicked:
root.membershipCount += cnt;
break;
default:
break;
}
}
onOpened: {
Global.popupOpened = true
}
@ -108,16 +62,6 @@ Popup {
}
}
Repeater {
id: notificationTypeCounter
model: root.activityCenterStore.activityCenterNotifications
delegate: Item {
Component.onCompleted: calcNotificationType(model.notificationType, 1)
Component.onDestruction: calcNotificationType(model.notificationType, -1)
}
}
ActivityCenterPopupTopBarPanel {
id: activityCenterTopBar
width: parent.width
@ -129,8 +73,8 @@ Popup {
hasIdentityRequests: root.identityRequestsCount > 0
hasMembership: root.membershipCount > 0
hideReadNotifications: activityCenterStore.hideReadNotifications
currentActivityCategory: root.currentActivityCategory
onCategoryTriggered: root.currentActivityCategory = category
activeGroup: activityCenterStore.activeNotificationGroup
onGroupTriggered: activityCenterStore.setActiveNotificationGroup(group)
onMarkAllReadClicked: root.activityCenterStore.markAllActivityCenterNotificationsRead()
onShowHideReadNotifications: activityCenterStore.hideReadNotifications = hideReadNotifications
}
@ -154,21 +98,21 @@ Popup {
sourceComponent: {
switch (model.notificationType) {
case Constants.activityCenterNotificationTypeMention:
case Constants.ActivityCenterNotificationType.Mention:
return mentionNotificationComponent
case Constants.activityCenterNotificationTypeReply:
case Constants.ActivityCenterNotificationType.Reply:
return replyNotificationComponent
case Constants.activityCenterNotificationTypeContactRequest:
case Constants.ActivityCenterNotificationType.ContactRequest:
return contactRequestNotificationComponent
case Constants.activityCenterNotificationTypeContactVerification:
case Constants.ActivityCenterNotificationType.ContactVerification:
return verificationRequestNotificationComponent
case Constants.activityCenterNotificationTypeCommunityInvitation:
case Constants.ActivityCenterNotificationType.CommunityInvitation:
return communityInvitationNotificationComponent
case Constants.activityCenterNotificationTypeCommunityMembershipRequest:
case Constants.ActivityCenterNotificationType.MembershipRequest:
return membershipRequestNotificationComponent
case Constants.activityCenterNotificationTypeCommunityRequest:
case Constants.ActivityCenterNotificationType.CommunityRequest:
return communityRequestNotificationComponent
case Constants.activityCenterNotificationTypeCommunityKicked:
case Constants.ActivityCenterNotificationType.CommunityKicked:
return communityKickedNotificationComponent
default:
return null

View File

@ -1,4 +1,6 @@
import QtQuick 2.14
import QtQuick 2.15
import shared 1.0
QtObject {
id: root
@ -9,6 +11,7 @@ QtObject {
readonly property var activityCenterNotifications: activityCenterModuleInst.activityNotificationsModel
readonly property int unreadNotificationsCount: activityCenterModuleInst.unreadActivityCenterNotificationsCount
readonly property bool hasUnseenNotifications: activityCenterModuleInst.hasUnseenActivityCenterNotifications
readonly property int activeNotificationGroup: activityCenterModuleInst.activeNotificationGroup
function markAllActivityCenterNotificationsRead() {
root.activityCenterModuleInst.markAllActivityCenterNotificationsRead()
@ -33,4 +36,8 @@ QtObject {
function switchTo(notification) {
root.activityCenterModuleInst.switchTo(notification.sectionId, notification.chatId, notification.id)
}
function setActiveNotificationGroup(group) {
root.activityCenterModuleInst.setActiveNotificationGroup(group)
}
}

View File

@ -613,17 +613,31 @@ QtObject {
readonly property int communityChatInvitationOnlyAccess: 2
readonly property int communityChatOnRequestAccess: 3
readonly property int activityCenterNotificationTypeNoType: 0
readonly property int activityCenterNotificationTypeOneToOne: 1
readonly property int activityCenterNotificationTypeGroupRequest: 2
readonly property int activityCenterNotificationTypeMention: 3
readonly property int activityCenterNotificationTypeReply: 4
readonly property int activityCenterNotificationTypeContactRequest: 5
readonly property int activityCenterNotificationTypeCommunityInvitation: 6
readonly property int activityCenterNotificationTypeCommunityRequest: 7
readonly property int activityCenterNotificationTypeCommunityMembershipRequest: 8
readonly property int activityCenterNotificationTypeCommunityKicked: 9
readonly property int activityCenterNotificationTypeContactVerification: 10
enum ActivityCenterGroup {
All = 0,
Mentions = 1,
Replies = 2,
Membership = 3,
Admin = 4,
ContactRequests = 5,
IdentityVerification = 6,
Transactions = 7,
System = 8
}
enum ActivityCenterNotificationType {
NoType = 0,
NewOneToOne = 1,
NewPrivateGroupChat = 2,
Mention = 3,
Reply = 4,
ContactRequest = 5,
CommunityInvitation = 6,
CommunityRequest = 7,
CommunityMembershipRequest = 8,
CommunityKicked = 9,
ContactVerification = 10
}
readonly property int activityCenterMembershipStatusPending: 1
readonly property int activityCenterMembershipStatusAccepted: 2