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) = proc delete*(self: Controller) =
discard discard
proc updateActivityGroupCounters*(self: Controller) =
let counters = self.activityCenterService.getActivityGroupCounters()
self.delegate.setActivityGroupCounters(counters)
proc init*(self: Controller) = proc init*(self: Controller) =
self.events.on(activity_center_service.SIGNAL_ACTIVITY_CENTER_NOTIFICATIONS_LOADED) do(e: Args): self.events.on(activity_center_service.SIGNAL_ACTIVITY_CENTER_NOTIFICATIONS_LOADED) do(e: Args):
let args = ActivityCenterNotificationsArgs(e) 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.events.on(activity_center_service.SIGNAL_ACTIVITY_CENTER_NOTIFICATIONS_COUNT_MAY_HAVE_CHANGED) do(e: Args):
self.delegate.unreadActivityCenterNotificationsCountChanged() self.delegate.unreadActivityCenterNotificationsCountChanged()
self.delegate.hasUnseenActivityCenterNotificationsChanged() self.delegate.hasUnseenActivityCenterNotificationsChanged()
self.delegate.groupCountersChanged() self.updateActivityGroupCounters()
proc hasMoreToShow*(self: Controller): bool = proc hasMoreToShow*(self: Controller): bool =
return self.activityCenterService.hasMoreToShow() return self.activityCenterService.hasMoreToShow()
@ -156,9 +160,8 @@ proc setActivityCenterReadType*(self: Controller, readType: ActivityCenterReadTy
self.activityCenterService.resetCursor() self.activityCenterService.resetCursor()
let activityCenterNotifications = self.activityCenterService.getActivityCenterNotifications() let activityCenterNotifications = self.activityCenterService.getActivityCenterNotifications()
self.delegate.resetActivityCenterNotifications(activityCenterNotifications) self.delegate.resetActivityCenterNotifications(activityCenterNotifications)
self.updateActivityGroupCounters()
proc getActivityCenterReadType*(self: Controller): ActivityCenterReadType = proc getActivityCenterReadType*(self: Controller): ActivityCenterReadType =
return self.activityCenterService.getActivityCenterReadType() 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.} = method getActivityCenterReadType*(self: AccessInterface): int {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method groupCountersChanged*(self: AccessInterface) {.base.} = method setActivityGroupCounters*(self: AccessInterface, counters: Table[ActivityCenterGroup, int]) {.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.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")

View File

@ -303,23 +303,5 @@ method setActivityCenterReadType*(self: Module, readType: int) =
method getActivityCenterReadType*(self: Module): int = method getActivityCenterReadType*(self: Module): int =
return self.controller.getActivityCenterReadType().int return self.controller.getActivityCenterReadType().int
method groupCountersChanged*(self: Module) = method setActivityGroupCounters*(self: Module, counters: Table[ActivityCenterGroup, int]) =
self.view.groupCountersChanged() self.view.setActivityGroupCounters(counters)
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)

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 ../../../../app_service/service/activity_center/service as activity_center_service
import ./model import ./model
@ -10,6 +10,7 @@ QtObject:
delegate: io_interface.AccessInterface delegate: io_interface.AccessInterface
model: Model model: Model
modelVariant: QVariant modelVariant: QVariant
groupCounters: Table[ActivityCenterGroup, int]
proc delete*(self: View) = proc delete*(self: View) =
self.QObject.delete self.QObject.delete
@ -20,6 +21,7 @@ QtObject:
result.delegate = delegate result.delegate = delegate
result.model = newModel() result.model = newModel()
result.modelVariant = newQVariant(result.model) result.modelVariant = newQVariant(result.model)
result.groupCounters = initTable[ActivityCenterGroup, int]()
proc load*(self: View) = proc load*(self: View) =
self.delegate.viewDidLoad() self.delegate.viewDidLoad()
@ -166,7 +168,6 @@ QtObject:
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()
@ -177,43 +178,47 @@ QtObject:
notify = activityCenterReadTypeChanged notify = activityCenterReadTypeChanged
proc getAdminCount*(self: View): int {.slot.} = proc getAdminCount*(self: View): int {.slot.} =
return self.delegate.getAdminCount() return self.groupCounters.getOrDefault(ActivityCenterGroup.Admin, 0)
QtProperty[int] adminCount: QtProperty[int] adminCount:
read = getAdminCount read = getAdminCount
notify = groupCountersChanged notify = groupCountersChanged
proc getMentionsCount*(self: View): int {.slot.} = proc getMentionsCount*(self: View): int {.slot.} =
return self.delegate.getMentionsCount() return self.groupCounters.getOrDefault(ActivityCenterGroup.Mentions, 0)
QtProperty[int] mentionsCount: QtProperty[int] mentionsCount:
read = getMentionsCount read = getMentionsCount
notify = groupCountersChanged notify = groupCountersChanged
proc getRepliesCount*(self: View): int {.slot.} = proc getRepliesCount*(self: View): int {.slot.} =
return self.delegate.getRepliesCount() return self.groupCounters.getOrDefault(ActivityCenterGroup.Replies, 0)
QtProperty[int] repliesCount: QtProperty[int] repliesCount:
read = getRepliesCount read = getRepliesCount
notify = groupCountersChanged notify = groupCountersChanged
proc getContactRequestsCount*(self: View): int {.slot.} = proc getContactRequestsCount*(self: View): int {.slot.} =
return self.delegate.getContactRequestsCount() return self.groupCounters.getOrDefault(ActivityCenterGroup.ContactRequests, 0)
QtProperty[int] contactRequestsCount: QtProperty[int] contactRequestsCount:
read = getContactRequestsCount read = getContactRequestsCount
notify = groupCountersChanged notify = groupCountersChanged
proc getIdentityRequestsCount*(self: View): int {.slot.} = proc getIdentityVerificationCount*(self: View): int {.slot.} =
return self.delegate.getIdentityRequestsCount() return self.groupCounters.getOrDefault(ActivityCenterGroup.IdentityVerification, 0)
QtProperty[int] identityRequestsCount: QtProperty[int] identityVerificationCount:
read = getIdentityRequestsCount read = getIdentityVerificationCount
notify = groupCountersChanged notify = groupCountersChanged
proc getMembershipCount*(self: View): int {.slot.} = proc getMembershipCount*(self: View): int {.slot.} =
return self.delegate.getMembershipCount() return self.groupCounters.getOrDefault(ActivityCenterGroup.Membership, 0)
QtProperty[int] membershipCount: QtProperty[int] membershipCount:
read = getMembershipCount read = getMembershipCount
notify = groupCountersChanged 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.} = const asyncActivityNotificationLoadTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
let arg = decode[AsyncActivityNotificationLoadTaskArg](argEncoded) let arg = decode[AsyncActivityNotificationLoadTaskArg](argEncoded)
let groupTypes = activityCenterNotificationTypesByGroup(arg.group) let activityTypes = activityCenterNotificationTypesByGroup(arg.group)
let activityNotificationsCallResult = backend.activityCenterNotificationsBy(newJString(arg.cursor), arg.limit, groupTypes, arg.readType.int, true) let activityNotificationsCallResult = backend.activityCenterNotifications(
backend.ActivityCenterNotificationsRequest(
cursor: arg.cursor,
limit: arg.limit,
activityTypes: activityTypes,
readType: arg.readType.int
)
)
let responseJson = %*{ let responseJson = %*{
"activityNotifications": activityNotificationsCallResult.result "activityNotifications": activityNotificationsCallResult.result

View File

@ -51,6 +51,15 @@ const SIGNAL_MARK_NOTIFICATIONS_AS_DISMISSED* = "markNotificationsAsDismissed"
const DEFAULT_LIMIT = 20 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: QtObject:
type Service* = ref object of QObject type Service* = ref object of QObject
@ -137,17 +146,17 @@ QtObject:
self.threadpool.start(arg) self.threadpool.start(arg)
proc getActivityCenterNotifications*(self: Service): seq[ActivityCenterNotificationDto] = proc getActivityCenterNotifications*(self: Service): seq[ActivityCenterNotificationDto] =
var cursorVal: JsonNode
if self.cursor == "":
cursorVal = newJNull()
else:
cursorVal = newJString(self.cursor)
try: try:
let groupTypes = activityCenterNotificationTypesByGroup(self.activeGroup) let activityTypes = activityCenterNotificationTypesByGroup(self.activeGroup)
let callResult = backend.activityCenterNotificationsBy(cursorVal, DEFAULT_LIMIT, groupTypes, self.readType.int, true) let response = backend.activityCenterNotifications(
let activityCenterNotificationsTuple = parseActivityCenterNotifications(callResult.result) backend.ActivityCenterNotificationsRequest(
cursor: self.cursor,
limit: DEFAULT_LIMIT,
activityTypes: activityTypes,
readType: self.readType.int
)
)
let activityCenterNotificationsTuple = parseActivityCenterNotifications(response.result)
self.cursor = activityCenterNotificationsTuple[0]; self.cursor = activityCenterNotificationsTuple[0];
result = activityCenterNotificationsTuple[1] result = activityCenterNotificationsTuple[1]
@ -155,26 +164,42 @@ QtObject:
except Exception as e: except Exception as e:
error "Error getting activity center notifications", msg = e.msg 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: try:
let groupTypes = activityCenterNotificationTypesByGroup(group) let response = backend.activityCenterNotificationsCount(
let response = backend.activityCenterNotificationsCountBy(groupTypes, self.readType.int, true) backend.ActivityCenterCountRequest(
activityTypes: activityTypes,
readType: readType.int,
)
)
var counters = initTable[int, int]()
if response.result.kind != JNull: if response.result.kind != JNull:
return response.result.getInt for activityType in activityTypes:
except Exception as e: if response.result.contains($activityType):
error "Error getting activity center notifications group count", msg = e.msg counters.add(activityType, response.result[$activityType].getInt)
return counters
proc getUnreadActivityCenterNotificationsCount*(self: Service): int =
try:
let response = backend.unreadActivityCenterNotificationsCount()
if response.result.kind != JNull:
return response.result.getInt
except Exception as e: except Exception as e:
error "Error getting unread activity center notifications 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 =
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 = proc getHasUnseenActivityCenterNotifications*(self: Service): bool =
try: try:
let response = backend.hasUnseenActivityCenterNotifications() let response = backend.hasUnseenActivityCenterNotifications()

View File

@ -46,6 +46,16 @@ type
chainColor* {.serializedFieldName("chainColor").}: string chainColor* {.serializedFieldName("chainColor").}: string
shortName* {.serializedFieldName("shortName").}: 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"): rpc(clientVersion, "web3"):
discard discard
@ -162,20 +172,10 @@ rpc(addAccountWatch, "accounts"):
emoji: string emoji: string
rpc(activityCenterNotifications, "wakuext"): rpc(activityCenterNotifications, "wakuext"):
cursorVal: JsonNode request: ActivityCenterNotificationsRequest
limit: int
rpc(activityCenterNotificationsBy, "wakuext"): rpc(activityCenterNotificationsCount, "wakuext"):
cursorVal: JsonNode request: ActivityCenterCountRequest
limit: int
activityTypes: seq[int]
readType: int
accepted: bool
rpc(activityCenterNotificationsCountBy, "wakuext"):
activityTypes: seq[int]
readType: int
accepted: bool
rpc(markAllActivityCenterNotificationsRead, "wakuext"): rpc(markAllActivityCenterNotificationsRead, "wakuext"):
discard discard
@ -192,18 +192,12 @@ rpc(acceptActivityCenterNotifications, "wakuext"):
rpc(dismissActivityCenterNotifications, "wakuext"): rpc(dismissActivityCenterNotifications, "wakuext"):
ids: seq[string] ids: seq[string]
rpc(unreadActivityCenterNotificationsCount, "wakuext"):
discard
rpc(hasUnseenActivityCenterNotifications, "wakuext"): rpc(hasUnseenActivityCenterNotifications, "wakuext"):
discard discard
rpc(markAsSeenActivityCenterNotifications, "wakuext"): rpc(markAsSeenActivityCenterNotifications, "wakuext"):
discard discard
rpc(unreadAndAcceptedActivityCenterNotificationsCount, "wakuext"):
discard
rpc(getBookmarks, "browsers"): rpc(getBookmarks, "browsers"):
discard discard

View File

@ -18,7 +18,7 @@ Item {
property bool hasMentions: false property bool hasMentions: false
property bool hasReplies: false property bool hasReplies: false
property bool hasContactRequests: false property bool hasContactRequests: false
property bool hasIdentityRequests: false property bool hasIdentityVerification: false
property bool hasMembership: false property bool hasMembership: false
property bool hideReadNotifications: false property bool hideReadNotifications: false
@ -54,7 +54,7 @@ Item {
{ text: qsTr("Mentions"), group: ActivityCenterStore.ActivityCenterGroup.Mentions, visible: true, enabled: root.hasMentions }, { 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("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("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("Transactions"), group: ActivityCenterStore.ActivityCenterGroup.Transactions, visible: false, enabled: true },
{ text: qsTr("Membership"), group: ActivityCenterStore.ActivityCenterGroup.Membership, visible: true, enabled: root.hasMembership }, { text: qsTr("Membership"), group: ActivityCenterStore.ActivityCenterGroup.Membership, visible: true, enabled: root.hasMembership },
{ text: qsTr("System"), group: ActivityCenterStore.ActivityCenterGroup.System, visible: false, enabled: true } ] { text: qsTr("System"), group: ActivityCenterStore.ActivityCenterGroup.System, visible: false, enabled: true } ]

View File

@ -60,7 +60,7 @@ Popup {
hasReplies: activityCenterStore.repliesCount > 0 hasReplies: activityCenterStore.repliesCount > 0
hasMentions: activityCenterStore.mentionsCount > 0 hasMentions: activityCenterStore.mentionsCount > 0
hasContactRequests: activityCenterStore.contactRequestsCount > 0 hasContactRequests: activityCenterStore.contactRequestsCount > 0
hasIdentityRequests: activityCenterStore.identityRequestsCount > 0 hasIdentityVerification: activityCenterStore.identityVerificationCount > 0
hasMembership: activityCenterStore.membershipCount > 0 hasMembership: activityCenterStore.membershipCount > 0
hideReadNotifications: activityCenterStore.activityCenterReadType === ActivityCenterStore.ActivityCenterReadType.Unread hideReadNotifications: activityCenterStore.activityCenterReadType === ActivityCenterStore.ActivityCenterReadType.Unread
activeGroup: activityCenterStore.activeNotificationGroup activeGroup: activityCenterStore.activeNotificationGroup

View File

@ -55,7 +55,7 @@ QtObject {
readonly property int mentionsCount: activityCenterModuleInst.mentionsCount readonly property int mentionsCount: activityCenterModuleInst.mentionsCount
readonly property int repliesCount: activityCenterModuleInst.repliesCount readonly property int repliesCount: activityCenterModuleInst.repliesCount
readonly property int contactRequestsCount: activityCenterModuleInst.contactRequestsCount readonly property int contactRequestsCount: activityCenterModuleInst.contactRequestsCount
readonly property int identityRequestsCount: activityCenterModuleInst.identityRequestsCount readonly property int identityVerificationCount: activityCenterModuleInst.identityVerificationCount
readonly property int membershipCount: activityCenterModuleInst.membershipCount readonly property int membershipCount: activityCenterModuleInst.membershipCount
function markAllActivityCenterNotificationsRead() { function markAllActivityCenterNotificationsRead() {

2
vendor/status-go vendored

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