diff --git a/src/app/chat/views/activity_notification_list.nim b/src/app/chat/views/activity_notification_list.nim index 43843d720c..f45239d58d 100644 --- a/src/app/chat/views/activity_notification_list.nim +++ b/src/app/chat/views/activity_notification_list.nim @@ -1,4 +1,4 @@ -import NimQml, Tables, chronicles +import NimQml, Tables, chronicles, json, sequtils, strformat import ../../../status/chat/chat import ../../../status/status import ../../../status/accounts @@ -125,6 +125,30 @@ QtObject: let bottomRight = self.createIndex(self.activityCenterNotifications.len - 1, 0, nil) self.dataChanged(topLeft, bottomRight, @[NotifRoles.Read.int]) + proc markActivityCenterNotificationsRead(self: ActivityNotificationList, idsJson: string): string {.slot.} = + let ids = map(parseJson(idsJson).getElems(), proc(x:JsonNode):string = x.getStr()) + + let error = self.status.chat.markActivityCenterNotificationsRead(ids) + if (error != ""): + return error + + self.nbUnreadNotifications = self.nbUnreadNotifications - ids.len + if (self.nbUnreadNotifications < 0): + self.nbUnreadNotifications = 0 + self.unreadCountChanged() + + var i = 0 + for activityCenterNotification in self.activityCenterNotifications: + for id in ids: + if (activityCenterNotification.id == id): + activityCenterNotification.read = true + let topLeft = self.createIndex(i, 0, nil) + let bottomRight = self.createIndex(i, 0, nil) + self.dataChanged(topLeft, bottomRight, @[NotifRoles.Read.int]) + i = i + 1 + + proc markActivityCenterNotificationRead(self: ActivityNotificationList, id: string): string {.slot.} = + self.markActivityCenterNotificationsRead(fmt"[""{id}""]") proc toActivityCenterNotificationViewItem*(self: ActivityNotificationList, activityCenterNotification: ActivityCenterNotification): ActivityCenterNotificationViewItem = ActivityCenterNotificationViewItem( diff --git a/src/app/chat/views/communities.nim b/src/app/chat/views/communities.nim index 7a66fea24e..939045e7c0 100644 --- a/src/app/chat/views/communities.nim +++ b/src/app/chat/views/communities.nim @@ -1,4 +1,4 @@ -import NimQml, json, sequtils, chronicles, strutils, strformat, json +import NimQml, json, sequtils, chronicles, strutils, strformat import ../../../status/status import ../../../status/chat/chat import ./community_list diff --git a/src/status/chat.nim b/src/status/chat.nim index cb168f7a6e..e386abbe9c 100644 --- a/src/status/chat.nim +++ b/src/status/chat.nim @@ -563,7 +563,13 @@ proc markAllActivityCenterNotificationsRead*(self: ChatModel): string = except Exception as e: error "Error marking all as read", msg = e.msg result = e.msg - + +proc markActivityCenterNotificationsRead*(self: ChatModel, ids: seq[string]): string = + try: + status_chat.markActivityCenterNotificationsRead(ids) + except Exception as e: + error "Error marking as read", msg = e.msg + result = e.msg proc unreadActivityCenterNotificationsCount*(self: ChatModel): int = status_chat.unreadActivityCenterNotificationsCount() diff --git a/src/status/libstatus/chat.nim b/src/status/libstatus/chat.nim index 446b6ea317..e9064cc941 100644 --- a/src/status/libstatus/chat.nim +++ b/src/status/libstatus/chat.nim @@ -591,6 +591,9 @@ proc activityCenterNotification*(cursor: string = ""): (string, seq[ActivityCent proc markAllActivityCenterNotificationsRead*() = discard callPrivateRPC("markAllActivityCenterNotificationsRead".prefix, %*[]) +proc markActivityCenterNotificationsRead*(ids: seq[string]) = + let res = callPrivateRPC("markActivityCenterNotificationsRead".prefix, %*[ids]) + proc unreadActivityCenterNotificationsCount*(): int = let rpcResult = callPrivateRPC("unreadActivityCenterNotificationsCount".prefix, %*[]).parseJson diff --git a/ui/app/AppLayouts/Chat/ChatColumn/ActivityCenter.qml b/ui/app/AppLayouts/Chat/ChatColumn/ActivityCenter.qml index a66a4e601b..d016f3b18a 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/ActivityCenter.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/ActivityCenter.qml @@ -176,29 +176,28 @@ Popup { prevMsgTimestamp: notificationDelegate.idx === 0 ? "" : chatsModel.activityNotificationList.getNotificationData(prevMessageIndex, "timestamp") } - // TODO add this back when single MarkAsRead is available - // StatusIconButton { - // id: markReadBtn - // icon.name: "double-check" - // iconColor: Style.current.primary - // icon.width: 24 - // icon.height: 24 - // width: 32 - // height: 32 - // onClicked: console.log('TODO mark read') - // anchors.right: parent.right - // anchors.rightMargin: 12 - // anchors.verticalCenter: notificationMessage.verticalCenter - // z: 52 + StatusIconButton { + id: markReadBtn + icon.name: "double-check" + iconColor: Style.current.primary + icon.width: 24 + icon.height: 24 + width: 32 + height: 32 + onClicked: chatsModel.activityNotificationList.markActivityCenterNotificationRead(model.id) + anchors.right: parent.right + anchors.rightMargin: 12 + anchors.verticalCenter: notificationMessage.verticalCenter + z: 52 - // StatusToolTip { - // visible: markReadBtn.hovered - // text: qsTr("Mark as Read") - // orientation: "left" - // x: - width - Style.current.padding - // y: markReadBtn.height / 2 - height / 2 + 4 - // } - // } + StatusToolTip { + visible: markReadBtn.hovered + text: qsTr("Mark as Read") + orientation: "left" + x: - width - Style.current.padding + y: markReadBtn.height / 2 - height / 2 + 4 + } + } ActivityChannelBadge { name: model.name