From c4496483d35dee6d5cd9bac50db8fe8292dbb57e Mon Sep 17 00:00:00 2001 From: MishkaRogachev Date: Fri, 30 Sep 2022 20:49:54 +0400 Subject: [PATCH] feat(ActivityCenter): handle notification's updates via response --- src/app/boot/app_controller.nim | 6 ++--- src/app/modules/main/activity_center/view.nim | 3 +-- .../service/activity_center/service.nim | 25 +++++++++++-------- src/app_service/service/contacts/service.nim | 8 +++++- .../panels/ContactRequestCta.qml | 4 +-- .../ActivityNotificationContactRequest.qml | 8 ++++-- 6 files changed, 33 insertions(+), 21 deletions(-) diff --git a/src/app/boot/app_controller.nim b/src/app/boot/app_controller.nim index 531267243b..4d78fe008b 100644 --- a/src/app/boot/app_controller.nim +++ b/src/app/boot/app_controller.nim @@ -129,6 +129,7 @@ proc newAppController*(statusFoundation: StatusFoundation): AppController = # Services result.generalService = general_service.newService() + result.activityCenterService = activity_center_service.newService(statusFoundation.events, statusFoundation.threadpool) result.keycardService = keycard_service.newService(statusFoundation.events, statusFoundation.threadpool) result.nodeConfigurationService = node_configuration_service.newService(statusFoundation.fleetConfiguration, result.settingsService) @@ -136,13 +137,12 @@ proc newAppController*(statusFoundation: StatusFoundation): AppController = result.accountsService = accounts_service.newService(statusFoundation.fleetConfiguration) result.networkService = network_service.newService(statusFoundation.events, result.settingsService) result.contactsService = contacts_service.newService( - statusFoundation.events, statusFoundation.threadpool, result.networkService, result.settingsService + statusFoundation.events, statusFoundation.threadpool, result.networkService, result.settingsService, + result.activityCenterService ) result.chatService = chat_service.newService(statusFoundation.events, result.contactsService) result.communityService = community_service.newService(statusFoundation.events, statusFoundation.threadpool, result.chatService) - result.activityCenterService = activity_center_service.newService(statusFoundation.events, - statusFoundation.threadpool, result.chatService) result.tokenService = token_service.newService( statusFoundation.events, statusFoundation.threadpool, result.networkService ) diff --git a/src/app/modules/main/activity_center/view.nim b/src/app/modules/main/activity_center/view.nim index 55092ea9f2..ee2ea608e4 100644 --- a/src/app/modules/main/activity_center/view.nim +++ b/src/app/modules/main/activity_center/view.nim @@ -116,14 +116,13 @@ QtObject: self.model.removeNotifications(notificationIds) proc addActivityCenterNotification*(self: View, activityCenterNotifications: seq[Item]) = - for activityCenterNotification in activityCenterNotifications: # TODO this should be handled by the chat or community module # if self.channelView.activeChannel.id == activityCenterNotification.chatId: # activityCenterNotification.read = true # let communityId = self.status.chat.getCommunityIdForChat(activityCenterNotification.chatId) # if communityId != "": # self.communities.joinedCommunityList.decrementMentions(communityId, activityCenterNotification.chatId) - self.model.addActivityNotificationItemToList(activityCenterNotification) + self.model.addActivityNotificationItemsToList(activityCenterNotifications) proc switchTo*(self: View, sectionId: string, chatId: string, messageId: string) {.slot.} = self.delegate.switchTo(sectionId, chatId, messageId) diff --git a/src/app_service/service/activity_center/service.nim b/src/app_service/service/activity_center/service.nim index 6fdeb1964c..aad183f5d3 100644 --- a/src/app_service/service/activity_center/service.nim +++ b/src/app_service/service/activity_center/service.nim @@ -7,8 +7,6 @@ import ../../../app/core/tasks/[qt, threadpool] import web3/ethtypes, web3/conversions, stew/byteutils, nimcrypto, json_serialization, chronicles import json, tables, json_serialization -import ../chat/service as chat_service - import ../../../backend/backend import ../../../backend/response_type import ./dto/notification @@ -57,7 +55,6 @@ QtObject: type Service* = ref object of QObject threadpool: ThreadPool events: EventEmitter - chatService: chat_service.Service cursor*: string # Forward declaration @@ -68,14 +65,12 @@ QtObject: proc newService*( events: EventEmitter, - threadpool: ThreadPool, - chatService: chat_service.Service + threadpool: ThreadPool ): Service = new(result, delete) result.QObject.setup result.events = events result.threadpool = threadpool - result.chatService = chatService proc init*(self: Service) = self.asyncActivityNotificationLoad() @@ -89,6 +84,18 @@ QtObject: ActivityCenterNotificationsArgs(activityCenterNotifications: receivedData.activityCenterNotifications) ) + proc parseACNotificationResponse*(self: Service, response: RpcResponse[JsonNode]) = + var activityCenterNotifications: seq[ActivityCenterNotificationDto] = @[] + if response.result{"activityCenterNotifications"} != nil: + for jsonMsg in response.result["activityCenterNotifications"]: + activityCenterNotifications.add(jsonMsg.toActivityCenterNotificationDto) + + if (activityCenterNotifications.len > 0): + self.events.emit( + SIGNAL_ACTIVITY_CENTER_NOTIFICATIONS_LOADED, + ActivityCenterNotificationsArgs(activityCenterNotifications: activityCenterNotifications) + ) + proc hasMoreToShow*(self: Service): bool = return self.cursor != "" @@ -177,11 +184,7 @@ QtObject: proc acceptActivityCenterNotifications*(self: Service, notificationIds: seq[string]): string = try: - let response = backend.acceptActivityCenterNotifications(notificationIds) - - let (chats, messages) = self.chatService.parseChatResponse(response) - self.events.emit(chat_service.SIGNAL_CHAT_UPDATE, - ChatUpdateArgs(messages: messages, chats: chats)) + discard backend.acceptActivityCenterNotifications(notificationIds) except Exception as e: error "Error marking as accepted", msg = e.msg diff --git a/src/app_service/service/contacts/service.nim b/src/app_service/service/contacts/service.nim index 3eeb14dd4e..e8d128286b 100644 --- a/src/app_service/service/contacts/service.nim +++ b/src/app_service/service/contacts/service.nim @@ -7,6 +7,7 @@ import ../../../app/core/tasks/[qt, threadpool] import ../../common/types as common_types import ../../common/conversion as service_conversion +import ../activity_center/service as activity_center_service import ../settings/service as settings_service import ../network/service as network_service import ../visual_identity/service as procs_from_visual_identity_service @@ -83,6 +84,7 @@ QtObject: threadpool: ThreadPool networkService: network_service.Service settingsService: settings_service.Service + activityCenterService: activity_center_service.Service contacts: Table[string, ContactsDto] # [contact_id, ContactsDto] contactsStatus: Table[string, StatusUpdateDto] # [contact_id, StatusUpdateDto] receivedIdentityRequests: Table[string, VerificationRequest] # [from_id, VerificationRequest] @@ -106,7 +108,8 @@ QtObject: events: EventEmitter, threadpool: ThreadPool, networkService: network_service.Service, - settingsService: settings_service.Service + settingsService: settings_service.Service, + activityCenterService: activity_center_service.Service, ): Service = new(result, delete) result.QObject.setup @@ -114,6 +117,7 @@ QtObject: result.events = events result.networkService = networkService result.settingsService = settingsService + result.activityCenterService = activityCenterService result.threadpool = threadpool result.contacts = initTable[string, ContactsDto]() result.contactsStatus = initTable[string, StatusUpdateDto]() @@ -415,6 +419,7 @@ QtObject: contact.removed = false self.saveContact(contact) self.events.emit(SIGNAL_CONTACT_ADDED, ContactArgs(contactId: contact.id)) + self.activityCenterService.parseACNotificationResponse(response) except Exception as e: error "an error occurred while accepting contact request", msg=e.msg @@ -431,6 +436,7 @@ QtObject: contact.removed = true self.saveContact(contact) self.events.emit(SIGNAL_CONTACT_REMOVED, ContactArgs(contactId: contact.id)) + self.activityCenterService.parseACNotificationResponse(response) except Exception as e: error "an error occurred while dismissing contact request", msg=e.msg diff --git a/ui/app/mainui/activitycenter/panels/ContactRequestCta.qml b/ui/app/mainui/activitycenter/panels/ContactRequestCta.qml index d6cec0f4d2..f8cda741ab 100644 --- a/ui/app/mainui/activitycenter/panels/ContactRequestCta.qml +++ b/ui/app/mainui/activitycenter/panels/ContactRequestCta.qml @@ -19,8 +19,8 @@ Item { signal blockClicked() signal profileClicked() - width: buttons.width - height: buttons.height + width: Math.max(textItem.width, buttons.width) + height: Math.max(textItem.height, buttons.height) StatusBaseText { id: textItem diff --git a/ui/app/mainui/activitycenter/views/ActivityNotificationContactRequest.qml b/ui/app/mainui/activitycenter/views/ActivityNotificationContactRequest.qml index fc23d596ab..e3a95f57af 100644 --- a/ui/app/mainui/activitycenter/views/ActivityNotificationContactRequest.qml +++ b/ui/app/mainui/activitycenter/views/ActivityNotificationContactRequest.qml @@ -16,14 +16,18 @@ ActivityNotificationMessage { ctaComponent: ContactRequestCta { readonly property string senderId: notification.message.senderId + readonly property var contactDetails: Utils.getContactDetailsAsJson(senderId) pending: notification.message.contactRequestState == Constants.contactRequestStatePending accepted: notification.message.contactRequestState == Constants.contactRequestStateAccepted dismissed: notification.message.contactRequestState == Constants.contactRequestStateDismissed - blocked: root.store.contactsStore.isBlockedContact(senderId) + blocked: contactDetails.isBlocked onAcceptClicked: root.store.contactsStore.acceptContactRequest(senderId) onDeclineClicked: root.store.contactsStore.dismissContactRequest(senderId) onProfileClicked: Global.openProfilePopup(senderId) - onBlockClicked: root.store.contactsStore.blockContact(senderId) + onBlockClicked: { + root.store.contactsStore.dismissContactRequest(senderId) + root.store.contactsStore.blockContact(senderId) + } } } \ No newline at end of file