feat(ActivityCenter): Move group logic to nim service layer
This commit is contained in:
parent
a70bbd448c
commit
7b250b20b8
|
@ -161,9 +161,12 @@ QtObject:
|
|||
|
||||
proc activityCenterReadTypeChanged*(self: View) {.signal.}
|
||||
|
||||
proc groupCountersChanged*(self: View) {.signal.}
|
||||
|
||||
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()
|
||||
|
@ -173,8 +176,6 @@ QtObject:
|
|||
write = setActivityCenterReadType
|
||||
notify = activityCenterReadTypeChanged
|
||||
|
||||
proc groupCountersChanged*(self: View) {.signal.}
|
||||
|
||||
proc getAdminCount*(self: View): int {.slot.} =
|
||||
return self.delegate.getAdminCount()
|
||||
|
||||
|
|
|
@ -10,7 +10,8 @@ type
|
|||
|
||||
const asyncActivityNotificationLoadTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
|
||||
let arg = decode[AsyncActivityNotificationLoadTaskArg](argEncoded)
|
||||
let activityNotificationsCallResult = backend.activityCenterNotificationsByGroup(newJString(arg.cursor), arg.limit, arg.group.int, arg.readType.int)
|
||||
let groupTypes = activityCenterNotificationTypesByGroup(arg.group)
|
||||
let activityNotificationsCallResult = backend.activityCenterNotificationsBy(newJString(arg.cursor), arg.limit, groupTypes, arg.readType.int, true)
|
||||
|
||||
let responseJson = %*{
|
||||
"activityNotifications": activityNotificationsCallResult.result
|
||||
|
|
|
@ -125,11 +125,37 @@ proc parseActivityCenterNotifications*(rpcResult: JsonNode): (string, seq[Activi
|
|||
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
|
||||
proc activityCenterNotificationTypesByGroup*(group: ActivityCenterGroup) : seq[int] =
|
||||
case group
|
||||
of ActivityCenterGroup.All:
|
||||
return @[
|
||||
ActivityCenterNotificationType.NewPrivateGroupChat.int,
|
||||
ActivityCenterNotificationType.Mention.int,
|
||||
ActivityCenterNotificationType.Reply.int,
|
||||
ActivityCenterNotificationType.ContactRequest.int,
|
||||
ActivityCenterNotificationType.CommunityInvitation.int,
|
||||
ActivityCenterNotificationType.CommunityRequest.int,
|
||||
ActivityCenterNotificationType.CommunityMembershipRequest.int,
|
||||
ActivityCenterNotificationType.CommunityKicked.int,
|
||||
ActivityCenterNotificationType.ContactVerification.int
|
||||
]
|
||||
of ActivityCenterGroup.Mentions:
|
||||
return @[ActivityCenterNotificationType.Mention.int]
|
||||
of ActivityCenterGroup.Replies:
|
||||
return @[ActivityCenterNotificationType.Reply.int]
|
||||
of ActivityCenterGroup.Membership:
|
||||
return @[
|
||||
ActivityCenterNotificationType.NewPrivateGroupChat.int,
|
||||
ActivityCenterNotificationType.CommunityInvitation.int,
|
||||
ActivityCenterNotificationType.CommunityRequest.int,
|
||||
ActivityCenterNotificationType.CommunityMembershipRequest.int,
|
||||
ActivityCenterNotificationType.CommunityKicked.int
|
||||
]
|
||||
of ActivityCenterGroup.Admin:
|
||||
return @[ActivityCenterNotificationType.CommunityMembershipRequest.int]
|
||||
of ActivityCenterGroup.ContactRequests:
|
||||
return @[ActivityCenterNotificationType.ContactRequest.int]
|
||||
of ActivityCenterGroup.IdentityVerification:
|
||||
return @[ActivityCenterNotificationType.ContactVerification.int]
|
||||
else:
|
||||
return @[]
|
||||
|
|
|
@ -80,10 +80,9 @@ QtObject:
|
|||
|
||||
proc handleNewNotificationsLoaded(self: Service, activityCenterNotifications: seq[ActivityCenterNotificationDto]) =
|
||||
# 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)
|
||||
let groupTypes = activityCenterNotificationTypesByGroup(self.activeGroup)
|
||||
let filteredNotifications = filter(activityCenterNotifications, proc(notification: ActivityCenterNotificationDto): bool =
|
||||
return (self.readType == ActivityCenterReadType.All or not notification.read) and groupTypes.contains(notification.notificationType.int)
|
||||
)
|
||||
|
||||
if (filteredNotifications.len > 0):
|
||||
|
@ -145,15 +144,21 @@ QtObject:
|
|||
else:
|
||||
cursorVal = newJString(self.cursor)
|
||||
|
||||
let callResult = backend.activityCenterNotificationsByGroup(cursorVal, DEFAULT_LIMIT, self.activeGroup.int, self.readType.int)
|
||||
try:
|
||||
let groupTypes = activityCenterNotificationTypesByGroup(self.activeGroup)
|
||||
let callResult = backend.activityCenterNotificationsBy(cursorVal, DEFAULT_LIMIT, groupTypes, self.readType.int, true)
|
||||
let activityCenterNotificationsTuple = parseActivityCenterNotifications(callResult.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 =
|
||||
try:
|
||||
let response = backend.activityCenterNotificationsByGroupCount(group.int)
|
||||
let groupTypes = activityCenterNotificationTypesByGroup(group)
|
||||
let response = backend.activityCenterNotificationsCountBy(groupTypes, self.readType.int, true)
|
||||
|
||||
if response.result.kind != JNull:
|
||||
return response.result.getInt
|
||||
|
|
|
@ -165,17 +165,17 @@ rpc(activityCenterNotifications, "wakuext"):
|
|||
cursorVal: JsonNode
|
||||
limit: int
|
||||
|
||||
rpc(activityCenterNotificationsByGroup, "wakuext"):
|
||||
rpc(activityCenterNotificationsBy, "wakuext"):
|
||||
cursorVal: JsonNode
|
||||
limit: int
|
||||
group: int
|
||||
activityTypes: seq[int]
|
||||
readType: int
|
||||
accepted: bool
|
||||
|
||||
rpc(activityCenterNotificationsByGroupCount, "wakuext"):
|
||||
group: int
|
||||
|
||||
rpc(activityCenterTypesByGroup, "wakuext"):
|
||||
group: int
|
||||
rpc(activityCenterNotificationsCountBy, "wakuext"):
|
||||
activityTypes: seq[int]
|
||||
readType: int
|
||||
accepted: bool
|
||||
|
||||
rpc(markAllActivityCenterNotificationsRead, "wakuext"):
|
||||
discard
|
||||
|
|
Loading…
Reference in New Issue