feat: update chat unseen counters from the Activity Center (#13020)
Close #12857 * feat: update chat unseen counters from the Activity Center * feat: mark all notifications read also updates chats * chore: review fixes
This commit is contained in:
parent
55d0a3efb5
commit
2d00478467
|
@ -11,6 +11,8 @@ import ../../../backend/response_type
|
|||
import ./dto/notification
|
||||
|
||||
import ../../common/activity_center
|
||||
import ../message/service
|
||||
import ../message/dto/seen_unseen_messages
|
||||
|
||||
export notification
|
||||
|
||||
|
@ -205,7 +207,23 @@ QtObject:
|
|||
proc markActivityCenterNotificationRead*(self: Service, notificationId: string) =
|
||||
try:
|
||||
let notificationIds = @[notificationId]
|
||||
discard backend.markActivityCenterNotificationsRead(notificationIds)
|
||||
let response = backend.markActivityCenterNotificationsRead(notificationIds)
|
||||
|
||||
var seenAndUnseenMessagesBatch: JsonNode = newJObject()
|
||||
discard response.result.getProp("seenAndUnseenMessages", seenAndUnseenMessagesBatch)
|
||||
|
||||
if seenAndUnseenMessagesBatch.len > 0:
|
||||
for seenAndUnseenMessagesRaw in seenAndUnseenMessagesBatch:
|
||||
let seenAndUnseenMessages = seenAndUnseenMessagesRaw.toSeenUnseenMessagesDto()
|
||||
|
||||
let data = MessagesMarkedAsReadArgs(
|
||||
chatId: seenAndUnseenMessages.chatId,
|
||||
allMessagesMarked: false,
|
||||
messagesIds: notificationIds,
|
||||
messagesCount: seenAndUnseenMessages.count,
|
||||
messagesWithMentionsCount: seenAndUnseenMessages.countWithMentions)
|
||||
self.events.emit(SIGNAL_MESSAGES_MARKED_AS_READ, data)
|
||||
|
||||
self.events.emit(SIGNAL_ACTIVITY_CENTER_MARK_NOTIFICATIONS_AS_READ, ActivityCenterNotificationIdsArgs(notificationIds: notificationIds))
|
||||
except Exception as e:
|
||||
error "Error marking as read", msg = e.msg
|
||||
|
@ -220,7 +238,18 @@ QtObject:
|
|||
|
||||
proc markAllActivityCenterNotificationsRead*(self: Service) =
|
||||
try:
|
||||
discard backend.markAllActivityCenterNotificationsRead()
|
||||
let response = backend.markAllActivityCenterNotificationsRead()
|
||||
|
||||
var seenAndUnseenMessagesBatch: JsonNode = newJObject()
|
||||
discard response.result.getProp("seenAndUnseenMessages", seenAndUnseenMessagesBatch)
|
||||
|
||||
if seenAndUnseenMessagesBatch.len > 0:
|
||||
for seenAndUnseenMessagesRaw in seenAndUnseenMessagesBatch:
|
||||
let seenAndUnseenMessages = seenAndUnseenMessagesRaw.toSeenUnseenMessagesDto()
|
||||
|
||||
let data = MessagesMarkedAsReadArgs(chatId: seenAndUnseenMessages.chatId, allMessagesMarked: true)
|
||||
self.events.emit(SIGNAL_MESSAGES_MARKED_AS_READ, data)
|
||||
|
||||
self.events.emit(SIGNAL_ACTIVITY_CENTER_MARK_ALL_NOTIFICATIONS_AS_READ, Args())
|
||||
except Exception as e:
|
||||
error "Error marking all as read", msg = e.msg
|
||||
|
|
|
@ -6,6 +6,15 @@ import ../../../backend/chat as status_go_chat
|
|||
|
||||
import ../../../app/core/custom_urls/urls_manager
|
||||
|
||||
import dto/seen_unseen_messages
|
||||
|
||||
proc getCountAndCountWithMentionsFromResponse(chatId: string, seenAndUnseenMessagesBatch: JsonNode): (int, int) =
|
||||
if seenAndUnseenMessagesBatch.len > 0:
|
||||
for seenAndUnseenMessagesRaw in seenAndUnseenMessagesBatch:
|
||||
let seenAndUnseenMessages = seenAndUnseenMessagesRaw.toSeenUnseenMessagesDto()
|
||||
if seenAndUnseenMessages.chatId == chatId:
|
||||
return (seenAndUnseenMessages.count, seenAndUnseenMessages.countWithMentions)
|
||||
return (0, 0)
|
||||
|
||||
#################################################
|
||||
# Async load messages
|
||||
|
@ -149,11 +158,9 @@ const asyncMarkCertainMessagesReadTask: Task = proc(argEncoded: string) {.gcsafe
|
|||
|
||||
let response = status_go.markCertainMessagesFromChatWithIdAsRead(arg.chatId, arg.messagesIds)
|
||||
|
||||
var count: int
|
||||
discard response.result.getProp("count", count)
|
||||
|
||||
var countWithMentions: int
|
||||
discard response.result.getProp("countWithMentions", countWithMentions)
|
||||
var seenAndUnseenMessagesBatch: JsonNode = newJObject()
|
||||
discard response.result.getProp("seenAndUnseenMessages", seenAndUnseenMessagesBatch)
|
||||
let (count, countWithMentions) = getCountAndCountWithMentionsFromResponse(arg.chatId, seenAndUnseenMessagesBatch)
|
||||
|
||||
var activityCenterNotifications: JsonNode = newJObject()
|
||||
discard response.result.getProp("activityCenterNotifications", activityCenterNotifications)
|
||||
|
@ -319,10 +326,13 @@ const asyncMarkMessageAsUnreadTask: Task = proc(argEncoded: string) {.gcsafe, ni
|
|||
|
||||
var activityCenterNotifications: JsonNode = newJObject()
|
||||
discard response.result.getProp("activityCenterNotifications", activityCenterNotifications)
|
||||
|
||||
responseJson["messagesCount"] = %response.result["count"]
|
||||
responseJson["activityCenterNotifications"] = activityCenterNotifications
|
||||
responseJson["messagesWithMentionsCount"] = %response.result["countWithMentions"]
|
||||
|
||||
var seenAndUnseenMessagesBatch: JsonNode = newJObject()
|
||||
discard response.result.getProp("seenAndUnseenMessages", seenAndUnseenMessagesBatch)
|
||||
let (count, countWithMentions) = getCountAndCountWithMentionsFromResponse(arg.chatId, seenAndUnseenMessagesBatch)
|
||||
responseJson["messagesCount"] = %count
|
||||
responseJson["messagesWithMentionsCount"] = %countWithMentions
|
||||
|
||||
if response.error != nil:
|
||||
responseJson["error"] = %response.error
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
import json
|
||||
|
||||
include ../../../common/json_utils
|
||||
|
||||
type SeenUnseenMessagesDto* = object
|
||||
chatId*: string
|
||||
count*: int
|
||||
countWithMentions*: int
|
||||
seen*: bool
|
||||
|
||||
proc toSeenUnseenMessagesDto*(jsonObj: JsonNode): SeenUnseenMessagesDto =
|
||||
result = SeenUnseenMessagesDto()
|
||||
discard jsonObj.getProp("chatId", result.chatId)
|
||||
discard jsonObj.getProp("count", result.count)
|
||||
discard jsonObj.getProp("countWithMentions", result.countWithMentions)
|
||||
discard jsonObj.getProp("seen", result.seen)
|
|
@ -828,7 +828,7 @@ QtObject:
|
|||
discard responseObj.getProp("countWithMentions", countWithMentions)
|
||||
|
||||
let data = MessagesMarkedAsReadArgs(
|
||||
chatId: chatId,
|
||||
chatId: chatId,
|
||||
allMessagesMarked: false,
|
||||
messagesIds: messagesIds,
|
||||
messagesCount: count,
|
||||
|
|
|
@ -61,7 +61,7 @@ proc markAllMessagesFromChatWithIdAsRead*(chatId: string): RpcResponse[JsonNode]
|
|||
proc markCertainMessagesFromChatWithIdAsRead*(chatId: string, messageIds: seq[string]):
|
||||
RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
let payload = %* [chatId, messageIds]
|
||||
result = callPrivateRPC("markMessagesSeen".prefix, payload)
|
||||
result = callPrivateRPC("markMessagesRead".prefix, payload)
|
||||
|
||||
proc deleteMessageAndSend*(messageID: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
result = callPrivateRPC("deleteMessageAndSend".prefix, %* [messageID])
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit a35236e3ed77e012f540c4ef7d62db046f355387
|
||||
Subproject commit 843bae56597ecf3811d724504bd0216b867979f7
|
Loading…
Reference in New Issue