feat(ActivityCenter): Refactor AC Store and fix notifications counting

Close #7654
This commit is contained in:
MishkaRogachev 2022-10-26 20:00:20 +04:00 committed by Mikhail Rogachev
parent 58fe1ed8ca
commit 6a72773ab6
29 changed files with 102 additions and 133 deletions

View File

@ -2,6 +2,8 @@ import strformat, stint
import ../../shared_models/message_item_qobject
import ../../../../app_service/service/activity_center/dto/notification
const CONTACT_REQUEST_PENDING_STATE = 1
type Item* = ref object
id: string # ID is the id of the chat, for public chats it is the name e.g. status, for one-to-one is the hex encoded public key and for group chats is a random uuid appended with the hex encoded pk of the creator of the chat
chatId: string
@ -111,4 +113,15 @@ proc messageItem*(self: Item): MessageItem =
return self.messageItem
proc repliedMessageItem*(self: Item): MessageItem =
return self.repliedMessageItem
return self.repliedMessageItem
# TODO: this logic should be moved to status-go
proc isNotReadOrActiveCTA*(self: Item): bool =
return ((self.notificationType == ActivityCenterNotificationType.CommunityMembershipRequest and
self.membershipStatus == ActivityCenterMembershipStatus.Pending) or
(self.notificationType == ActivityCenterNotificationType.ContactRequest and
self.messageItem.contactRequestState == CONTACT_REQUEST_PENDING_STATE) or
(self.notificationType == ActivityCenterNotificationType.Mention and
not self.read) or
(self.notificationType == ActivityCenterNotificationType.Reply and
not self.read))

View File

@ -22,7 +22,6 @@ QtObject:
type
Model* = ref object of QAbstractListModel
activityCenterNotifications*: seq[Item]
nbUnreadNotifications*: int
proc setup(self: Model) = self.QAbstractListModel.setup
@ -43,23 +42,25 @@ QtObject:
proc unreadCountChanged*(self: Model) {.signal.}
proc unreadCount*(self: Model): int {.slot.} =
self.nbUnreadNotifications
proc unreadCount*(self: Model): int {.slot.} =
result = 0
for notification in self.activityCenterNotifications:
if (notification.isNotReadOrActiveCTA()):
result += 1
return result
QtProperty[int] unreadCount:
read = unreadCount
notify = unreadCountChanged
proc markAllAsRead*(self: Model) =
self.nbUnreadNotifications = 0
self.unreadCountChanged()
for activityCenterNotification in self.activityCenterNotifications:
activityCenterNotification.read = true
let topLeft = self.createIndex(0, 0, nil)
let bottomRight = self.createIndex(self.activityCenterNotifications.len - 1, 0, nil)
self.dataChanged(topLeft, bottomRight, @[NotifRoles.Read.int])
self.unreadCountChanged()
method rowCount*(self: Model, index: QModelIndex = nil): int = self.activityCenterNotifications.len
@ -124,16 +125,7 @@ QtObject:
NotifRoles.RepliedMessage.int: "repliedMessage"
}.toTable
proc reduceUnreadCount(self: Model, numberNotifs: int) =
self.nbUnreadNotifications = self.nbUnreadNotifications - numberNotifs
if (self.nbUnreadNotifications < 0):
self.nbUnreadNotifications = 0
self.unreadCountChanged()
proc markActivityCenterNotificationUnread*(self: Model, notificationId: string) =
self.nbUnreadNotifications = self.nbUnreadNotifications + 1
self.unreadCountChanged()
var i = 0
for acnViewItem in self.activityCenterNotifications:
if (acnViewItem.id == notificationId):
@ -142,13 +134,9 @@ QtObject:
self.dataChanged(index, index, @[NotifRoles.Read.int])
break
i.inc
proc markActivityCenterNotificationRead*(self: Model, notificationId: string) =
self.nbUnreadNotifications = self.nbUnreadNotifications - 1
if (self.nbUnreadNotifications < 0):
self.nbUnreadNotifications = 0
self.unreadCountChanged()
proc markActivityCenterNotificationRead*(self: Model, notificationId: string) =
var i = 0
for acnViewItem in self.activityCenterNotifications:
if (acnViewItem.id == notificationId):
@ -157,6 +145,7 @@ QtObject:
self.dataChanged(index, index, @[NotifRoles.Read.int])
break
i.inc
self.unreadCountChanged()
proc removeNotifications*(self: Model, ids: seq[string]) =
var i = 0
@ -175,8 +164,7 @@ QtObject:
self.activityCenterNotifications.delete(indexUpdated)
self.endRemoveRows()
i = i + 1
self.reduceUnreadCount(ids.len)
self.unreadCountChanged()
proc setNewData*(self: Model, activityCenterNotifications: seq[Item]) =
self.beginResetModel()
@ -189,13 +177,6 @@ QtObject:
self.activityCenterNotifications.add(activityCenterNotification)
self.endInsertRows()
if (addToCount and not activityCenterNotification.read):
self.nbUnreadNotifications = self.nbUnreadNotifications + 1
self.unreadCountChanged()
proc updateUnreadCount*(self: Model, count: int) =
self.nbUnreadNotifications = count
self.unreadCountChanged()
proc addActivityNotificationItemsToList*(self: Model, activityCenterNotifications: seq[Item]) =
@ -208,3 +189,4 @@ QtObject:
self.removeNotifications(@[notif.id])
break
self.addActivityNotificationItemToList(activityCenterNotification, false)
self.unreadCountChanged()

View File

@ -46,9 +46,6 @@ QtObject:
self.model.addActivityNotificationItemsToList(activityCenterNotifications)
self.hasMoreToShowChanged()
let count = self.delegate.unreadActivityCenterNotificationsCount()
self.model.updateUnreadCount(count)
proc loadMoreNotifications(self: View) {.slot.} =
self.delegate.fetchActivityCenterNotifications()

View File

@ -35,7 +35,7 @@ StatusSectionLayout {
tab.item.url = _internal.determineRealURL(url)
}
notificationCount: root.globalStore.unreadNotificationsCount
notificationCount: activityCenterStore.unreadNotificationsCount
onNotificationButtonClicked: Global.openActivityCenterPopup()
QtObject {

View File

@ -125,13 +125,6 @@ QtObject {
property var globalUtilsInst: globalUtils
property var mainModuleInst: mainModule
property var activityCenterModuleInst: activityCenterModule
property var activityCenterList: activityCenterModuleInst.activityNotificationsModel
property int unreadNotificationsCount: activityCenterList.unreadCount
function loadMoreNotifications() {
activityCenterModuleInst.loadMoreNotifications()
}
property var communitiesModuleInst: communitiesModule
property var communitiesList: communitiesModuleInst.model
@ -157,29 +150,6 @@ QtObject {
stickersModule: stickersModuleInst
}
// Not Refactored Yet
// property var activeCommunity: chatsModelInst.communities.activeCommunity
function getBadgeDetails(sectionId, chatId) {
try {
const jsonObj = root.activityCenterModuleInst.getDetails(sectionId, chatId)
let obj = JSON.parse(jsonObj)
return obj
}
catch (e) {
return {
sType: "",
sName: "",
sImage: "",
sColor: "",
cName: "",
cImage: "",
cColor: "",
cEmoji: ""
}
}
}
function sendSticker(channelId, hash, replyTo, pack, url) {
stickersModuleInst.send(channelId, hash, replyTo, pack, url)
}

View File

@ -59,7 +59,7 @@ StatusSectionLayout {
notificationButton.tooltip.offset: localAccountSensitiveSettings.expandUsersList && headerContent.membersButton.visible ? 0 : 14
onNotificationButtonClicked: Global.openActivityCenterPopup()
notificationCount: root.rootStore.unreadNotificationsCount
notificationCount: activityCenterStore.unreadNotificationsCount
headerContent: ChatHeaderContentView {
id: headerContent

View File

@ -23,7 +23,7 @@ import "../layouts"
StatusSectionLayout {
id: root
notificationCount: root.rootStore.unreadNotificationsCount
notificationCount: activityCenterStore.unreadNotificationsCount
onNotificationButtonClicked: Global.openActivityCenterPopup()
// TODO: get this model from backend?
property var settingsMenuModel: root.rootStore.communityPermissionsEnabled ? [{name: qsTr("Overview"), icon: "show"},

View File

@ -85,7 +85,7 @@ Page {
StatusActivityCenterButton {
Layout.alignment: Qt.AlignVCenter
unreadNotificationsCount: root.rootStore.unreadNotificationsCount
unreadNotificationsCount: activityCenterStore.unreadNotificationsCount
onClicked: Global.openActivityCenterPopup()
}
}

View File

@ -31,7 +31,7 @@ StatusSectionLayout {
property var createCommunitiesPopup: createCommunitiesPopupComponent
property var discordImportProgressPopup: discordImportProgressDialog
notificationCount: root.communitiesStore.unreadNotificationsCount
notificationCount: activityCenterStore.unreadNotificationsCount
onNotificationButtonClicked: Global.openActivityCenterPopup()
onVisibleChanged: {

View File

@ -26,9 +26,6 @@ QtObject {
property var advancedModule: profileSectionModule.advancedModule
property bool isCommunityHistoryArchiveSupportEnabled: advancedModule? advancedModule.isCommunityHistoryArchiveSupportEnabled : false
property var activityCenterModuleInst: activityCenterModule
property var activityCenterList: activityCenterModuleInst.activityNotificationsModel
property int unreadNotificationsCount: activityCenterList.unreadCount
// TODO: Could the backend provide directly 2 filtered models??
//property var featuredCommunitiesModel: root.communitiesModuleInst.curatedFeaturedCommunities
//property var popularCommunitiesModel: root.communitiesModuleInst.curatedPopularCommunities

View File

@ -19,7 +19,7 @@ StatusSectionLayout {
property RootStore store: RootStore {}
notificationCount: root.store.unreadNotificationsCount
notificationCount: activityCenterStore.unreadNotificationsCount
onNotificationButtonClicked: Global.openActivityCenterPopup()
centerPanel: ColumnLayout {
id: rpcColumn

View File

@ -5,10 +5,6 @@ import utils 1.0
QtObject {
id: root
property var activityCenterModuleInst: activityCenterModule
property var activityCenterList: activityCenterModuleInst.activityNotificationsModel
property int unreadNotificationsCount: activityCenterList.unreadCount
property var nodeModelInst: nodeModel
// property var profileModelInst: profileModel

View File

@ -22,7 +22,7 @@ StatusSectionLayout {
property var emojiPopup
backButtonName: root.store.backButtonName
notificationCount: root.store.unreadNotificationsCount
notificationCount: activityCenterStore.unreadNotificationsCount
onNotificationButtonClicked: Global.openActivityCenterPopup()
onBackButtonClicked: {

View File

@ -8,10 +8,6 @@ QtObject {
property string backButtonName
property var activityCenterModuleInst: activityCenterModule
property var activityCenterList: activityCenterModuleInst.activityNotificationsModel
property int unreadNotificationsCount: activityCenterList.unreadCount
property var aboutModuleInst: aboutModule
property var profileSectionModuleInst: profileSectionModule

View File

@ -65,7 +65,7 @@ Item {
height: root.height - seedPhraseWarning.height
width: root.width
backButtonName: RootStore.backButtonName
notificationCount: RootStore.unreadNotificationsCount
notificationCount: activityCenterStore.unreadNotificationsCount
onNotificationButtonClicked: Global.openActivityCenterPopup()
onBackButtonClicked: {
rightPanelStackView.currentItem.resetStack();

View File

@ -23,10 +23,6 @@ QtObject {
property string signingPhrase: walletSection.signingPhrase
property string mnemonicBackedUp: walletSection.isMnemonicBackedUp
property var activityCenterModuleInst: activityCenterModule
property var activityCenterList: activityCenterModuleInst.activityNotificationsModel
property int unreadNotificationsCount: activityCenterList.unreadCount
property var walletTokensModule: walletSectionAllTokens
property var tokens: walletSectionAllTokens.all

View File

@ -14,10 +14,6 @@ QtObject {
property var communitiesModuleInst: communitiesModule
property var observedCommunity: communitiesModuleInst.observedCommunity
property var activityCenterModuleInst: activityCenterModule
property var activityCenterList: activityCenterModuleInst.activityNotificationsModel
property int unreadNotificationsCount: activityCenterList.unreadCount
property bool newVersionAvailable: false
property string latestVersion
property string downloadURL

View File

@ -40,14 +40,14 @@ import AppLayouts.stores 1.0
import "popups"
import "panels"
import "activitycenter/popups"
import "activitycenter/stores" as AC
import "activitycenter/stores"
Item {
id: appMain
property alias appLayout: appLayout
property RootStore rootStore: RootStore {}
property AC.RootStore acStore: AC.RootStore {}
property ActivityCenterStore activityCenterStore: ActivityCenterStore {}
// set from main.qml
property var sysPalette
@ -993,8 +993,7 @@ Item {
height: appView.height - 56 * 2 // TODO get screen size // Taken from old code top bar height was fixed there to 56
y: 56
store: chatLayoutContainer.rootStore
acStore: appMain.acStore
chatSectionModule: chatLayoutContainer.rootStore.chatCommunitySectionModule
activityCenterStore: appMain.activityCenterStore
onClosed: {
Global.activityCenterPopupOpened = false
}

View File

@ -16,6 +16,7 @@ import utils 1.0
import "../views"
import "../panels"
import "../stores"
Popup {
id: root
@ -39,15 +40,14 @@ Popup {
property int contactRequestsCount: 0
property int membershipCount: 0
property ActivityCenterStore activityCenterStore
property var store
property var acStore
property var chatSectionModule
property var messageContextMenu: MessageContextMenuView {
store: root.store
reactionModel: root.store.emojiReactionsModel
}
readonly property int unreadNotificationsCount : root.store.unreadNotificationsCount
readonly property int unreadNotificationsCount: root.activityCenterStore.unreadNotificationsCount
function filterActivityCategories(notificationType) {
switch (root.currentActivityCategory) {
@ -136,7 +136,7 @@ Popup {
Repeater {
id: notificationTypeCounter
model: root.store.activityCenterList
model: root.activityCenterStore.activityCenterList
delegate: Item {
Component.onCompleted: calcNotificationType(model.notificationType, 1)
@ -153,11 +153,11 @@ Popup {
hasMentions: root.mentionsCount > 0
hasContactRequests: root.contactRequestsCount > 0
hasMembership: root.membershipCount > 0
hideReadNotifications: acStore.hideReadNotifications
hideReadNotifications: activityCenterStore.hideReadNotifications
currentActivityCategory: root.currentActivityCategory
onCategoryTriggered: root.currentActivityCategory = category
onMarkAllReadClicked: errorText = root.store.activityCenterModuleInst.markAllActivityCenterNotificationsRead()
onShowHideReadNotifications: acStore.hideReadNotifications = hideReadNotifications
onMarkAllReadClicked: errorText = root.activityCenterStore.markAllActivityCenterNotificationsRead()
onShowHideReadNotifications: activityCenterStore.hideReadNotifications = hideReadNotifications
}
StatusListView {
@ -169,10 +169,10 @@ Popup {
anchors.margins: Style.current.smallPadding
model: SortFilterProxyModel {
sourceModel: root.store.activityCenterList
sourceModel: root.activityCenterStore.activityCenterList
filters: ExpressionFilter { expression: filterActivityCategories(model.notificationType) &&
!(acStore.hideReadNotifications && model.read) }
!(activityCenterStore.hideReadNotifications && model.read) }
sorters: [
RoleSorter {
@ -191,6 +191,7 @@ Popup {
ActivityNotificationMention {
width: listView.availableWidth
store: root.store
activityCenterStore: root.activityCenterStore
notification: model
messageContextMenu: root.messageContextMenu
previousNotificationIndex: Math.min(listView.count - 1, index + 1)
@ -203,6 +204,7 @@ Popup {
ActivityNotificationReply {
width: listView.availableWidth
store: root.store
activityCenterStore: root.activityCenterStore
notification: model
messageContextMenu: root.messageContextMenu
previousNotificationIndex: Math.min(listView.count - 1, index + 1)
@ -215,6 +217,7 @@ Popup {
ActivityNotificationContactRequest {
width: listView.availableWidth
store: root.store
activityCenterStore: root.activityCenterStore
notification: model
messageContextMenu: root.messageContextMenu
previousNotificationIndex: Math.min(listView.count - 1, index + 1)
@ -227,6 +230,7 @@ Popup {
ActivityNotificationCommunityInvitation {
width: listView.availableWidth
store: root.store
activityCenterStore: root.activityCenterStore
notification: model
messageContextMenu: root.messageContextMenu
previousNotificationIndex: Math.min(listView.count - 1, index + 1)
@ -239,6 +243,7 @@ Popup {
ActivityNotificationCommunityMembershipRequest {
width: listView.availableWidth
store: root.store
activityCenterStore: root.activityCenterStore
notification: model
messageContextMenu: root.messageContextMenu
previousNotificationIndex: Math.min(listView.count - 1, index + 1)
@ -251,6 +256,7 @@ Popup {
ActivityNotificationCommunityRequest {
width: listView.availableWidth
store: root.store
activityCenterStore: root.activityCenterStore
notification: model
previousNotificationIndex: Math.min(listView.count - 1, index + 1)
}
@ -261,6 +267,7 @@ Popup {
ActivityNotificationCommunityKicked {
width: listView.availableWidth
store: root.store
activityCenterStore: root.activityCenterStore
notification: model
previousNotificationIndex: Math.min(listView.count - 1, index + 1)
}

View File

@ -0,0 +1,31 @@
import QtQuick 2.14
QtObject {
id: root
property bool hideReadNotifications: false
property var activityCenterModuleInst: activityCenterModule
property var activityCenterList: activityCenterModuleInst.activityNotificationsModel
property int unreadNotificationsCount: activityCenterList.unreadCount
function markAllActivityCenterNotificationsRead() {
root.activityCenterModuleInst.markAllActivityCenterNotificationsRead()
}
function markActivityCenterNotificationRead(notification) {
root.activityCenterModuleInst.markActivityCenterNotificationRead(
notification.id, notification.message.communityId,
notification.message.chatId, notification.notificationType)
}
function markActivityCenterNotificationUnread(notification) {
root.activityCenterModuleInst.markActivityCenterNotificationUnread(
notification.id, notification.message.communityId,
notification.message.chatId, notification.notificationType)
}
function switchTo(notification) {
root.activityCenterModuleInst.switchTo(notification.sectionId, notification.chatId, notification.id)
}
}

View File

@ -1,9 +0,0 @@
import QtQuick 2.14
QtObject {
id: root
property bool hideReadNotifications: false
// TODO: move AC-related stuff from chat here
}

View File

@ -1 +1 @@
RootStore 1.0 RootStore.qml
ActivityCenterStore 1.0 ActivityCenterStore.qml

View File

@ -13,6 +13,7 @@ Item {
property var notification
property var store
property var activityCenterStore
property alias bodyComponent: bodyLoader.sourceComponent
property alias badgeComponent: badgeLoader.sourceComponent
@ -30,8 +31,8 @@ Item {
anchors.left: parent.left
messageTimestamp: notification.timestamp
previousMessageTimestamp: root.previousNotificationIndex == 0 ? "" :
root.store.activityCenterList.getNotificationData(previousNotificationIndex,
"timestamp")
root.activityCenterStore.activityCenterList.getNotificationData(
previousNotificationIndex, "timestamp")
visible: text !== ""
}
@ -57,21 +58,18 @@ Item {
sourceComponent: StatusFlatRoundButton {
id: markReadBtn
icon.width: 20
icon.height: 20
icon.source: Style.svg("check-activity")
icon.color: notification.read ? icon.disabledColor : "transparent"
color: "transparent"
tooltip.text: !notification.read ? qsTr("Mark as Read") : qsTr("Mark as Unread")
icon.color: root.notification.read ? icon.disabledColor : "transparent"
tooltip.text: !root.notification.read ? qsTr("Mark as Read") : qsTr("Mark as Unread")
tooltip.orientation: StatusToolTip.Orientation.Left
tooltip.x: -tooltip.width - Style.current.padding
tooltip.y: 4
onClicked: {
notification.read ?
root.store.activityCenterModuleInst.markActivityCenterNotificationUnread(
notification.id, notification.message.communityId,
notification.message.chatId, notification.notificationType) :
root.store.activityCenterModuleInst.markActivityCenterNotificationRead(
notification.id, notification.message.communityId,
notification.chatId, notification.notificationType)
root.activityCenterStore.markActivityCenterNotificationUnread(root.notification) :
root.activityCenterStore.markActivityCenterNotificationRead(root.notification)
}
}
}

View File

@ -28,7 +28,7 @@ ActivityNotificationMessage {
}
onChannelNameClicked: {
root.activityCenterClose()
root.store.activityCenterModuleInst.switchTo(notification.sectionId, notification.chatId, notification.id)
root.activityCenterStore.switchTo(notification)
}
}
}

View File

@ -52,14 +52,14 @@ ActivityNotificationBase {
}
root.activityCenterClose()
root.store.activityCenterModuleInst.switchTo(notification.sectionId, notification.chatId, notification.id)
root.activityCenterStore.switchTo(notification)
}
CommunityBadge {
readonly property var community: root.store.getCommunityDetailsAsJson(notification.communityId)
anchors.bottom: parent.bottom
anchors.bottomMargin: 6
anchors.verticalCenter: parent.verticalCenter
anchors.verticalCenterOffset: 15
anchors.left: parent.left
anchors.leftMargin: 160 // TODO: get right text margin
communityName: community.name

View File

@ -23,7 +23,7 @@ ActivityNotificationMessage {
property var community: root.store.getCommunityDetailsAsJson(notification.message.communityId)
// TODO: here i need chanel
// property var channel: root.store.chatSectionModule.getItemAsJson(notification.chatId)
// property var channel: root.store.getItemAsJson(notification.chatId)
communityName: community.name
communityImage: community.image
@ -36,7 +36,7 @@ ActivityNotificationMessage {
}
onChannelNameClicked: {
root.activityCenterClose()
root.store.activityCenterModuleInst.switchTo(notification.sectionId, notification.chatId, notification.id)
root.activityCenterStore.switchTo(notification)
}
}
}

View File

@ -52,7 +52,7 @@ ActivityNotificationBase {
}
root.activityCenterClose()
root.store.activityCenterModuleInst.switchTo(notification.sectionId, notification.chatId, notification.id)
root.activityCenterStore.switchTo(notification)
}
}
}

View File

@ -15,6 +15,6 @@ ActivityNotificationMessage {
badgeComponent: ReplyBadge {
repliedMessageContent: notification.repliedMessage.messageText
onReplyClicked: root.store.activityCenterModuleInst.switchTo(notification.sectionId, notification.chatId, notification.id)
onReplyClicked: root.activityCenterStore.switchTo(notification)
}
}

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit de61ed1213db6f05052bd60e18a2ecc46a27496d
Subproject commit bb4237f616ea17fb7083b91bf20ceed11ca253aa