feat(ActivityCenter): Support status-go PR with endpoints refactor

This commit is contained in:
MishkaRogachev 2023-03-01 16:23:46 +04:00 committed by Mikhail Rogachev
parent 702d355e89
commit 38a9b4a7f1
11 changed files with 102 additions and 104 deletions

View File

@ -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)
@ -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()
@ -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)

View File

@ -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")

View File

@ -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)

View File

@ -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
@ -10,6 +10,7 @@ QtObject:
delegate: io_interface.AccessInterface
model: Model
modelVariant: QVariant
groupCounters: Table[ActivityCenterGroup, int]
proc delete*(self: View) =
self.QObject.delete
@ -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()
@ -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()
@ -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()

View File

@ -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

View File

@ -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
@ -137,17 +146,17 @@ 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]
@ -155,26 +164,42 @@ QtObject:
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
except Exception as e:
error "Error getting activity center notifications group count", msg = e.msg
proc getUnreadActivityCenterNotificationsCount*(self: Service): int =
try:
let response = backend.unreadActivityCenterNotificationsCount()
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 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 =
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:
let response = backend.hasUnseenActivityCenterNotifications()

View File

@ -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
@ -162,20 +172,10 @@ rpc(addAccountWatch, "accounts"):
emoji: string
rpc(activityCenterNotifications, "wakuext"):
cursorVal: JsonNode
limit: int
request: ActivityCenterNotificationsRequest
rpc(activityCenterNotificationsBy, "wakuext"):
cursorVal: JsonNode
limit: int
activityTypes: seq[int]
readType: int
accepted: bool
rpc(activityCenterNotificationsCountBy, "wakuext"):
activityTypes: seq[int]
readType: int
accepted: bool
rpc(activityCenterNotificationsCount, "wakuext"):
request: ActivityCenterCountRequest
rpc(markAllActivityCenterNotificationsRead, "wakuext"):
discard
@ -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

View File

@ -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
@ -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 } ]

View File

@ -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

View File

@ -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() {

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit 596660c1106a5d991784a1372ba69a9f1e9b1f7e
Subproject commit 224f7461e9dfe61e839d3e7e6d69b593619f2fc8