Skip to content

Commit

Permalink
feat(ActivityCenter): Move AC notifications counting to status-go
Browse files Browse the repository at this point in the history
Close #8074
  • Loading branch information
MishkaRogachev committed Jan 30, 2023
1 parent 7ed5b0d commit 128ac8d
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 50 deletions.
4 changes: 3 additions & 1 deletion src/app/modules/main/activity_center/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ proc init*(self: Controller) =
if (evArgs.notificationIds.len > 0):
self.delegate.markActivityCenterNotificationUnreadDone(evArgs.notificationIds)

self.events.on(activity_center_service.SIGNAL_ACTIVITY_CENTER_NOTIFICATIONS_COUNT_MAY_HAVE_CHANGED) do(e: Args):
self.delegate.unreadActivityCenterNotificationsCountChanged()

proc hasMoreToShow*(self: Controller): bool =
return self.activityCenterService.hasMoreToShow()

proc unreadActivityCenterNotificationsCount*(self: Controller): int =
return self.activityCenterService.unreadActivityCenterNotificationsCount()
return self.activityCenterService.getUnreadActivityCenterNotificationsCount()

proc getContactDetails*(self: Controller, contactId: string): ContactDetails =
return self.contactsService.getContactDetails(contactId)
Expand Down
3 changes: 3 additions & 0 deletions src/app/modules/main/activity_center/io_interface.nim
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ method hasMoreToShow*(self: AccessInterface): bool {.base.} =
method unreadActivityCenterNotificationsCount*(self: AccessInterface): int {.base.} =
raise newException(ValueError, "No implementation available")

method unreadActivityCenterNotificationsCountChanged*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

method convertToItems*(self: AccessInterface, activityCenterNotifications: seq[ActivityCenterNotificationDto]): seq[Item] {.base.} =
raise newException(ValueError, "No implementation available")

Expand Down
13 changes: 0 additions & 13 deletions src/app/modules/main/activity_center/item.nim
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,3 @@ proc messageItem*(self: Item): MessageItem =

proc repliedMessageItem*(self: Item): MessageItem =
return self.repliedMessageItem

# TODO: this logic should be moved to status-go (https://github.com/status-im/status-desktop/issues/8074)
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.ContactVerification and
self.verificationStatus == VerificationStatus.Verifying) or
(self.notificationType == ActivityCenterNotificationType.Mention and
not self.read) or
(self.notificationType == ActivityCenterNotificationType.Reply and
not self.read))
20 changes: 0 additions & 20 deletions src/app/modules/main/activity_center/model.nim
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,13 @@ QtObject:
if (notification.chatId == chatId and not notification.read):
result.add(notification.id)

proc unreadCountChanged*(self: Model) {.signal.}

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) =
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

Expand Down Expand Up @@ -127,7 +113,6 @@ QtObject:
self.dataChanged(index, index, @[NotifRoles.Read.int])
break
i.inc
self.unreadCountChanged()

proc markActivityCenterNotificationRead*(self: Model, notificationId: string) =
var i = 0
Expand All @@ -138,7 +123,6 @@ QtObject:
self.dataChanged(index, index, @[NotifRoles.Read.int])
break
i.inc
self.unreadCountChanged()

proc removeNotifications*(self: Model, ids: seq[string]) =
var i = 0
Expand All @@ -157,7 +141,6 @@ QtObject:
self.activityCenterNotifications.delete(indexUpdated)
self.endRemoveRows()
i = i + 1
self.unreadCountChanged()

proc setNewData*(self: Model, activityCenterNotifications: seq[Item]) =
self.beginResetModel()
Expand All @@ -169,8 +152,6 @@ QtObject:
self.activityCenterNotifications.insert(activityCenterNotification, 0)
self.endInsertRows()

self.unreadCountChanged()

if self.activityCenterNotifications.len > 1:
let topLeft = self.createIndex(0, 0, nil)
let bottomRight = self.createIndex(1, 0, nil)
Expand All @@ -186,4 +167,3 @@ QtObject:
self.removeNotifications(@[notif.id])
break
self.addActivityNotificationItemToList(activityCenterNotification, false)
self.unreadCountChanged()
3 changes: 3 additions & 0 deletions src/app/modules/main/activity_center/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ method hasMoreToShow*(self: Module): bool =
method unreadActivityCenterNotificationsCount*(self: Module): int =
self.controller.unreadActivityCenterNotificationsCount()

method unreadActivityCenterNotificationsCountChanged*(self: Module) =
self.view.unreadActivityCenterNotificationsCountChanged()

proc createMessageItemFromDto(self: Module, message: MessageDto, chatDetails: ChatDto): MessageItem =
let contactDetails = self.controller.getContactDetails(message.`from`)
let communityChats = self.controller.getCommunityById(chatDetails.communityId).chats
Expand Down
9 changes: 9 additions & 0 deletions src/app/modules/main/activity_center/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ QtObject:
read = hasMoreToShow
notify = hasMoreToShowChanged

proc unreadActivityCenterNotificationsCountChanged*(self: View) {.signal.}

proc unreadActivityCenterNotificationsCount*(self: View): int {.slot.} =
self.delegate.unreadActivityCenterNotificationsCount()

QtProperty[int] unreadActivityCenterNotificationsCount:
read = unreadActivityCenterNotificationsCount
notify = unreadActivityCenterNotificationsCountChanged

proc pushActivityCenterNotifications*(self:View, activityCenterNotifications: seq[Item]) =
self.model.addActivityNotificationItemsToList(activityCenterNotifications)
self.hasMoreToShowChanged()
Expand Down
29 changes: 19 additions & 10 deletions src/app_service/service/activity_center/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type

# Signals which may be emitted by this service:
const SIGNAL_ACTIVITY_CENTER_NOTIFICATIONS_LOADED* = "activityCenterNotificationsLoaded"
const SIGNAL_ACTIVITY_CENTER_NOTIFICATIONS_COUNT_MAY_HAVE_CHANGED* = "activityCenterNotificationsCountMayChanged"
const SIGNAL_MARK_NOTIFICATIONS_AS_READ* = "markNotificationsAsRead"
const SIGNAL_MARK_NOTIFICATIONS_AS_UNREAD* = "markNotificationsAsUnread"
const SIGNAL_MARK_NOTIFICATIONS_AS_ACCEPTED* = "markNotificationsAsAccepted"
Expand Down Expand Up @@ -83,6 +84,7 @@ QtObject:
SIGNAL_ACTIVITY_CENTER_NOTIFICATIONS_LOADED,
ActivityCenterNotificationsArgs(activityCenterNotifications: receivedData.activityCenterNotifications)
)
self.events.emit(SIGNAL_ACTIVITY_CENTER_NOTIFICATIONS_COUNT_MAY_HAVE_CHANGED, Args())

proc parseACNotificationResponse*(self: Service, response: RpcResponse[JsonNode]) =
var activityCenterNotifications: seq[ActivityCenterNotificationDto] = @[]
Expand All @@ -95,6 +97,7 @@ QtObject:
SIGNAL_ACTIVITY_CENTER_NOTIFICATIONS_LOADED,
ActivityCenterNotificationsArgs(activityCenterNotifications: activityCenterNotifications)
)
self.events.emit(SIGNAL_ACTIVITY_CENTER_NOTIFICATIONS_COUNT_MAY_HAVE_CHANGED, Args())

proc hasMoreToShow*(self: Service): bool =
return self.cursor != ""
Expand Down Expand Up @@ -123,6 +126,15 @@ QtObject:
self.cursor = activityCenterNotificationsTuple[0];
result = activityCenterNotificationsTuple[1]

proc getUnreadActivityCenterNotificationsCount*(self: Service): int =
try:
let response = backend.unreadActivityCenterNotificationsCount()

if response.result.kind != JNull:
return response.result.getInt
except Exception as e:
error "Error getting unread activity center unread count", msg = e.msg

proc markActivityCenterNotificationRead*(
self: Service,
notificationId: string,
Expand All @@ -131,19 +143,11 @@ QtObject:
try:
discard backend.markActivityCenterNotificationsRead(@[notificationId])
self.events.emit(SIGNAL_MARK_NOTIFICATIONS_AS_READ, markAsReadProps)
self.events.emit(SIGNAL_ACTIVITY_CENTER_NOTIFICATIONS_COUNT_MAY_HAVE_CHANGED, Args())
except Exception as e:
error "Error marking as read", msg = e.msg
result = e.msg

proc unreadActivityCenterNotificationsCount*(self: Service): int =
try:
let response = backend.unreadActivityCenterNotificationsCount()

if response.result.kind != JNull:
return response.result.getInt
except Exception as e:
error "Error getting unread activity center unread count", msg = e.msg

proc markActivityCenterNotificationUnread*(
self: Service,
notificationId: string,
Expand All @@ -152,6 +156,7 @@ QtObject:
try:
discard backend.markActivityCenterNotificationsUnread(@[notificationId])
self.events.emit(SIGNAL_MARK_NOTIFICATIONS_AS_UNREAD, markAsUnreadProps)
self.events.emit(SIGNAL_ACTIVITY_CENTER_NOTIFICATIONS_COUNT_MAY_HAVE_CHANGED, Args())
except Exception as e:
error "Error marking as unread", msg = e.msg
result = e.msg
Expand All @@ -167,6 +172,7 @@ QtObject:

self.events.emit(SIGNAL_MARK_NOTIFICATIONS_AS_READ,
MarkAsReadNotificationProperties(notificationTypes: types, isAll: true))
self.events.emit(SIGNAL_ACTIVITY_CENTER_NOTIFICATIONS_COUNT_MAY_HAVE_CHANGED, Args())
except Exception as e:
error "Error marking all as read", msg = e.msg
result = e.msg
Expand All @@ -185,7 +191,9 @@ QtObject:
proc acceptActivityCenterNotifications*(self: Service, notificationIds: seq[string]): string =
try:
discard backend.acceptActivityCenterNotifications(notificationIds)

self.events.emit(SIGNAL_MARK_NOTIFICATIONS_AS_ACCEPTED,
MarkAsDismissedNotificationProperties(notificationIds: notificationIds))
self.events.emit(SIGNAL_ACTIVITY_CENTER_NOTIFICATIONS_COUNT_MAY_HAVE_CHANGED, Args())
except Exception as e:
error "Error marking as accepted", msg = e.msg
result = e.msg
Expand All @@ -195,6 +203,7 @@ QtObject:
discard backend.dismissActivityCenterNotifications(notificationIds)
self.events.emit(SIGNAL_MARK_NOTIFICATIONS_AS_DISMISSED,
MarkAsDismissedNotificationProperties(notificationIds: notificationIds))
self.events.emit(SIGNAL_ACTIVITY_CENTER_NOTIFICATIONS_COUNT_MAY_HAVE_CHANGED, Args())
except Exception as e:
error "Error marking as dismissed", msg = e.msg
result = e.msg
Expand Down
3 changes: 3 additions & 0 deletions src/backend/backend.nim
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ rpc(dismissActivityCenterNotifications, "wakuext"):
rpc(unreadActivityCenterNotificationsCount, "wakuext"):
discard

rpc(unreadAndAcceptedActivityCenterNotificationsCount, "wakuext"):
discard

rpc(getBookmarks, "browsers"):
discard

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ Popup {
anchors.top: activityCenterTopBar.bottom
anchors.bottom: parent.bottom
anchors.margins: Style.current.smallPadding
spacing: Style.current.padding
spacing: 1

model: SortFilterProxyModel {
sourceModel: root.activityCenterStore.activityCenterList
Expand Down
6 changes: 3 additions & 3 deletions ui/app/mainui/activitycenter/stores/ActivityCenterStore.qml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ QtObject {

property bool hideReadNotifications: false

property var activityCenterModuleInst: activityCenterModule
property var activityCenterList: activityCenterModuleInst.activityNotificationsModel
property int unreadNotificationsCount: activityCenterList.unreadCount
readonly property var activityCenterModuleInst: activityCenterModule
readonly property var activityCenterList: activityCenterModuleInst.activityNotificationsModel
readonly property int unreadNotificationsCount: activityCenterModuleInst.unreadActivityCenterNotificationsCount

function markAllActivityCenterNotificationsRead() {
root.activityCenterModuleInst.markAllActivityCenterNotificationsRead()
Expand Down
13 changes: 12 additions & 1 deletion ui/app/mainui/activitycenter/views/ActivityNotificationBase.qml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Item {

signal closeActivityCenter()

implicitHeight: Math.max(60, bodyLoader.height +
implicitHeight: Math.max(60, bodyLoader.height + bodyLoader.anchors.topMargin * 2 +
(dateGroupLabel.visible ? dateGroupLabel.height : 0) +
(badgeLoader.item ? badgeLoader.height + Style.current.smallPadding : 0))

Expand All @@ -37,16 +37,27 @@ Item {
visible: text !== ""
}

Rectangle {
id: backgroundRect
anchors.fill: parent
anchors.topMargin: dateGroupLabel.visible ? dateGroupLabel.height : 0
radius: 6
color: notification && !notification.read ? Theme.palette.primaryColor3 : "transparent"
Behavior on color { ColorAnimation { duration: 200 } }
}

Loader {
id: bodyLoader
anchors.top: dateGroupLabel.visible ? dateGroupLabel.bottom : parent.top
anchors.topMargin: Style.current.smallPadding
anchors.right: ctaLoader.left
anchors.left: parent.left
}

Loader {
id: badgeLoader
anchors.bottom: parent.bottom
anchors.bottomMargin: Style.current.smallPadding
anchors.left: parent.left
anchors.leftMargin: 50 // TODO find a way to align with the text of the message
}
Expand Down
2 changes: 1 addition & 1 deletion vendor/status-go
Submodule status-go updated 67 files
+8 −6 Makefile
+1 −1 VERSION
+2 −37 account/accounts.go
+140 −57 api/backend_test.go
+111 −5 api/geth_backend.go
+69 −45 appdatabase/migrations/bindata.go
+15 −0 appdatabase/migrations/sql/1674232431_add_balance_history.up.sql
+54 −54 appdatabase/migrationsprevnodecfg/bindata.go
+2 −1 eth-node/bridge/geth/waku.go
+3 −2 eth-node/bridge/geth/wakuv2.go
+2 −1 eth-node/types/waku.go
+1 −1 go.mod
+2 −2 go.sum
+3 −3 mailserver/migrations/bindata.go
+10 −2 mobile/status.go
+19 −5 multiaccounts/accounts/database_test.go
+2 −2 multiaccounts/database.go
+18 −0 multiaccounts/keypairs/database.go
+11 −11 multiaccounts/migrations/bindata.go
+5 −0 multiaccounts/settings/columns.go
+16 −0 multiaccounts/settings/database.go
+4 −4 multiaccounts/settings_notifications/database.go
+3 −1 nodecfg/node_config.go
+33 −55 protocol/activity_center_persistence.go
+3 −3 protocol/anonmetrics/migrations/migrations.go
+18 −0 protocol/communities_messenger_test.go
+5 −3 protocol/discord/types.go
+20 −20 protocol/encryption/migrations/migrations.go
+1 −1 protocol/messenger.go
+4 −0 protocol/messenger_activity_center.go
+32 −12 protocol/messenger_communities.go
+13 −1 protocol/messenger_contact_requests_test.go
+29 −16 protocol/messenger_contact_verification.go
+65 −17 protocol/messenger_contact_verification_test.go
+12 −4 protocol/messenger_contacts.go
+23 −19 protocol/messenger_handler.go
+1 −1 protocol/messenger_mailserver.go
+72 −72 protocol/migrations/migrations.go
+10 −7 protocol/persistence_test.go
+7 −7 protocol/pushnotificationclient/migrations/migrations.go
+5 −5 protocol/pushnotificationserver/migrations/migrations.go
+6 −6 protocol/transport/migrations/migrations.go
+2 −2 protocol/transport/transport.go
+6 −2 services/accounts/accounts.go
+27 −3 services/wallet/api.go
+350 −0 services/wallet/history/balance.go
+175 −0 services/wallet/history/balance_db.go
+328 −0 services/wallet/history/balance_db_test.go
+723 −0 services/wallet/history/balance_test.go
+447 −0 services/wallet/history/service.go
+216 −0 services/wallet/history/service_test.go
+5 −0 services/wallet/service.go
+12 −0 services/wallet/token/token.go
+0 −7 services/wallet/transfer/balance_cache.go
+0 −124 services/wallet/transfer/controller.go
+21 −21 static/bindata.go
+3 −3 t/bindata.go
+1 −0 telemetry/client.go
+11 −7 vendor/github.com/waku-org/go-waku/waku/v2/discv5/discover.go
+15 −7 vendor/github.com/waku-org/go-waku/waku/v2/node/keepalive.go
+20 −16 vendor/github.com/waku-org/go-waku/waku/v2/node/wakunode2.go
+15 −5 vendor/github.com/waku-org/go-waku/waku/v2/node/wakuoptions.go
+10 −4 vendor/github.com/waku-org/go-waku/waku/v2/protocol/peer_exchange/waku_peer_exchange.go
+4 −3 vendor/github.com/waku-org/go-waku/waku/v2/protocol/store/waku_store_client.go
+0 −2 vendor/github.com/waku-org/go-waku/waku/v2/protocol/store/waku_store_common.go
+1 −1 vendor/modules.txt
+3 −9 wakuv2/waku.go

0 comments on commit 128ac8d

Please sign in to comment.