feat(ActivityCenter): handle notification's updates via response

This commit is contained in:
MishkaRogachev 2022-09-30 20:49:54 +04:00 committed by Mikhail Rogachev
parent 9b227cbfd9
commit c4496483d3
6 changed files with 33 additions and 21 deletions

View File

@ -129,6 +129,7 @@ proc newAppController*(statusFoundation: StatusFoundation): AppController =
# Services # Services
result.generalService = general_service.newService() 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.keycardService = keycard_service.newService(statusFoundation.events, statusFoundation.threadpool)
result.nodeConfigurationService = node_configuration_service.newService(statusFoundation.fleetConfiguration, result.nodeConfigurationService = node_configuration_service.newService(statusFoundation.fleetConfiguration,
result.settingsService) result.settingsService)
@ -136,13 +137,12 @@ proc newAppController*(statusFoundation: StatusFoundation): AppController =
result.accountsService = accounts_service.newService(statusFoundation.fleetConfiguration) result.accountsService = accounts_service.newService(statusFoundation.fleetConfiguration)
result.networkService = network_service.newService(statusFoundation.events, result.settingsService) result.networkService = network_service.newService(statusFoundation.events, result.settingsService)
result.contactsService = contacts_service.newService( 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.chatService = chat_service.newService(statusFoundation.events, result.contactsService)
result.communityService = community_service.newService(statusFoundation.events, result.communityService = community_service.newService(statusFoundation.events,
statusFoundation.threadpool, result.chatService) statusFoundation.threadpool, result.chatService)
result.activityCenterService = activity_center_service.newService(statusFoundation.events,
statusFoundation.threadpool, result.chatService)
result.tokenService = token_service.newService( result.tokenService = token_service.newService(
statusFoundation.events, statusFoundation.threadpool, result.networkService statusFoundation.events, statusFoundation.threadpool, result.networkService
) )

View File

@ -116,14 +116,13 @@ QtObject:
self.model.removeNotifications(notificationIds) self.model.removeNotifications(notificationIds)
proc addActivityCenterNotification*(self: View, activityCenterNotifications: seq[Item]) = proc addActivityCenterNotification*(self: View, activityCenterNotifications: seq[Item]) =
for activityCenterNotification in activityCenterNotifications:
# TODO this should be handled by the chat or community module # TODO this should be handled by the chat or community module
# if self.channelView.activeChannel.id == activityCenterNotification.chatId: # if self.channelView.activeChannel.id == activityCenterNotification.chatId:
# activityCenterNotification.read = true # activityCenterNotification.read = true
# let communityId = self.status.chat.getCommunityIdForChat(activityCenterNotification.chatId) # let communityId = self.status.chat.getCommunityIdForChat(activityCenterNotification.chatId)
# if communityId != "": # if communityId != "":
# self.communities.joinedCommunityList.decrementMentions(communityId, activityCenterNotification.chatId) # 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.} = proc switchTo*(self: View, sectionId: string, chatId: string, messageId: string) {.slot.} =
self.delegate.switchTo(sectionId, chatId, messageId) self.delegate.switchTo(sectionId, chatId, messageId)

View File

@ -7,8 +7,6 @@ import ../../../app/core/tasks/[qt, threadpool]
import web3/ethtypes, web3/conversions, stew/byteutils, nimcrypto, json_serialization, chronicles import web3/ethtypes, web3/conversions, stew/byteutils, nimcrypto, json_serialization, chronicles
import json, tables, json_serialization import json, tables, json_serialization
import ../chat/service as chat_service
import ../../../backend/backend import ../../../backend/backend
import ../../../backend/response_type import ../../../backend/response_type
import ./dto/notification import ./dto/notification
@ -57,7 +55,6 @@ QtObject:
type Service* = ref object of QObject type Service* = ref object of QObject
threadpool: ThreadPool threadpool: ThreadPool
events: EventEmitter events: EventEmitter
chatService: chat_service.Service
cursor*: string cursor*: string
# Forward declaration # Forward declaration
@ -68,14 +65,12 @@ QtObject:
proc newService*( proc newService*(
events: EventEmitter, events: EventEmitter,
threadpool: ThreadPool, threadpool: ThreadPool
chatService: chat_service.Service
): Service = ): Service =
new(result, delete) new(result, delete)
result.QObject.setup result.QObject.setup
result.events = events result.events = events
result.threadpool = threadpool result.threadpool = threadpool
result.chatService = chatService
proc init*(self: Service) = proc init*(self: Service) =
self.asyncActivityNotificationLoad() self.asyncActivityNotificationLoad()
@ -89,6 +84,18 @@ QtObject:
ActivityCenterNotificationsArgs(activityCenterNotifications: receivedData.activityCenterNotifications) 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 = proc hasMoreToShow*(self: Service): bool =
return self.cursor != "" return self.cursor != ""
@ -177,11 +184,7 @@ QtObject:
proc acceptActivityCenterNotifications*(self: Service, notificationIds: seq[string]): string = proc acceptActivityCenterNotifications*(self: Service, notificationIds: seq[string]): string =
try: try:
let response = backend.acceptActivityCenterNotifications(notificationIds) discard backend.acceptActivityCenterNotifications(notificationIds)
let (chats, messages) = self.chatService.parseChatResponse(response)
self.events.emit(chat_service.SIGNAL_CHAT_UPDATE,
ChatUpdateArgs(messages: messages, chats: chats))
except Exception as e: except Exception as e:
error "Error marking as accepted", msg = e.msg error "Error marking as accepted", msg = e.msg

View File

@ -7,6 +7,7 @@ import ../../../app/core/tasks/[qt, threadpool]
import ../../common/types as common_types import ../../common/types as common_types
import ../../common/conversion as service_conversion import ../../common/conversion as service_conversion
import ../activity_center/service as activity_center_service
import ../settings/service as settings_service import ../settings/service as settings_service
import ../network/service as network_service import ../network/service as network_service
import ../visual_identity/service as procs_from_visual_identity_service import ../visual_identity/service as procs_from_visual_identity_service
@ -83,6 +84,7 @@ QtObject:
threadpool: ThreadPool threadpool: ThreadPool
networkService: network_service.Service networkService: network_service.Service
settingsService: settings_service.Service settingsService: settings_service.Service
activityCenterService: activity_center_service.Service
contacts: Table[string, ContactsDto] # [contact_id, ContactsDto] contacts: Table[string, ContactsDto] # [contact_id, ContactsDto]
contactsStatus: Table[string, StatusUpdateDto] # [contact_id, StatusUpdateDto] contactsStatus: Table[string, StatusUpdateDto] # [contact_id, StatusUpdateDto]
receivedIdentityRequests: Table[string, VerificationRequest] # [from_id, VerificationRequest] receivedIdentityRequests: Table[string, VerificationRequest] # [from_id, VerificationRequest]
@ -106,7 +108,8 @@ QtObject:
events: EventEmitter, events: EventEmitter,
threadpool: ThreadPool, threadpool: ThreadPool,
networkService: network_service.Service, networkService: network_service.Service,
settingsService: settings_service.Service settingsService: settings_service.Service,
activityCenterService: activity_center_service.Service,
): Service = ): Service =
new(result, delete) new(result, delete)
result.QObject.setup result.QObject.setup
@ -114,6 +117,7 @@ QtObject:
result.events = events result.events = events
result.networkService = networkService result.networkService = networkService
result.settingsService = settingsService result.settingsService = settingsService
result.activityCenterService = activityCenterService
result.threadpool = threadpool result.threadpool = threadpool
result.contacts = initTable[string, ContactsDto]() result.contacts = initTable[string, ContactsDto]()
result.contactsStatus = initTable[string, StatusUpdateDto]() result.contactsStatus = initTable[string, StatusUpdateDto]()
@ -415,6 +419,7 @@ QtObject:
contact.removed = false contact.removed = false
self.saveContact(contact) self.saveContact(contact)
self.events.emit(SIGNAL_CONTACT_ADDED, ContactArgs(contactId: contact.id)) self.events.emit(SIGNAL_CONTACT_ADDED, ContactArgs(contactId: contact.id))
self.activityCenterService.parseACNotificationResponse(response)
except Exception as e: except Exception as e:
error "an error occurred while accepting contact request", msg=e.msg error "an error occurred while accepting contact request", msg=e.msg
@ -431,6 +436,7 @@ QtObject:
contact.removed = true contact.removed = true
self.saveContact(contact) self.saveContact(contact)
self.events.emit(SIGNAL_CONTACT_REMOVED, ContactArgs(contactId: contact.id)) self.events.emit(SIGNAL_CONTACT_REMOVED, ContactArgs(contactId: contact.id))
self.activityCenterService.parseACNotificationResponse(response)
except Exception as e: except Exception as e:
error "an error occurred while dismissing contact request", msg=e.msg error "an error occurred while dismissing contact request", msg=e.msg

View File

@ -19,8 +19,8 @@ Item {
signal blockClicked() signal blockClicked()
signal profileClicked() signal profileClicked()
width: buttons.width width: Math.max(textItem.width, buttons.width)
height: buttons.height height: Math.max(textItem.height, buttons.height)
StatusBaseText { StatusBaseText {
id: textItem id: textItem

View File

@ -16,14 +16,18 @@ ActivityNotificationMessage {
ctaComponent: ContactRequestCta { ctaComponent: ContactRequestCta {
readonly property string senderId: notification.message.senderId readonly property string senderId: notification.message.senderId
readonly property var contactDetails: Utils.getContactDetailsAsJson(senderId)
pending: notification.message.contactRequestState == Constants.contactRequestStatePending pending: notification.message.contactRequestState == Constants.contactRequestStatePending
accepted: notification.message.contactRequestState == Constants.contactRequestStateAccepted accepted: notification.message.contactRequestState == Constants.contactRequestStateAccepted
dismissed: notification.message.contactRequestState == Constants.contactRequestStateDismissed dismissed: notification.message.contactRequestState == Constants.contactRequestStateDismissed
blocked: root.store.contactsStore.isBlockedContact(senderId) blocked: contactDetails.isBlocked
onAcceptClicked: root.store.contactsStore.acceptContactRequest(senderId) onAcceptClicked: root.store.contactsStore.acceptContactRequest(senderId)
onDeclineClicked: root.store.contactsStore.dismissContactRequest(senderId) onDeclineClicked: root.store.contactsStore.dismissContactRequest(senderId)
onProfileClicked: Global.openProfilePopup(senderId) onProfileClicked: Global.openProfilePopup(senderId)
onBlockClicked: root.store.contactsStore.blockContact(senderId) onBlockClicked: {
root.store.contactsStore.dismissContactRequest(senderId)
root.store.contactsStore.blockContact(senderId)
}
} }
} }