feat(ActivityCenter): Move AC notifications counting to status-go
Close #8074
This commit is contained in:
parent
7ed5b0d0d6
commit
128ac8dbd8
|
@ -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)
|
||||
|
|
|
@ -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")
|
||||
|
||||
|
|
|
@ -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))
|
|
@ -43,19 +43,6 @@ 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
|
||||
|
@ -63,7 +50,6 @@ QtObject:
|
|||
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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
|
@ -186,4 +167,3 @@ QtObject:
|
|||
self.removeNotifications(@[notif.id])
|
||||
break
|
||||
self.addActivityNotificationItemToList(activityCenterNotification, false)
|
||||
self.unreadCountChanged()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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"
|
||||
|
@ -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] = @[]
|
||||
|
@ -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 != ""
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
|
|
@ -182,6 +182,9 @@ rpc(dismissActivityCenterNotifications, "wakuext"):
|
|||
rpc(unreadActivityCenterNotificationsCount, "wakuext"):
|
||||
discard
|
||||
|
||||
rpc(unreadAndAcceptedActivityCenterNotificationsCount, "wakuext"):
|
||||
discard
|
||||
|
||||
rpc(getBookmarks, "browsers"):
|
||||
discard
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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))
|
||||
|
||||
|
@ -37,9 +37,19 @@ 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
|
||||
}
|
||||
|
@ -47,6 +57,7 @@ Item {
|
|||
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
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 1a15533f62294a69685373305ac2aabf5b489ecb
|
||||
Subproject commit ee9f8edfcf66eb0df752489d8558edf4ce3bf5ae
|
Loading…
Reference in New Issue