Skip to content

Commit

Permalink
fix(ActivityCenter): Simplify and fix AC notifications read/unread st…
Browse files Browse the repository at this point in the history
…ates (#12753)

* fix(ActivityCenter): Simplify and fix AC notifications read/unread states

* fix: review fixes
  • Loading branch information
MishkaRogachev committed Nov 20, 2023
1 parent 200c0b3 commit 7830310
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 250 deletions.
54 changes: 15 additions & 39 deletions src/app/modules/main/activity_center/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -55,34 +55,25 @@ proc init*(self: Controller) =
self.delegate.addActivityCenterNotifications(args.activityCenterNotifications)
self.updateActivityGroupCounters()

self.events.on(activity_center_service.SIGNAL_MARK_NOTIFICATIONS_AS_ACCEPTED) do(e: Args):
var evArgs = MarkAsAcceptedNotificationProperties(e)
self.delegate.acceptActivityCenterNotificationsDone(evArgs.notificationIds)

self.events.on(activity_center_service.SIGNAL_MARK_NOTIFICATIONS_AS_DISMISSED) do(e: Args):
var evArgs = MarkAsDismissedNotificationProperties(e)
self.delegate.dismissActivityCenterNotificationsDone(evArgs.notificationIds)

self.events.on(activity_center_service.SIGNAL_MARK_NOTIFICATIONS_AS_READ) do(e: Args):
var evArgs = MarkAsReadNotificationProperties(e)
if (evArgs.isAll):
self.delegate.markAllActivityCenterNotificationsReadDone()
return
self.events.on(activity_center_service.SIGNAL_ACTIVITY_CENTER_MARK_NOTIFICATIONS_AS_READ) do(e: Args):
var evArgs = ActivityCenterNotificationIdsArgs(e)
if (evArgs.notificationIds.len > 0):
self.delegate.markActivityCenterNotificationReadDone(evArgs.notificationIds)

self.events.on(activity_center_service.SIGNAL_MARK_NOTIFICATIONS_AS_UNREAD) do(e: Args):
var evArgs = MarkAsUnreadNotificationProperties(e)
self.events.on(activity_center_service.SIGNAL_ACTIVITY_CENTER_MARK_NOTIFICATIONS_AS_UNREAD) do(e: Args):
var evArgs = ActivityCenterNotificationIdsArgs(e)
if (evArgs.notificationIds.len > 0):
self.delegate.markActivityCenterNotificationUnreadDone(evArgs.notificationIds)

self.events.on(activity_center_service.SIGNAL_ACTIVITY_CENTER_MARK_ALL_NOTIFICATIONS_AS_READ) do(e: Args):
self.delegate.markAllActivityCenterNotificationsReadDone()

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.onNotificationsCountMayHaveChanged()
self.updateActivityGroupCounters()

self.events.on(activity_center_service.SIGNAL_ACTIVITY_CENTER_NOTIFICATIONS_REMOVED) do(e: Args):
var evArgs = RemoveActivityCenterNotificationsArgs(e)
var evArgs = ActivityCenterNotificationIdsArgs(e)
if (evArgs.notificationIds.len > 0):
self.delegate.removeActivityCenterNotifications(evArgs.notificationIds)

Expand All @@ -107,32 +98,18 @@ proc getActivityCenterNotifications*(self: Controller): seq[ActivityCenterNotifi
proc asyncActivityNotificationLoad*(self: Controller) =
self.activityCenterService.asyncActivityNotificationLoad()

proc markAllActivityCenterNotificationsRead*(self: Controller): string =
return self.activityCenterService.markAllActivityCenterNotificationsRead()
proc markAllActivityCenterNotificationsRead*(self: Controller) =
self.activityCenterService.markAllActivityCenterNotificationsRead()

proc markActivityCenterNotificationRead*(
self: Controller,
notificationId: string,
markAsReadProps: MarkAsReadNotificationProperties
): string =
return self.activityCenterService.markActivityCenterNotificationRead(notificationId, markAsReadProps)
proc markActivityCenterNotificationRead*(self: Controller, notificationId: string) =
self.activityCenterService.markActivityCenterNotificationRead(notificationId)

proc markActivityCenterNotificationUnread*(
self: Controller,
notificationId: string,
markAsUnreadProps: MarkAsUnreadNotificationProperties
): string =
return self.activityCenterService.markActivityCenterNotificationUnread(notificationId, markAsUnreadProps)
proc markActivityCenterNotificationUnread*(self: Controller,notificationId: string) =
self.activityCenterService.markActivityCenterNotificationUnread(notificationId)

proc markAsSeenActivityCenterNotifications*(self: Controller) =
self.activityCenterService.markAsSeenActivityCenterNotifications()

proc acceptActivityCenterNotifications*(self: Controller, notificationIds: seq[string]): string =
return self.activityCenterService.acceptActivityCenterNotifications(notificationIds)

proc dismissActivityCenterNotifications*(self: Controller, notificationIds: seq[string]): string =
return self.activityCenterService.dismissActivityCenterNotifications(notificationIds)

proc replacePubKeysWithDisplayNames*(self: Controller, message: string): string =
return self.messageService.replacePubKeysWithDisplayNames(message)

Expand Down Expand Up @@ -171,4 +148,3 @@ proc setActivityCenterReadType*(self: Controller, readType: ActivityCenterReadTy

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

18 changes: 3 additions & 15 deletions src/app/modules/main/activity_center/io_interface.nim
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ method unreadActivityCenterNotificationsCount*(self: AccessInterface): int {.bas
method hasUnseenActivityCenterNotifications*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")

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

method hasUnseenActivityCenterNotificationsChanged*(self: AccessInterface) {.base.} =
Expand All @@ -45,9 +45,6 @@ method markAllActivityCenterNotificationsRead*(self: AccessInterface): string {.
method markAllActivityCenterNotificationsReadDone*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

method dismissActivityCenterNotificationsDone*(self: AccessInterface, notificationIds: seq[string]) {.base.} =
raise newException(ValueError, "No implementation available")

method markActivityCenterNotificationReadDone*(self: AccessInterface, notificationIds: seq[string]) {.base.} =
raise newException(ValueError, "No implementation available")

Expand All @@ -57,13 +54,10 @@ method markActivityCenterNotificationUnreadDone*(self: AccessInterface, notifica
method removeActivityCenterNotifications*(self: AccessInterface, notificationIds: seq[string]) {.base.} =
raise newException(ValueError, "No implementation available")

method acceptActivityCenterNotificationsDone*(self: AccessInterface, notificationIds: seq[string]) {.base.} =
raise newException(ValueError, "No implementation available")

method markActivityCenterNotificationRead*(self: AccessInterface, notificationId: string, communityId: string, channelId: string, nType: int): string {.base.} =
method markActivityCenterNotificationRead*(self: AccessInterface, notificationId: string) {.base.} =
raise newException(ValueError, "No implementation available")

method markActivityCenterNotificationUnread*(self: AccessInterface, notificationId: string, communityId: string, channelId: string, nType: int): string {.base.} =
method markActivityCenterNotificationUnread*(self: AccessInterface, notificationId: string) {.base.} =
raise newException(ValueError, "No implementation available")

method markAsSeenActivityCenterNotifications*(self: AccessInterface) {.base.} =
Expand All @@ -75,12 +69,6 @@ method addActivityCenterNotifications*(self: AccessInterface, activityCenterNoti
method resetActivityCenterNotifications*(self: AccessInterface, activityCenterNotifications: seq[ActivityCenterNotificationDto]) {.base.} =
raise newException(ValueError, "No implementation available")

method acceptActivityCenterNotifications*(self: AccessInterface, notificationIds: seq[string]): string {.base.} =
raise newException(ValueError, "No implementation available")

method dismissActivityCenterNotifications*(self: AccessInterface, notificationIds: seq[string]): string {.base.} =
raise newException(ValueError, "No implementation available")

method switchTo*(self: AccessInterface, sectionId, chatId, messageId: string) {.base.} =
raise newException(ValueError, "No implementation available")

Expand Down
2 changes: 1 addition & 1 deletion src/app/modules/main/activity_center/model.nim
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ QtObject:
if (notification.chatId == chatId and not notification.read):
result.add(notification.id)

proc markAllAsRead*(self: Model) =
proc markAllAsRead*(self: Model) =
for activityCenterNotification in self.activityCenterNotifications:
activityCenterNotification.read = true

Expand Down
54 changes: 10 additions & 44 deletions src/app/modules/main/activity_center/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ method unreadActivityCenterNotificationsCount*(self: Module): int =
method hasUnseenActivityCenterNotifications*(self: Module): bool =
self.controller.hasUnseenActivityCenterNotifications()

method unreadActivityCenterNotificationsCountChanged*(self: Module) =
method onNotificationsCountMayHaveChanged*(self: Module) =
self.view.unreadActivityCenterNotificationsCountChanged()
self.view.hasUnseenActivityCenterNotificationsChanged()

method hasUnseenActivityCenterNotificationsChanged*(self: Module) =
self.view.hasUnseenActivityCenterNotificationsChanged()
Expand Down Expand Up @@ -196,72 +197,37 @@ method markAllActivityCenterNotificationsRead*(self: Module): string =

method markAllActivityCenterNotificationsReadDone*(self: Module) =
self.view.markAllActivityCenterNotificationsReadDone()
self.view.unreadActivityCenterNotificationsCountChanged()

method markActivityCenterNotificationRead*(
self: Module,
notificationId: string,
communityId: string,
channelId: string,
nType: int
): string =
let notificationType = ActivityCenterNotificationType(nType)
let markAsReadProps = MarkAsReadNotificationProperties(
notificationIds: @[notificationId],
communityId: communityId,
channelId: channelId,
notificationTypes: @[notificationType]
)
result = self.controller.markActivityCenterNotificationRead(notificationId, markAsReadProps)
method markActivityCenterNotificationRead*(self: Module, notificationId: string) =
self.controller.markActivityCenterNotificationRead(notificationId)

method markActivityCenterNotificationReadDone*(self: Module, notificationIds: seq[string]) =
for notificationId in notificationIds:
self.view.markActivityCenterNotificationReadDone(notificationId)
self.view.unreadActivityCenterNotificationsCountChanged()

method markAsSeenActivityCenterNotifications*(self: Module) =
self.controller.markAsSeenActivityCenterNotifications()

method addActivityCenterNotifications*(self: Module, activityCenterNotifications: seq[ActivityCenterNotificationDto]) =
self.view.addActivityCenterNotifications(self.convertToItems(activityCenterNotifications))
self.view.hasUnseenActivityCenterNotificationsChanged()

method resetActivityCenterNotifications*(self: Module, activityCenterNotifications: seq[ActivityCenterNotificationDto]) =
self.view.resetActivityCenterNotifications(self.convertToItems(activityCenterNotifications))

method markActivityCenterNotificationUnread*(
self: Module,
notificationId: string,
communityId: string,
channelId: string,
nType: int
): string =
let notificationType = ActivityCenterNotificationType(nType)
let markAsUnreadProps = MarkAsUnreadNotificationProperties(
notificationIds: @[notificationId],
communityId: communityId,
channelId: channelId,
notificationTypes: @[notificationType]
)

result = self.controller.markActivityCenterNotificationUnread(notificationId, markAsUnreadProps)
method markActivityCenterNotificationUnread*(self: Module, notificationId: string) =
self.controller.markActivityCenterNotificationUnread(notificationId)

method markActivityCenterNotificationUnreadDone*(self: Module, notificationIds: seq[string]) =
for notificationId in notificationIds:
self.view.markActivityCenterNotificationUnreadDone(notificationId)
self.view.unreadActivityCenterNotificationsCountChanged()

method removeActivityCenterNotifications*(self: Module, notificationIds: seq[string]) =
self.view.removeActivityCenterNotifications(notificationIds)

method acceptActivityCenterNotificationsDone*(self: Module, notificationIds: seq[string]) =
self.view.acceptActivityCenterNotificationsDone(notificationIds)

method acceptActivityCenterNotifications*(self: Module, notificationIds: seq[string]): string =
self.controller.acceptActivityCenterNotifications(notificationIds)

method dismissActivityCenterNotificationsDone*(self: Module, notificationIds: seq[string]) =
self.view.dismissActivityCenterNotificationsDone(notificationIds)

method dismissActivityCenterNotifications*(self: Module, notificationIds: seq[string]): string =
self.controller.dismissActivityCenterNotifications(notificationIds)

method switchTo*(self: Module, sectionId, chatId, messageId: string) =
self.controller.switchTo(sectionId, chatId, messageId)

Expand Down
61 changes: 8 additions & 53 deletions src/app/modules/main/activity_center/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -71,70 +71,25 @@ QtObject:
proc markAllActivityCenterNotificationsReadDone*(self: View) {.slot.} =
self.model.markAllAsRead()

proc markActivityCenterNotificationRead(
self: View,
notificationId: string,
communityId: string,
channelId: string,
nType: int
): void {.slot.} =
discard self.delegate.markActivityCenterNotificationRead(notificationId, communityId, channelId, nType)
proc markActivityCenterNotificationRead(self: View, notificationId: string): void {.slot.} =
self.delegate.markActivityCenterNotificationRead(notificationId)

proc markActivityCenterNotificationReadDone*(self: View, notificationId: string) =
self.model.markActivityCenterNotificationRead(notificationId)
self.model.markActivityCenterNotificationRead(notificationId)

proc markActivityCenterNotificationUnreadDone*(self: View, notificationId: string) =
self.model.markActivityCenterNotificationUnread(notificationId)
self.model.markActivityCenterNotificationUnread(notificationId)

proc removeActivityCenterNotifications*(self: View, notificationIds: seq[string]) =
self.model.removeNotifications(notificationIds)

proc markAllChatMentionsAsRead*(self: View, communityId: string, chatId: string) =
let notifsIds = self.model.getUnreadNotificationsForChat(chatId)
for notifId in notifsIds:
# TODO change the 3 to the real type
self.markActivityCenterNotificationRead(notifId, communityId, chatId, ActivityCenterNotificationType.Mention.int)

proc markActivityCenterNotificationUnread(
self: View,
notificationId: string,
communityId: string,
channelId: string,
nType: int
): void {.slot.} =
discard self.delegate.markActivityCenterNotificationUnread(
notificationId,
communityId,
channelId,
nType
)
self.model.removeNotifications(notificationIds)

proc markActivityCenterNotificationUnread(self: View, notificationId: string): void {.slot.} =
self.delegate.markActivityCenterNotificationUnread(notificationId)

proc markAsSeenActivityCenterNotifications(self: View): void {.slot.} =
self.delegate.markAsSeenActivityCenterNotifications()
self.hasUnseenActivityCenterNotificationsChanged()

proc acceptActivityCenterNotifications(self: View, idsJson: string): string {.slot.} =
let ids = map(parseJson(idsJson).getElems(), proc(x:JsonNode):string = x.getStr())

result = self.delegate.acceptActivityCenterNotifications(ids)

proc acceptActivityCenterNotificationsDone*(self: View, notificationIds: seq[string]) =
self.model.removeNotifications(notificationIds)

proc acceptActivityCenterNotification(self: View, id: string): string {.slot.} =
self.acceptActivityCenterNotifications(fmt"[""{id}""]")

proc dismissActivityCenterNotifications(self: View, idsJson: string): string {.slot.} =
let ids = map(parseJson(idsJson).getElems(), proc(x:JsonNode):string = x.getStr())

result = self.delegate.dismissActivityCenterNotifications(ids)

proc dismissActivityCenterNotification(self: View, id: string): string {.slot.} =
self.dismissActivityCenterNotifications(fmt"[""{id}""]")

proc dismissActivityCenterNotificationsDone*(self: View, notificationIds: seq[string]) =
self.model.removeNotifications(notificationIds)

proc addActivityCenterNotifications*(self: View, activityCenterNotifications: seq[Item]) =
self.model.upsertActivityCenterNotifications(activityCenterNotifications)

Expand Down
Loading

0 comments on commit 7830310

Please sign in to comment.