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 activityCenterReadTypeChanged*(self: View) {.signal.}
|
||||||
|
|
||||||
|
proc groupCountersChanged*(self: View) {.signal.}
|
||||||
|
|
||||||
proc setActivityCenterReadType*(self: View, readType: int) {.slot.} =
|
proc setActivityCenterReadType*(self: View, readType: int) {.slot.} =
|
||||||
self.delegate.setActivityCenterReadType(readType)
|
self.delegate.setActivityCenterReadType(readType)
|
||||||
self.activityCenterReadTypeChanged()
|
self.activityCenterReadTypeChanged()
|
||||||
|
self.groupCountersChanged()
|
||||||
|
|
||||||
proc getActivityCenterReadType*(self: View): int {.slot.} =
|
proc getActivityCenterReadType*(self: View): int {.slot.} =
|
||||||
return self.delegate.getActivityCenterReadType()
|
return self.delegate.getActivityCenterReadType()
|
||||||
|
@ -173,8 +176,6 @@ QtObject:
|
||||||
write = setActivityCenterReadType
|
write = setActivityCenterReadType
|
||||||
notify = activityCenterReadTypeChanged
|
notify = activityCenterReadTypeChanged
|
||||||
|
|
||||||
proc groupCountersChanged*(self: View) {.signal.}
|
|
||||||
|
|
||||||
proc getAdminCount*(self: View): int {.slot.} =
|
proc getAdminCount*(self: View): int {.slot.} =
|
||||||
return self.delegate.getAdminCount()
|
return self.delegate.getAdminCount()
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,8 @@ type
|
||||||
|
|
||||||
const asyncActivityNotificationLoadTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
|
const asyncActivityNotificationLoadTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
|
||||||
let arg = decode[AsyncActivityNotificationLoadTaskArg](argEncoded)
|
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 = %*{
|
let responseJson = %*{
|
||||||
"activityNotifications": activityNotificationsCallResult.result
|
"activityNotifications": activityNotificationsCallResult.result
|
||||||
|
|
|
@ -125,11 +125,37 @@ proc parseActivityCenterNotifications*(rpcResult: JsonNode): (string, seq[Activi
|
||||||
notifs.add(jsonMsg.toActivityCenterNotificationDto())
|
notifs.add(jsonMsg.toActivityCenterNotificationDto())
|
||||||
return (rpcResult{"cursor"}.getStr, notifs)
|
return (rpcResult{"cursor"}.getStr, notifs)
|
||||||
|
|
||||||
proc toActivityCenterNotificationTypeList*(rpcResult: JsonNode): seq[ActivityCenterNotificationType] =
|
proc activityCenterNotificationTypesByGroup*(group: ActivityCenterGroup) : seq[int] =
|
||||||
var types: seq[ActivityCenterNotificationType] = @[]
|
case group
|
||||||
for jsonObj in rpcResult:
|
of ActivityCenterGroup.All:
|
||||||
var notificationTypeInt = jsonObj.getInt()
|
return @[
|
||||||
if notificationTypeInt >= ord(low(ActivityCenterNotificationType)) and
|
ActivityCenterNotificationType.NewPrivateGroupChat.int,
|
||||||
notificationTypeInt <= ord(high(ActivityCenterNotificationType)):
|
ActivityCenterNotificationType.Mention.int,
|
||||||
types.add(ActivityCenterNotificationType(notificationTypeInt))
|
ActivityCenterNotificationType.Reply.int,
|
||||||
return types
|
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]) =
|
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
|
# 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
|
let groupTypes = activityCenterNotificationTypesByGroup(self.activeGroup)
|
||||||
var groupTypes = toActivityCenterNotificationTypeList(response.result)
|
let filteredNotifications = filter(activityCenterNotifications, proc(notification: ActivityCenterNotificationDto): bool =
|
||||||
var filteredNotifications = filter(activityCenterNotifications, proc(notification: ActivityCenterNotificationDto): bool =
|
return (self.readType == ActivityCenterReadType.All or not notification.read) and groupTypes.contains(notification.notificationType.int)
|
||||||
return (self.readType == ActivityCenterReadType.All or not notification.read) and groupTypes.contains(notification.notificationType)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if (filteredNotifications.len > 0):
|
if (filteredNotifications.len > 0):
|
||||||
|
@ -145,15 +144,21 @@ QtObject:
|
||||||
else:
|
else:
|
||||||
cursorVal = newJString(self.cursor)
|
cursorVal = newJString(self.cursor)
|
||||||
|
|
||||||
let callResult = backend.activityCenterNotificationsByGroup(cursorVal, DEFAULT_LIMIT, self.activeGroup.int, self.readType.int)
|
try:
|
||||||
let activityCenterNotificationsTuple = parseActivityCenterNotifications(callResult.result)
|
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];
|
self.cursor = activityCenterNotificationsTuple[0];
|
||||||
result = activityCenterNotificationsTuple[1]
|
result = activityCenterNotificationsTuple[1]
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
error "Error getting activity center notifications", msg = e.msg
|
||||||
|
|
||||||
proc getActivityGroupCounter*(self: Service, group: ActivityCenterGroup): int =
|
proc getActivityGroupCounter*(self: Service, group: ActivityCenterGroup): int =
|
||||||
try:
|
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:
|
if response.result.kind != JNull:
|
||||||
return response.result.getInt
|
return response.result.getInt
|
||||||
|
|
|
@ -165,17 +165,17 @@ rpc(activityCenterNotifications, "wakuext"):
|
||||||
cursorVal: JsonNode
|
cursorVal: JsonNode
|
||||||
limit: int
|
limit: int
|
||||||
|
|
||||||
rpc(activityCenterNotificationsByGroup, "wakuext"):
|
rpc(activityCenterNotificationsBy, "wakuext"):
|
||||||
cursorVal: JsonNode
|
cursorVal: JsonNode
|
||||||
limit: int
|
limit: int
|
||||||
group: int
|
activityTypes: seq[int]
|
||||||
readType: int
|
readType: int
|
||||||
|
accepted: bool
|
||||||
|
|
||||||
rpc(activityCenterNotificationsByGroupCount, "wakuext"):
|
rpc(activityCenterNotificationsCountBy, "wakuext"):
|
||||||
group: int
|
activityTypes: seq[int]
|
||||||
|
readType: int
|
||||||
rpc(activityCenterTypesByGroup, "wakuext"):
|
accepted: bool
|
||||||
group: int
|
|
||||||
|
|
||||||
rpc(markAllActivityCenterNotificationsRead, "wakuext"):
|
rpc(markAllActivityCenterNotificationsRead, "wakuext"):
|
||||||
discard
|
discard
|
||||||
|
|
Loading…
Reference in New Issue