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
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
)

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)
}
}
}