Skip to content

Commit

Permalink
feat(ActivityCenter): Support status-go PR with endpoints refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
MishkaRogachev committed Mar 3, 2023
1 parent 702d355 commit 38a9b4a
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 102 deletions.
9 changes: 6 additions & 3 deletions src/app/modules/main/activity_center/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ proc newController*(
proc delete*(self: Controller) =
discard

proc updateActivityGroupCounters*(self: Controller) =
let counters = self.activityCenterService.getActivityGroupCounters()
self.delegate.setActivityGroupCounters(counters)

proc init*(self: Controller) =
self.events.on(activity_center_service.SIGNAL_ACTIVITY_CENTER_NOTIFICATIONS_LOADED) do(e: Args):
let args = ActivityCenterNotificationsArgs(e)
Expand Down Expand Up @@ -70,7 +74,7 @@ proc init*(self: Controller) =
self.events.on(activity_center_service.SIGNAL_ACTIVITY_CENTER_NOTIFICATIONS_COUNT_MAY_HAVE_CHANGED) do(e: Args):
self.delegate.unreadActivityCenterNotificationsCountChanged()
self.delegate.hasUnseenActivityCenterNotificationsChanged()
self.delegate.groupCountersChanged()
self.updateActivityGroupCounters()

proc hasMoreToShow*(self: Controller): bool =
return self.activityCenterService.hasMoreToShow()
Expand Down Expand Up @@ -156,9 +160,8 @@ proc setActivityCenterReadType*(self: Controller, readType: ActivityCenterReadTy
self.activityCenterService.resetCursor()
let activityCenterNotifications = self.activityCenterService.getActivityCenterNotifications()
self.delegate.resetActivityCenterNotifications(activityCenterNotifications)
self.updateActivityGroupCounters()

proc getActivityCenterReadType*(self: Controller): ActivityCenterReadType =
return self.activityCenterService.getActivityCenterReadType()

proc getActivityGroupCounter*(self: Controller, group: ActivityCenterGroup): int =
return self.activityCenterService.getActivityGroupCounter(group)
20 changes: 1 addition & 19 deletions src/app/modules/main/activity_center/io_interface.nim
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,5 @@ method setActivityCenterReadType*(self: AccessInterface, readType: int) {.base.}
method getActivityCenterReadType*(self: AccessInterface): int {.base.} =
raise newException(ValueError, "No implementation available")

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

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

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

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

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

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

method getMembershipCount*(self: AccessInterface): int {.base.} =
method setActivityGroupCounters*(self: AccessInterface, counters: Table[ActivityCenterGroup, int]) {.base.} =
raise newException(ValueError, "No implementation available")
22 changes: 2 additions & 20 deletions src/app/modules/main/activity_center/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -303,23 +303,5 @@ method setActivityCenterReadType*(self: Module, readType: int) =
method getActivityCenterReadType*(self: Module): int =
return self.controller.getActivityCenterReadType().int

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

method getAdminCount*(self: Module): int =
return self.controller.getActivityGroupCounter(ActivityCenterGroup.Admin)

method getMentionsCount*(self: Module): int =
return self.controller.getActivityGroupCounter(ActivityCenterGroup.Mentions)

method getRepliesCount*(self: Module): int =
return self.controller.getActivityGroupCounter(ActivityCenterGroup.Replies)

method getContactRequestsCount*(self: Module): int =
return self.controller.getActivityGroupCounter(ActivityCenterGroup.ContactRequests)

method getIdentityRequestsCount*(self: Module): int =
return self.controller.getActivityGroupCounter(ActivityCenterGroup.IdentityVerification)

method getMembershipCount*(self: Module): int =
return self.controller.getActivityGroupCounter(ActivityCenterGroup.Membership)
method setActivityGroupCounters*(self: Module, counters: Table[ActivityCenterGroup, int]) =
self.view.setActivityGroupCounters(counters)
27 changes: 16 additions & 11 deletions src/app/modules/main/activity_center/view.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NimQml, json, strutils, json_serialization, sequtils, strformat
import NimQml, json, strutils, json_serialization, sequtils, strformat, std/tables
import ../../../../app_service/service/activity_center/service as activity_center_service

import ./model
Expand All @@ -10,6 +10,7 @@ QtObject:
delegate: io_interface.AccessInterface
model: Model
modelVariant: QVariant
groupCounters: Table[ActivityCenterGroup, int]

proc delete*(self: View) =
self.QObject.delete
Expand All @@ -20,6 +21,7 @@ QtObject:
result.delegate = delegate
result.model = newModel()
result.modelVariant = newQVariant(result.model)
result.groupCounters = initTable[ActivityCenterGroup, int]()

proc load*(self: View) =
self.delegate.viewDidLoad()
Expand Down Expand Up @@ -166,7 +168,6 @@ QtObject:
proc setActivityCenterReadType*(self: View, readType: int) {.slot.} =
self.delegate.setActivityCenterReadType(readType)
self.activityCenterReadTypeChanged()
self.groupCountersChanged()

proc getActivityCenterReadType*(self: View): int {.slot.} =
return self.delegate.getActivityCenterReadType()
Expand All @@ -177,43 +178,47 @@ QtObject:
notify = activityCenterReadTypeChanged

proc getAdminCount*(self: View): int {.slot.} =
return self.delegate.getAdminCount()
return self.groupCounters.getOrDefault(ActivityCenterGroup.Admin, 0)

QtProperty[int] adminCount:
read = getAdminCount
notify = groupCountersChanged

proc getMentionsCount*(self: View): int {.slot.} =
return self.delegate.getMentionsCount()
return self.groupCounters.getOrDefault(ActivityCenterGroup.Mentions, 0)

QtProperty[int] mentionsCount:
read = getMentionsCount
notify = groupCountersChanged

proc getRepliesCount*(self: View): int {.slot.} =
return self.delegate.getRepliesCount()
return self.groupCounters.getOrDefault(ActivityCenterGroup.Replies, 0)

QtProperty[int] repliesCount:
read = getRepliesCount
notify = groupCountersChanged

proc getContactRequestsCount*(self: View): int {.slot.} =
return self.delegate.getContactRequestsCount()
return self.groupCounters.getOrDefault(ActivityCenterGroup.ContactRequests, 0)

QtProperty[int] contactRequestsCount:
read = getContactRequestsCount
notify = groupCountersChanged

proc getIdentityRequestsCount*(self: View): int {.slot.} =
return self.delegate.getIdentityRequestsCount()
proc getIdentityVerificationCount*(self: View): int {.slot.} =
return self.groupCounters.getOrDefault(ActivityCenterGroup.IdentityVerification, 0)

QtProperty[int] identityRequestsCount:
read = getIdentityRequestsCount
QtProperty[int] identityVerificationCount:
read = getIdentityVerificationCount
notify = groupCountersChanged

proc getMembershipCount*(self: View): int {.slot.} =
return self.delegate.getMembershipCount()
return self.groupCounters.getOrDefault(ActivityCenterGroup.Membership, 0)

QtProperty[int] membershipCount:
read = getMembershipCount
notify = groupCountersChanged

proc setActivityGroupCounters*(self: View, counters: Table[ActivityCenterGroup, int]) =
self.groupCounters = counters
self.groupCountersChanged()
11 changes: 9 additions & 2 deletions src/app_service/service/activity_center/async_tasks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@ type

const asyncActivityNotificationLoadTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
let arg = decode[AsyncActivityNotificationLoadTaskArg](argEncoded)
let groupTypes = activityCenterNotificationTypesByGroup(arg.group)
let activityNotificationsCallResult = backend.activityCenterNotificationsBy(newJString(arg.cursor), arg.limit, groupTypes, arg.readType.int, true)
let activityTypes = activityCenterNotificationTypesByGroup(arg.group)
let activityNotificationsCallResult = backend.activityCenterNotifications(
backend.ActivityCenterNotificationsRequest(
cursor: arg.cursor,
limit: arg.limit,
activityTypes: activityTypes,
readType: arg.readType.int
)
)

let responseJson = %*{
"activityNotifications": activityNotificationsCallResult.result
Expand Down
71 changes: 48 additions & 23 deletions src/app_service/service/activity_center/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ const SIGNAL_MARK_NOTIFICATIONS_AS_DISMISSED* = "markNotificationsAsDismissed"

const DEFAULT_LIMIT = 20

# NOTE: temporary disable Transactions and System and we don't count All group
const ACTIVITY_GROUPS = @[
ActivityCenterGroup.Mentions,
ActivityCenterGroup.Replies,
ActivityCenterGroup.Membership,
ActivityCenterGroup.Admin,
ActivityCenterGroup.ContactRequests,
ActivityCenterGroup.IdentityVerification
]

QtObject:
type Service* = ref object of QObject
Expand Down Expand Up @@ -137,43 +146,59 @@ QtObject:
self.threadpool.start(arg)

proc getActivityCenterNotifications*(self: Service): seq[ActivityCenterNotificationDto] =
var cursorVal: JsonNode

if self.cursor == "":
cursorVal = newJNull()
else:
cursorVal = newJString(self.cursor)

try:
let groupTypes = activityCenterNotificationTypesByGroup(self.activeGroup)
let callResult = backend.activityCenterNotificationsBy(cursorVal, DEFAULT_LIMIT, groupTypes, self.readType.int, true)
let activityCenterNotificationsTuple = parseActivityCenterNotifications(callResult.result)
let activityTypes = activityCenterNotificationTypesByGroup(self.activeGroup)
let response = backend.activityCenterNotifications(
backend.ActivityCenterNotificationsRequest(
cursor: self.cursor,
limit: DEFAULT_LIMIT,
activityTypes: activityTypes,
readType: self.readType.int
)
)
let activityCenterNotificationsTuple = parseActivityCenterNotifications(response.result)

self.cursor = activityCenterNotificationsTuple[0];
result = activityCenterNotificationsTuple[1]

except Exception as e:
error "Error getting activity center notifications", msg = e.msg

proc getActivityGroupCounter*(self: Service, group: ActivityCenterGroup): int =
proc getActivityCenterNotificationsCounters(self: Service, activityTypes: seq[int], readType: ActivityCenterReadType): Table[int, int] =
try:
let groupTypes = activityCenterNotificationTypesByGroup(group)
let response = backend.activityCenterNotificationsCountBy(groupTypes, self.readType.int, true)

let response = backend.activityCenterNotificationsCount(
backend.ActivityCenterCountRequest(
activityTypes: activityTypes,
readType: readType.int,
)
)
var counters = initTable[int, int]()
if response.result.kind != JNull:
return response.result.getInt
for activityType in activityTypes:
if response.result.contains($activityType):
counters.add(activityType, response.result[$activityType].getInt)
return counters
except Exception as e:
error "Error getting activity center notifications group count", msg = e.msg
error "Error getting unread activity center notifications count", msg = e.msg

proc getActivityGroupCounters*(self: Service): Table[ActivityCenterGroup, int] =
let allActivityTypes = activityCenterNotificationTypesByGroup(ActivityCenterGroup.All)
let counters = self.getActivityCenterNotificationsCounters(allActivityTypes, self.readType)
var groupCounters = initTable[ActivityCenterGroup, int]()
for group in ACTIVITY_GROUPS:
var groupTotal = 0
for activityType in activityCenterNotificationTypesByGroup(group):
groupTotal = groupTotal + counters.getOrDefault(activityType, 0)
groupCounters.add(group, groupTotal)
return groupCounters

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 notifications count", msg = e.msg
let activityTypes = activityCenterNotificationTypesByGroup(ActivityCenterGroup.All)
let counters = self.getActivityCenterNotificationsCounters(activityTypes, ActivityCenterReadType.Unread)
var total = 0
for activityType in activityTypes:
total = total + counters.getOrDefault(activityType, 0)
return total

proc getHasUnseenActivityCenterNotifications*(self: Service): bool =
try:
Expand Down
32 changes: 13 additions & 19 deletions src/backend/backend.nim
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ type
chainColor* {.serializedFieldName("chainColor").}: string
shortName* {.serializedFieldName("shortName").}: string

ActivityCenterNotificationsRequest* = ref object of RootObj
cursor* {.serializedFieldName("cursor").}: string
limit* {.serializedFieldName("limit").}: int
activityTypes* {.serializedFieldName("activityTypes").}: seq[int]
readType* {.serializedFieldName("readType").}: int

ActivityCenterCountRequest* = ref object of RootObj
activityTypes* {.serializedFieldName("activityTypes").}: seq[int]
readType* {.serializedFieldName("readType").}: int

rpc(clientVersion, "web3"):
discard

Expand Down Expand Up @@ -162,20 +172,10 @@ rpc(addAccountWatch, "accounts"):
emoji: string

rpc(activityCenterNotifications, "wakuext"):
cursorVal: JsonNode
limit: int

rpc(activityCenterNotificationsBy, "wakuext"):
cursorVal: JsonNode
limit: int
activityTypes: seq[int]
readType: int
accepted: bool
request: ActivityCenterNotificationsRequest

rpc(activityCenterNotificationsCountBy, "wakuext"):
activityTypes: seq[int]
readType: int
accepted: bool
rpc(activityCenterNotificationsCount, "wakuext"):
request: ActivityCenterCountRequest

rpc(markAllActivityCenterNotificationsRead, "wakuext"):
discard
Expand All @@ -192,18 +192,12 @@ rpc(acceptActivityCenterNotifications, "wakuext"):
rpc(dismissActivityCenterNotifications, "wakuext"):
ids: seq[string]

rpc(unreadActivityCenterNotificationsCount, "wakuext"):
discard

rpc(hasUnseenActivityCenterNotifications, "wakuext"):
discard

rpc(markAsSeenActivityCenterNotifications, "wakuext"):
discard

rpc(unreadAndAcceptedActivityCenterNotificationsCount, "wakuext"):
discard

rpc(getBookmarks, "browsers"):
discard

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Item {
property bool hasMentions: false
property bool hasReplies: false
property bool hasContactRequests: false
property bool hasIdentityRequests: false
property bool hasIdentityVerification: false
property bool hasMembership: false

property bool hideReadNotifications: false
Expand Down Expand Up @@ -54,7 +54,7 @@ Item {
{ text: qsTr("Mentions"), group: ActivityCenterStore.ActivityCenterGroup.Mentions, visible: true, enabled: root.hasMentions },
{ text: qsTr("Replies"), group: ActivityCenterStore.ActivityCenterGroup.Replies, visible: true, enabled: root.hasReplies },
{ text: qsTr("Contact requests"), group: ActivityCenterStore.ActivityCenterGroup.ContactRequests, visible: true, enabled: root.hasContactRequests },
{ text: qsTr("Identity verification"), group: ActivityCenterStore.ActivityCenterGroup.IdentityVerification, visible: true, enabled: root.hasIdentityRequests },
{ text: qsTr("Identity verification"), group: ActivityCenterStore.ActivityCenterGroup.IdentityVerification, visible: true, enabled: root.hasIdentityVerification },
{ text: qsTr("Transactions"), group: ActivityCenterStore.ActivityCenterGroup.Transactions, visible: false, enabled: true },
{ text: qsTr("Membership"), group: ActivityCenterStore.ActivityCenterGroup.Membership, visible: true, enabled: root.hasMembership },
{ text: qsTr("System"), group: ActivityCenterStore.ActivityCenterGroup.System, visible: false, enabled: true } ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Popup {
hasReplies: activityCenterStore.repliesCount > 0
hasMentions: activityCenterStore.mentionsCount > 0
hasContactRequests: activityCenterStore.contactRequestsCount > 0
hasIdentityRequests: activityCenterStore.identityRequestsCount > 0
hasIdentityVerification: activityCenterStore.identityVerificationCount > 0
hasMembership: activityCenterStore.membershipCount > 0
hideReadNotifications: activityCenterStore.activityCenterReadType === ActivityCenterStore.ActivityCenterReadType.Unread
activeGroup: activityCenterStore.activeNotificationGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ QtObject {
readonly property int mentionsCount: activityCenterModuleInst.mentionsCount
readonly property int repliesCount: activityCenterModuleInst.repliesCount
readonly property int contactRequestsCount: activityCenterModuleInst.contactRequestsCount
readonly property int identityRequestsCount: activityCenterModuleInst.identityRequestsCount
readonly property int identityVerificationCount: activityCenterModuleInst.identityVerificationCount
readonly property int membershipCount: activityCenterModuleInst.membershipCount

function markAllActivityCenterNotificationsRead() {
Expand Down

0 comments on commit 38a9b4a

Please sign in to comment.