feat(ActivityCenter): Switch on backend filtering for the AC notifications
This commit is contained in:
parent
0529ea4be5
commit
c5a32ff8cb
|
@ -44,7 +44,7 @@ proc delete*(self: Controller) =
|
|||
proc init*(self: Controller) =
|
||||
self.events.on(activity_center_service.SIGNAL_ACTIVITY_CENTER_NOTIFICATIONS_LOADED) do(e: Args):
|
||||
let args = ActivityCenterNotificationsArgs(e)
|
||||
self.delegate.addActivityCenterNotification(args.activityCenterNotifications)
|
||||
self.delegate.addActivityCenterNotifications(args.activityCenterNotifications)
|
||||
|
||||
self.events.on(activity_center_service.SIGNAL_MARK_NOTIFICATIONS_AS_ACCEPTED) do(e: Args):
|
||||
var evArgs = MarkAsAcceptedNotificationProperties(e)
|
||||
|
@ -143,6 +143,18 @@ proc getMessageById*(self: Controller, chatId, messageId: string): MessageDto =
|
|||
|
||||
proc setActiveNotificationGroup*(self: Controller, group: int) =
|
||||
self.activityCenterService.setActiveNotificationGroup(ActivityCenterGroup(group))
|
||||
self.activityCenterService.resetCursor()
|
||||
let activityCenterNotifications = self.activityCenterService.getActivityCenterNotifications()
|
||||
self.delegate.resetActivityCenterNotifications(activityCenterNotifications)
|
||||
|
||||
proc getActiveNotificationGroup*(self: Controller): int =
|
||||
return self.activityCenterService.getActiveNotificationGroup().int
|
||||
|
||||
proc setActivityCenterReadType*(self: Controller, readType: int) =
|
||||
self.activityCenterService.setActivityCenterReadType(ActivityCenterReadType(readType))
|
||||
self.activityCenterService.resetCursor()
|
||||
let activityCenterNotifications = self.activityCenterService.getActivityCenterNotifications()
|
||||
self.delegate.resetActivityCenterNotifications(activityCenterNotifications)
|
||||
|
||||
proc getActivityCenterReadType*(self: Controller): int =
|
||||
return self.activityCenterService.getActivityCenterReadType().int
|
||||
|
|
|
@ -66,10 +66,10 @@ method markActivityCenterNotificationUnread*(self: AccessInterface, notification
|
|||
method markAsSeenActivityCenterNotifications*(self: AccessInterface) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method pushActivityCenterNotifications*(self: AccessInterface, activityCenterNotifications: seq[ActivityCenterNotificationDto]) {.base.} =
|
||||
method addActivityCenterNotifications*(self: AccessInterface, activityCenterNotifications: seq[ActivityCenterNotificationDto]) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method addActivityCenterNotification*(self: AccessInterface, activityCenterNotifications: seq[ActivityCenterNotificationDto]) {.base.} =
|
||||
method resetActivityCenterNotifications*(self: AccessInterface, activityCenterNotifications: seq[ActivityCenterNotificationDto]) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method acceptActivityCenterNotifications*(self: AccessInterface, notificationIds: seq[string]): string {.base.} =
|
||||
|
@ -92,3 +92,9 @@ method setActiveNotificationGroup*(self: AccessInterface, group: int) {.base.} =
|
|||
|
||||
method getActiveNotificationGroup*(self: AccessInterface): int {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method setActivityCenterReadType*(self: AccessInterface, readType: int) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method getActivityCenterReadType*(self: AccessInterface): int {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
|
|
@ -181,7 +181,7 @@ method convertToItems*(
|
|||
|
||||
method fetchActivityCenterNotifications*(self: Module) =
|
||||
let activityCenterNotifications = self.controller.getActivityCenterNotifications()
|
||||
self.view.pushActivityCenterNotifications(self.convertToItems(activityCenterNotifications))
|
||||
self.view.addActivityCenterNotifications(self.convertToItems(activityCenterNotifications))
|
||||
|
||||
method markAllActivityCenterNotificationsRead*(self: Module): string =
|
||||
self.controller.markAllActivityCenterNotificationsRead()
|
||||
|
@ -212,17 +212,11 @@ method markActivityCenterNotificationReadDone*(self: Module, notificationIds: se
|
|||
method markAsSeenActivityCenterNotifications*(self: Module) =
|
||||
self.controller.markAsSeenActivityCenterNotifications()
|
||||
|
||||
method pushActivityCenterNotifications*(
|
||||
self: Module,
|
||||
activityCenterNotifications: seq[ActivityCenterNotificationDto]
|
||||
) =
|
||||
self.view.pushActivityCenterNotifications(self.convertToItems(activityCenterNotifications))
|
||||
method addActivityCenterNotifications*(self: Module, activityCenterNotifications: seq[ActivityCenterNotificationDto]) =
|
||||
self.view.addActivityCenterNotifications(self.convertToItems(activityCenterNotifications))
|
||||
|
||||
method addActivityCenterNotification*(
|
||||
self: Module,
|
||||
activityCenterNotifications: seq[ActivityCenterNotificationDto]
|
||||
) =
|
||||
self.view.addActivityCenterNotification(self.convertToItems(activityCenterNotifications))
|
||||
method resetActivityCenterNotifications*(self: Module, activityCenterNotifications: seq[ActivityCenterNotificationDto]) =
|
||||
self.view.resetActivityCenterNotifications(self.convertToItems(activityCenterNotifications))
|
||||
|
||||
method markActivityCenterNotificationUnread*(
|
||||
self: Module,
|
||||
|
@ -302,3 +296,9 @@ method setActiveNotificationGroup*(self: Module, group: int) =
|
|||
|
||||
method getActiveNotificationGroup*(self: Module): int =
|
||||
return self.controller.getActiveNotificationGroup()
|
||||
|
||||
method setActivityCenterReadType*(self: Module, readType: int) =
|
||||
self.controller.setActivityCenterReadType(readType)
|
||||
|
||||
method getActivityCenterReadType*(self: Module): int =
|
||||
return self.controller.getActivityCenterReadType()
|
||||
|
|
|
@ -60,10 +60,6 @@ QtObject:
|
|||
read = hasUnseenActivityCenterNotifications
|
||||
notify = hasUnseenActivityCenterNotificationsChanged
|
||||
|
||||
proc pushActivityCenterNotifications*(self:View, activityCenterNotifications: seq[Item]) =
|
||||
self.model.addActivityNotificationItemsToList(activityCenterNotifications)
|
||||
self.hasMoreToShowChanged()
|
||||
|
||||
proc loadMoreNotifications(self: View) {.slot.} =
|
||||
self.delegate.fetchActivityCenterNotifications()
|
||||
|
||||
|
@ -134,9 +130,12 @@ QtObject:
|
|||
proc dismissActivityCenterNotificationsDone*(self: View, notificationIds: seq[string]) =
|
||||
self.model.removeNotifications(notificationIds)
|
||||
|
||||
proc addActivityCenterNotification*(self: View, activityCenterNotifications: seq[Item]) =
|
||||
proc addActivityCenterNotifications*(self: View, activityCenterNotifications: seq[Item]) =
|
||||
self.model.addActivityNotificationItemsToList(activityCenterNotifications)
|
||||
|
||||
proc resetActivityCenterNotifications*(self: View, activityCenterNotifications: seq[Item]) =
|
||||
self.model.setNewData(activityCenterNotifications)
|
||||
|
||||
proc switchTo*(self: View, sectionId: string, chatId: string, messageId: string) {.slot.} =
|
||||
self.delegate.switchTo(sectionId, chatId, messageId)
|
||||
|
||||
|
@ -159,3 +158,17 @@ QtObject:
|
|||
read = getActiveNotificationGroup
|
||||
write = setActiveNotificationGroup
|
||||
notify = activeNotificationGroupChanged
|
||||
|
||||
proc activityCenterReadTypeChanged*(self: View) {.signal.}
|
||||
|
||||
proc setActivityCenterReadType*(self: View, readType: int) {.slot.} =
|
||||
self.delegate.setActivityCenterReadType(readType)
|
||||
self.activityCenterReadTypeChanged()
|
||||
|
||||
proc getActivityCenterReadType*(self: View): int {.slot.} =
|
||||
return self.delegate.getActivityCenterReadType()
|
||||
|
||||
QtProperty[int] activityCenterReadType:
|
||||
read = getActivityCenterReadType
|
||||
write = setActivityCenterReadType
|
||||
notify = activityCenterReadTypeChanged
|
||||
|
|
|
@ -5,10 +5,12 @@ type
|
|||
AsyncActivityNotificationLoadTaskArg = ref object of QObjectTaskArg
|
||||
cursor: string
|
||||
limit: int
|
||||
group: ActivityCenterGroup
|
||||
readType: ActivityCenterReadType
|
||||
|
||||
const asyncActivityNotificationLoadTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
|
||||
let arg = decode[AsyncActivityNotificationLoadTaskArg](argEncoded)
|
||||
let activityNotificationsCallResult = backend.activityCenterNotifications(newJString(arg.cursor), arg.limit)
|
||||
let activityNotificationsCallResult = backend.activityCenterNotificationsByGroup(newJString(arg.cursor), arg.limit, arg.group.int, arg.readType.int)
|
||||
|
||||
let responseJson = %*{
|
||||
"activityNotifications": activityNotificationsCallResult.result
|
||||
|
|
|
@ -31,6 +31,11 @@ type ActivityCenterGroup* {.pure.}= enum
|
|||
Transactions = 7,
|
||||
System = 8
|
||||
|
||||
type ActivityCenterReadType* {.pure.}= enum
|
||||
Read = 1,
|
||||
Unread = 2
|
||||
All = 3
|
||||
|
||||
type ActivityCenterMembershipStatus* {.pure.}= enum
|
||||
Idle = 0,
|
||||
Pending = 1,
|
||||
|
@ -79,14 +84,14 @@ proc toActivityCenterNotificationDto*(jsonObj: JsonNode): ActivityCenterNotifica
|
|||
result.membershipStatus = ActivityCenterMembershipStatus.Idle
|
||||
var membershipStatusInt: int
|
||||
if (jsonObj.getProp("membershipStatus", membershipStatusInt) and
|
||||
(membershipStatusInt >= ord(low(ActivityCenterMembershipStatus)) or
|
||||
(membershipStatusInt >= ord(low(ActivityCenterMembershipStatus)) and
|
||||
membershipStatusInt <= ord(high(ActivityCenterMembershipStatus)))):
|
||||
result.membershipStatus = ActivityCenterMembershipStatus(membershipStatusInt)
|
||||
|
||||
result.verificationStatus = VerificationStatus.Unverified
|
||||
var verificationStatusInt: int
|
||||
if (jsonObj.getProp("contactVerificationStatus", verificationStatusInt) and
|
||||
(verificationStatusInt >= ord(low(VerificationStatus)) or
|
||||
(verificationStatusInt >= ord(low(VerificationStatus)) and
|
||||
verificationStatusInt <= ord(high(VerificationStatus)))):
|
||||
result.verificationStatus = VerificationStatus(verificationStatusInt)
|
||||
|
||||
|
@ -95,7 +100,7 @@ proc toActivityCenterNotificationDto*(jsonObj: JsonNode): ActivityCenterNotifica
|
|||
result.notificationType = ActivityCenterNotificationType.NoType
|
||||
var notificationTypeInt: int
|
||||
if (jsonObj.getProp("type", notificationTypeInt) and
|
||||
(notificationTypeInt >= ord(low(ActivityCenterNotificationType)) or
|
||||
(notificationTypeInt >= ord(low(ActivityCenterNotificationType)) and
|
||||
notificationTypeInt <= ord(high(ActivityCenterNotificationType)))):
|
||||
result.notificationType = ActivityCenterNotificationType(notificationTypeInt)
|
||||
|
||||
|
@ -113,10 +118,18 @@ proc toActivityCenterNotificationDto*(jsonObj: JsonNode): ActivityCenterNotifica
|
|||
if jsonObj.contains("replyMessage") and jsonObj{"replyMessage"}.kind != JNull:
|
||||
result.replyMessage = jsonObj{"replyMessage"}.toMessageDto()
|
||||
|
||||
|
||||
proc parseActivityCenterNotifications*(rpcResult: JsonNode): (string, seq[ActivityCenterNotificationDto]) =
|
||||
var notifs: seq[ActivityCenterNotificationDto] = @[]
|
||||
if rpcResult{"notifications"}.kind != JNull:
|
||||
for jsonMsg in rpcResult["notifications"]:
|
||||
notifs.add(jsonMsg.toActivityCenterNotificationDto())
|
||||
return (rpcResult{"cursor"}.getStr, notifs)
|
||||
|
||||
proc toActivityCenterNotificationTypeList*(rpcResult: JsonNode): seq[ActivityCenterNotificationType] =
|
||||
var types: seq[ActivityCenterNotificationType] = @[]
|
||||
for jsonObj in rpcResult:
|
||||
var notificationTypeInt = jsonObj.getInt()
|
||||
if notificationTypeInt >= ord(low(ActivityCenterNotificationType)) and
|
||||
notificationTypeInt <= ord(high(ActivityCenterNotificationType)):
|
||||
types.add(ActivityCenterNotificationType(notificationTypeInt))
|
||||
return types
|
|
@ -58,6 +58,7 @@ QtObject:
|
|||
events: EventEmitter
|
||||
cursor*: string
|
||||
activeGroup: ActivityCenterGroup
|
||||
readType: ActivityCenterReadType
|
||||
|
||||
# Forward declaration
|
||||
proc asyncActivityNotificationLoad*(self: Service)
|
||||
|
@ -75,17 +76,20 @@ QtObject:
|
|||
result.threadpool = threadpool
|
||||
result.cursor = ""
|
||||
result.activeGroup = ActivityCenterGroup.All
|
||||
result.readType = ActivityCenterReadType.All
|
||||
|
||||
proc handleNewNotificationsLoaded(self: Service, activityCenterNotifications: seq[ActivityCenterNotificationDto]) =
|
||||
if (activityCenterNotifications.len < 1):
|
||||
return
|
||||
|
||||
# if (self.activeGroup == ActivityCenterGroup.All ||
|
||||
# backend. )
|
||||
# For now status-go notify about every notification update regardless active group so we need filter manulay on the desktop side
|
||||
let response = backend.activityCenterTypesByGroup(self.activeGroup.int) # NOTE: no error for trivial call
|
||||
var groupTypes = toActivityCenterNotificationTypeList(response.result)
|
||||
var filteredNotifications = filter(activityCenterNotifications, proc(notification: ActivityCenterNotificationDto): bool =
|
||||
return (self.readType == ActivityCenterReadType.All or not notification.read) and groupTypes.contains(notification.notificationType)
|
||||
)
|
||||
|
||||
if (filteredNotifications.len > 0):
|
||||
self.events.emit(
|
||||
SIGNAL_ACTIVITY_CENTER_NOTIFICATIONS_LOADED,
|
||||
ActivityCenterNotificationsArgs(activityCenterNotifications: activityCenterNotifications)
|
||||
ActivityCenterNotificationsArgs(activityCenterNotifications: filteredNotifications)
|
||||
)
|
||||
self.events.emit(SIGNAL_ACTIVITY_CENTER_NOTIFICATIONS_COUNT_MAY_HAVE_CHANGED, Args())
|
||||
|
||||
|
@ -103,12 +107,20 @@ QtObject:
|
|||
self.handleNewNotificationsLoaded(activityCenterNotifications)
|
||||
|
||||
proc setActiveNotificationGroup*(self: Service, group: ActivityCenterGroup) =
|
||||
echo "---------------------------------- setActiveNotificationGroup >", group
|
||||
self.activeGroup = group
|
||||
|
||||
proc getActiveNotificationGroup*(self: Service): ActivityCenterGroup =
|
||||
return self.activeGroup
|
||||
|
||||
proc setActivityCenterReadType*(self: Service, readType: ActivityCenterReadType) =
|
||||
self.readType = readType
|
||||
|
||||
proc getActivityCenterReadType*(self: Service): ActivityCenterReadType =
|
||||
return self.readType
|
||||
|
||||
proc resetCursor*(self: Service) =
|
||||
self.cursor = ""
|
||||
|
||||
proc hasMoreToShow*(self: Service): bool =
|
||||
return self.cursor != ""
|
||||
|
||||
|
@ -117,8 +129,10 @@ QtObject:
|
|||
tptr: cast[ByteAddress](asyncActivityNotificationLoadTask),
|
||||
vptr: cast[ByteAddress](self.vptr),
|
||||
slot: "asyncActivityNotificationLoaded",
|
||||
cursor: "",
|
||||
limit: DEFAULT_LIMIT
|
||||
cursor: self.cursor,
|
||||
limit: DEFAULT_LIMIT,
|
||||
group: self.activeGroup,
|
||||
readType: self.readType
|
||||
)
|
||||
self.threadpool.start(arg)
|
||||
|
||||
|
@ -130,7 +144,7 @@ QtObject:
|
|||
else:
|
||||
cursorVal = newJString(self.cursor)
|
||||
|
||||
let callResult = backend.activityCenterNotifications(cursorVal, DEFAULT_LIMIT)
|
||||
let callResult = backend.activityCenterNotificationsByGroup(cursorVal, DEFAULT_LIMIT, self.activeGroup.int, self.readType.int)
|
||||
let activityCenterNotificationsTuple = parseActivityCenterNotifications(callResult.result)
|
||||
|
||||
self.cursor = activityCenterNotificationsTuple[0];
|
||||
|
|
|
@ -165,6 +165,15 @@ rpc(activityCenterNotifications, "wakuext"):
|
|||
cursorVal: JsonNode
|
||||
limit: int
|
||||
|
||||
rpc(activityCenterNotificationsByGroup, "wakuext"):
|
||||
cursorVal: JsonNode
|
||||
limit: int
|
||||
group: int
|
||||
readType: int
|
||||
|
||||
rpc(activityCenterTypesByGroup, "wakuext"):
|
||||
group: int
|
||||
|
||||
rpc(markAllActivityCenterNotificationsRead, "wakuext"):
|
||||
discard
|
||||
|
||||
|
|
|
@ -29,8 +29,6 @@ Popup {
|
|||
property ActivityCenterStore activityCenterStore
|
||||
property var store
|
||||
|
||||
readonly property int unreadNotificationsCount: root.activityCenterStore.unreadNotificationsCount
|
||||
|
||||
onOpened: {
|
||||
Global.popupOpened = true
|
||||
}
|
||||
|
@ -65,18 +63,20 @@ Popup {
|
|||
ActivityCenterPopupTopBarPanel {
|
||||
id: activityCenterTopBar
|
||||
width: parent.width
|
||||
unreadNotificationsCount: root.unreadNotificationsCount
|
||||
unreadNotificationsCount: activityCenterStore.unreadNotificationsCount
|
||||
hasAdmin: root.adminCount > 0
|
||||
hasReplies: root.repliesCount > 0
|
||||
hasMentions: root.mentionsCount > 0
|
||||
hasContactRequests: root.contactRequestsCount > 0
|
||||
hasIdentityRequests: root.identityRequestsCount > 0
|
||||
hasMembership: root.membershipCount > 0
|
||||
hideReadNotifications: activityCenterStore.hideReadNotifications
|
||||
hideReadNotifications: activityCenterStore.activityCenterReadType === Constants.ActivityCenterReadType.Unread
|
||||
activeGroup: activityCenterStore.activeNotificationGroup
|
||||
onGroupTriggered: activityCenterStore.setActiveNotificationGroup(group)
|
||||
onMarkAllReadClicked: root.activityCenterStore.markAllActivityCenterNotificationsRead()
|
||||
onShowHideReadNotifications: activityCenterStore.hideReadNotifications = hideReadNotifications
|
||||
onShowHideReadNotifications: activityCenterStore.setActivityCenterReadType(hideReadNotifications ?
|
||||
Constants.ActivityCenterReadType.Unread :
|
||||
Constants.ActivityCenterReadType.All)
|
||||
}
|
||||
|
||||
StatusListView {
|
||||
|
|
|
@ -5,13 +5,12 @@ import shared 1.0
|
|||
QtObject {
|
||||
id: root
|
||||
|
||||
property bool hideReadNotifications: false
|
||||
|
||||
readonly property var activityCenterModuleInst: activityCenterModule
|
||||
readonly property var activityCenterNotifications: activityCenterModuleInst.activityNotificationsModel
|
||||
readonly property int unreadNotificationsCount: activityCenterModuleInst.unreadActivityCenterNotificationsCount
|
||||
readonly property bool hasUnseenNotifications: activityCenterModuleInst.hasUnseenActivityCenterNotifications
|
||||
readonly property int activeNotificationGroup: activityCenterModuleInst.activeNotificationGroup
|
||||
readonly property int activityCenterReadType: activityCenterModuleInst.activityCenterReadType
|
||||
|
||||
function markAllActivityCenterNotificationsRead() {
|
||||
root.activityCenterModuleInst.markAllActivityCenterNotificationsRead()
|
||||
|
@ -40,4 +39,8 @@ QtObject {
|
|||
function setActiveNotificationGroup(group) {
|
||||
root.activityCenterModuleInst.setActiveNotificationGroup(group)
|
||||
}
|
||||
|
||||
function setActivityCenterReadType(readType) {
|
||||
root.activityCenterModuleInst.setActivityCenterReadType(readType)
|
||||
}
|
||||
}
|
|
@ -639,6 +639,12 @@ QtObject {
|
|||
ContactVerification = 10
|
||||
}
|
||||
|
||||
enum ActivityCenterReadType {
|
||||
Read = 1,
|
||||
Unread = 2,
|
||||
All = 3
|
||||
}
|
||||
|
||||
readonly property int activityCenterMembershipStatusPending: 1
|
||||
readonly property int activityCenterMembershipStatusAccepted: 2
|
||||
readonly property int activityCenterMembershipStatusDeclined: 3
|
||||
|
|
Loading…
Reference in New Issue