refactor(osnotification): os notification service updated
- os notification doesn't belong to core features so it's moved from there - os notification service updated and read to be used as other service - leftovers moved from `status-lib` that's its version is updated - using os notification service is commented out in the old code
This commit is contained in:
parent
a99422a00a
commit
4b882be8bd
|
@ -1,5 +1,6 @@
|
||||||
import NimQml, os, strformat
|
import NimQml, os, strformat
|
||||||
|
|
||||||
|
import ../../app_service/service/os_notification/service as os_notification_service
|
||||||
import ../../app_service/service/keychain/service as keychain_service
|
import ../../app_service/service/keychain/service as keychain_service
|
||||||
import ../../app_service/service/accounts/service as accounts_service
|
import ../../app_service/service/accounts/service as accounts_service
|
||||||
import ../../app_service/service/contacts/service as contacts_service
|
import ../../app_service/service/contacts/service as contacts_service
|
||||||
|
@ -68,6 +69,7 @@ type
|
||||||
AppController* = ref object of RootObj
|
AppController* = ref object of RootObj
|
||||||
appService: AppService
|
appService: AppService
|
||||||
# Services
|
# Services
|
||||||
|
osNotificationService: os_notification_service.Service
|
||||||
keychainService: keychain_service.Service
|
keychainService: keychain_service.Service
|
||||||
accountsService: accounts_service.Service
|
accountsService: accounts_service.Service
|
||||||
contactsService: contacts_service.Service
|
contactsService: contacts_service.Service
|
||||||
|
@ -133,6 +135,7 @@ proc newAppController*(appService: AppService): AppController =
|
||||||
result = AppController()
|
result = AppController()
|
||||||
result.appService = appService
|
result.appService = appService
|
||||||
# Services
|
# Services
|
||||||
|
result.osNotificationService = os_notification_service.newService(appService.status.events)
|
||||||
result.keychainService = keychain_service.newService(appService.status.events)
|
result.keychainService = keychain_service.newService(appService.status.events)
|
||||||
result.settingService = setting_service.newService()
|
result.settingService = setting_service.newService()
|
||||||
result.settingsService = settings_service.newService()
|
result.settingsService = settings_service.newService()
|
||||||
|
@ -217,6 +220,7 @@ proc newAppController*(appService: AppService): AppController =
|
||||||
#result.connect()
|
#result.connect()
|
||||||
|
|
||||||
proc delete*(self: AppController) =
|
proc delete*(self: AppController) =
|
||||||
|
self.osNotificationService.delete
|
||||||
self.contactsService.delete
|
self.contactsService.delete
|
||||||
self.chatService.delete
|
self.chatService.delete
|
||||||
self.communityService.delete
|
self.communityService.delete
|
||||||
|
|
|
@ -2,7 +2,7 @@ import NimQml, chronicles, tables
|
||||||
import status/chat as chat_model
|
import status/chat as chat_model
|
||||||
import status/messages as messages_model
|
import status/messages as messages_model
|
||||||
import status/[chat, contacts, status, wallet, stickers, settings]
|
import status/[chat, contacts, status, wallet, stickers, settings]
|
||||||
import status/types/[message, transaction, os_notification, setting]
|
import status/types/[message, transaction, setting]
|
||||||
import ../core/[main]
|
import ../core/[main]
|
||||||
import view, views/channels_list, views/message_list, views/reactions, views/stickers as stickers_view
|
import view, views/channels_list, views/message_list, views/reactions, views/stickers as stickers_view
|
||||||
import eventemitter
|
import eventemitter
|
||||||
|
|
|
@ -195,6 +195,8 @@ proc handleMailserverEvents(self: ChatController) =
|
||||||
mailserverWorker.start(task)
|
mailserverWorker.start(task)
|
||||||
|
|
||||||
proc handleSystemEvents(self: ChatController) =
|
proc handleSystemEvents(self: ChatController) =
|
||||||
self.status.events.on("osNotificationClicked") do(e:Args):
|
discard
|
||||||
let arg = OsNotificationsArgs(e)
|
# Not refactored yet - don't delete
|
||||||
self.view.onOsNotificationClicked(arg.details)
|
# self.status.events.on("osNotificationClicked") do(e:Args):
|
||||||
|
# let arg = OsNotificationsArgs(e)
|
||||||
|
# self.view.onOsNotificationClicked(arg.details)
|
|
@ -6,11 +6,10 @@ import status/messages as status_messages
|
||||||
import status/contacts as status_contacts
|
import status/contacts as status_contacts
|
||||||
import status/ens as status_ens
|
import status/ens as status_ens
|
||||||
import status/chat/[chat]
|
import status/chat/[chat]
|
||||||
import status/types/[activity_center_notification, os_notification, rpc_response, profile]
|
import status/types/[activity_center_notification, rpc_response, profile]
|
||||||
import ../core/[main]
|
import ../core/[main]
|
||||||
import ../core/tasks/[qt, threadpool]
|
import ../core/tasks/[qt, threadpool]
|
||||||
import ../core/tasks/marathon/mailserver/worker
|
import ../core/tasks/marathon/mailserver/worker
|
||||||
import status/notifications/[os_notifications]
|
|
||||||
import ../utils/image_utils
|
import ../utils/image_utils
|
||||||
import web3/[conversions, ethtypes]
|
import web3/[conversions, ethtypes]
|
||||||
import views/[channels_list, message_list, chat_item, reactions, stickers, groups, transactions, communities, community_list, community_item, format_input, ens, activity_notification_list, channel, messages, message_item, gif]
|
import views/[channels_list, message_list, chat_item, reactions, stickers, groups, transactions, communities, community_list, community_item, format_input, ens, activity_notification_list, channel, messages, message_item, gif]
|
||||||
|
@ -497,36 +496,45 @@ QtObject:
|
||||||
|
|
||||||
# self.switchTo(info.communityId, info.channelId, info.messageId)
|
# self.switchTo(info.communityId, info.channelId, info.messageId)
|
||||||
|
|
||||||
|
#################################################
|
||||||
|
## Don't delete this part, it's not refactored yet, just commented
|
||||||
|
## OsNotificationService is ready, but not not put in a play.
|
||||||
|
##
|
||||||
|
##
|
||||||
proc notificationClicked*(self:ChatsView, notificationType: int) {.signal.}
|
proc notificationClicked*(self:ChatsView, notificationType: int) {.signal.}
|
||||||
|
|
||||||
proc onOsNotificationClicked*(self: ChatsView, details: OsNotificationDetails) =
|
# proc onOsNotificationClicked*(self: ChatsView, details: OsNotificationDetails) =
|
||||||
# A logic what should be done depends on details.notificationType and should be
|
# # A logic what should be done depends on details.notificationType and should be
|
||||||
# defined here in this method.
|
# # defined here in this method.
|
||||||
# So far if notificationType is:
|
# # So far if notificationType is:
|
||||||
# - NewContactRequest or AcceptedContactRequest we are switching to Chat section
|
# # - NewContactRequest or AcceptedContactRequest we are switching to Chat section
|
||||||
# - JoinCommunityRequest or AcceptedIntoCommunity we are switching to that Community
|
# # - JoinCommunityRequest or AcceptedIntoCommunity we are switching to that Community
|
||||||
# - RejectedByCommunity we are switching to Chat section
|
# # - RejectedByCommunity we are switching to Chat section
|
||||||
# - NewMessage we are switching to appropriate chat/channel and a message inside it
|
# # - NewMessage we are switching to appropriate chat/channel and a message inside it
|
||||||
|
|
||||||
self.switchTo(details.communityId, details.channelId, details.messageId)
|
# self.switchTo(details.communityId, details.channelId, details.messageId)
|
||||||
|
|
||||||
# Notify qml about the changes, cause changing section cannot be performed
|
# # Notify qml about the changes, cause changing section cannot be performed
|
||||||
# completely from the nim side.
|
# # completely from the nim side.
|
||||||
self.notificationClicked(details.notificationType.int)
|
# self.notificationClicked(details.notificationType.int)
|
||||||
|
|
||||||
proc showOSNotification*(self: ChatsView, title: string, message: string,
|
proc showOSNotification*(self: ChatsView, title: string, message: string, notificationType: int, communityId: string,
|
||||||
notificationType: int, communityId: string, channelId: string,
|
channelId: string, messageId: string, useOSNotifications: bool) {.slot.} =
|
||||||
messageId: string, useOSNotifications: bool) {.slot.} =
|
discard
|
||||||
|
# Not refactored yet
|
||||||
|
# let details = OsNotificationDetails(
|
||||||
|
# notificationType: notificationType.OsNotificationType,
|
||||||
|
# communityId: communityId,
|
||||||
|
# channelId: channelId,
|
||||||
|
# messageId: messageId
|
||||||
|
# )
|
||||||
|
|
||||||
let details = OsNotificationDetails(
|
# Once this part gets refactored os notification service from the services will be used
|
||||||
notificationType: notificationType.OsNotificationType,
|
# instead fetching that service from the "core/main"
|
||||||
communityId: communityId,
|
#self.appService.osNotificationService.showNotification(title, message, details, useOSNotifications)
|
||||||
channelId: channelId,
|
##
|
||||||
messageId: messageId
|
##
|
||||||
)
|
#################################################
|
||||||
|
|
||||||
self.appService.osNotificationService.showNotification(title, message,
|
|
||||||
details, useOSNotifications)
|
|
||||||
|
|
||||||
proc handleProtocolUri*(self: ChatsView, uri: string) {.slot.} =
|
proc handleProtocolUri*(self: ChatsView, uri: string) {.slot.} =
|
||||||
# for now this only supports links to 1-1 chats, e.g.
|
# for now this only supports links to 1-1 chats, e.g.
|
||||||
|
|
|
@ -6,24 +6,18 @@ import
|
||||||
./tasks/threadpool,
|
./tasks/threadpool,
|
||||||
./signals/signal_controller
|
./signals/signal_controller
|
||||||
|
|
||||||
import ../../app_service/service/os_notification/service as os_notification_service
|
|
||||||
|
|
||||||
export status_lib_status
|
export status_lib_status
|
||||||
export marathon, task_runner, signal_controller
|
export marathon, task_runner, signal_controller
|
||||||
export os_notification_service
|
|
||||||
|
|
||||||
logScope:
|
logScope:
|
||||||
topics = "app-services"
|
topics = "app-services"
|
||||||
|
|
||||||
type AppService* = ref object
|
type AppService* = ref object # AppService should be renamed to "Foundation"
|
||||||
status*: Status # in one point of time this should be completely removed
|
status*: Status # in one point of time this should be completely removed
|
||||||
# foundation
|
# foundation
|
||||||
threadpool*: ThreadPool
|
threadpool*: ThreadPool
|
||||||
marathon*: Marathon
|
marathon*: Marathon
|
||||||
signalController*: SignalsController
|
signalController*: SignalsController
|
||||||
# services
|
|
||||||
osNotificationService*: OsNotificationService
|
|
||||||
# async services
|
|
||||||
|
|
||||||
proc newAppService*(status: Status, worker: MarathonWorker): AppService =
|
proc newAppService*(status: Status, worker: MarathonWorker): AppService =
|
||||||
result = AppService()
|
result = AppService()
|
||||||
|
@ -31,13 +25,11 @@ proc newAppService*(status: Status, worker: MarathonWorker): AppService =
|
||||||
result.threadpool = newThreadPool()
|
result.threadpool = newThreadPool()
|
||||||
result.marathon = newMarathon(worker)
|
result.marathon = newMarathon(worker)
|
||||||
result.signalController = newSignalsController(status)
|
result.signalController = newSignalsController(status)
|
||||||
result.osNotificationService = newOsNotificationService(status)
|
|
||||||
|
|
||||||
proc delete*(self: AppService) =
|
proc delete*(self: AppService) =
|
||||||
self.threadpool.teardown()
|
self.threadpool.teardown()
|
||||||
self.marathon.teardown()
|
self.marathon.teardown()
|
||||||
self.signalController.delete()
|
self.signalController.delete()
|
||||||
self.osNotificationService.delete()
|
|
||||||
|
|
||||||
proc onLoggedIn*(self: AppService) =
|
proc onLoggedIn*(self: AppService) =
|
||||||
self.marathon.onLoggedIn()
|
self.marathon.onLoggedIn()
|
||||||
|
|
|
@ -10,8 +10,7 @@ import status/profile as status_profile
|
||||||
import status/status
|
import status/status
|
||||||
import status/ens as status_ens
|
import status/ens as status_ens
|
||||||
import status/chat/chat
|
import status/chat/chat
|
||||||
import status/types/[setting, os_notification, profile]
|
import status/types/[setting, profile]
|
||||||
import status/notifications/[os_notifications]
|
|
||||||
|
|
||||||
import ../chat/views/channels_list
|
import ../chat/views/channels_list
|
||||||
import ../../constants
|
import ../../constants
|
||||||
|
@ -173,15 +172,23 @@ QtObject:
|
||||||
QtProperty[QVariant] mutedChats:
|
QtProperty[QVariant] mutedChats:
|
||||||
read = getMutedChats
|
read = getMutedChats
|
||||||
|
|
||||||
proc showOSNotification*(self: ProfileView, title: string, message: string,
|
proc setSendUserStatus*(self: ProfileView, sendUserStatus: bool) {.slot.} =
|
||||||
notificationType: int, useOSNotifications: bool) {.slot.} =
|
if (sendUserStatus == self.profile.sendUserStatus):
|
||||||
|
return
|
||||||
|
self.profile.setSendUserStatus(sendUserStatus)
|
||||||
|
self.status.saveSetting(Setting.SendUserStatus, sendUserStatus)
|
||||||
|
|
||||||
let details = OsNotificationDetails(
|
proc showOSNotification*(self: ProfileView, title: string, message: string, notificationType: int,
|
||||||
notificationType: notificationType.OsNotificationType
|
useOSNotifications: bool) {.slot.} =
|
||||||
)
|
discard
|
||||||
|
# Not refactored yet - don't delete
|
||||||
|
# let details = OsNotificationDetails(
|
||||||
|
# notificationType: notificationType.OsNotificationType
|
||||||
|
# )
|
||||||
|
|
||||||
self.appService.osNotificationService.showNotification(title, message,
|
# Once this part gets refactored os notification service from the services will be used
|
||||||
details, useOSNotifications)
|
# instead fetching that service from the "core/main"
|
||||||
|
#self.appService.osNotificationService.showNotification(title, message, details, useOSNotifications)
|
||||||
|
|
||||||
proc logDir*(self: ProfileView): string {.slot.} =
|
proc logDir*(self: ProfileView): string {.slot.} =
|
||||||
url_fromLocalFile(constants.LOGDIR)
|
url_fromLocalFile(constants.LOGDIR)
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
{.used.}
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
|
type
|
||||||
|
OsNotificationType* {.pure.} = enum
|
||||||
|
NewContactRequest = 1,
|
||||||
|
AcceptedContactRequest,
|
||||||
|
JoinCommunityRequest,
|
||||||
|
AcceptedIntoCommunity,
|
||||||
|
RejectedByCommunity,
|
||||||
|
NewMessage
|
||||||
|
|
||||||
|
OsNotificationDetails* = object
|
||||||
|
notificationType*: OsNotificationType
|
||||||
|
communityId*: string
|
||||||
|
channelId*: string
|
||||||
|
messageId*: string
|
||||||
|
|
||||||
|
proc toOsNotificationDetails*(json: JsonNode): OsNotificationDetails =
|
||||||
|
if (not (json.contains("notificationType") and
|
||||||
|
json.contains("communityId") and
|
||||||
|
json.contains("channelId") and
|
||||||
|
json.contains("messageId"))):
|
||||||
|
return OsNotificationDetails()
|
||||||
|
|
||||||
|
return OsNotificationDetails(
|
||||||
|
notificationType: json{"notificationType"}.getInt.OsNotificationType,
|
||||||
|
communityId: json{"communityId"}.getStr,
|
||||||
|
channelId: json{"channelId"}.getStr,
|
||||||
|
messageId: json{"messageId"}.getStr
|
||||||
|
)
|
||||||
|
|
||||||
|
proc toJsonNode*(self: OsNotificationDetails): JsonNode =
|
||||||
|
result = %* {
|
||||||
|
"notificationType": self.notificationType.int,
|
||||||
|
"communityId": self.communityId,
|
||||||
|
"channelId": self.channelId,
|
||||||
|
"messageId": self.messageId
|
||||||
|
}
|
|
@ -1,33 +1,38 @@
|
||||||
import NimQml, json, chronicles
|
import NimQml, json, chronicles
|
||||||
|
import details
|
||||||
import status/[status]
|
import eventemitter
|
||||||
import status/notifications/[os_notifications]
|
|
||||||
import status/types/[os_notification]
|
|
||||||
|
|
||||||
logScope:
|
logScope:
|
||||||
topics = "os-notification-service"
|
topics = "os-notification-service"
|
||||||
|
|
||||||
|
# Signals which may be emitted by this service:
|
||||||
|
const SIGNAL_OS_NOTIFICATION_CLICKED* = "new-osNotificationClicked" #Once we are done with refactoring we should remove "new-" from all signals
|
||||||
|
|
||||||
|
type
|
||||||
|
OsNotificationsArgs* = ref object of Args
|
||||||
|
details*: OsNotificationDetails
|
||||||
|
|
||||||
QtObject:
|
QtObject:
|
||||||
type OsNotificationService* = ref object of QObject
|
type Service* = ref object of QObject
|
||||||
status: Status
|
events: EventEmitter
|
||||||
notification: StatusOSNotification
|
notification: StatusOSNotification
|
||||||
notificationSetUp: bool
|
|
||||||
|
|
||||||
proc setup(self: OsNotificationService, status: Status) =
|
proc setup(self: Service, events: EventEmitter) =
|
||||||
self.QObject.setup
|
self.QObject.setup
|
||||||
self.status = status
|
self.events = events
|
||||||
|
self.notification = newStatusOSNotification()
|
||||||
|
signalConnect(self.notification, "notificationClicked(QString)", self, "onNotificationClicked(QString)", 2)
|
||||||
|
|
||||||
proc delete*(self: OsNotificationService) =
|
proc delete*(self: Service) =
|
||||||
if self.notificationSetUp:
|
|
||||||
self.notification.delete
|
self.notification.delete
|
||||||
self.QObject.delete
|
self.QObject.delete
|
||||||
|
|
||||||
proc newOsNotificationService*(status: Status): OsNotificationService =
|
proc newService*(events: EventEmitter): Service =
|
||||||
new(result, delete)
|
new(result, delete)
|
||||||
result.setup(status)
|
result.setup(events)
|
||||||
|
|
||||||
proc showNotification*(self: OsNotificationService, title: string,
|
proc showNotification*(self: Service, title: string, message: string, details: OsNotificationDetails,
|
||||||
message: string, details: OsNotificationDetails, useOSNotifications: bool) =
|
useOSNotifications: bool) =
|
||||||
## This method will add new notification to the Notification center. Param
|
## This method will add new notification to the Notification center. Param
|
||||||
## "details" is used to uniquely define a notification bubble.
|
## "details" is used to uniquely define a notification bubble.
|
||||||
|
|
||||||
|
@ -41,12 +46,8 @@ QtObject:
|
||||||
let identifier = $(details.toJsonNode())
|
let identifier = $(details.toJsonNode())
|
||||||
self.notification.showNotification(title, message, identifier)
|
self.notification.showNotification(title, message, identifier)
|
||||||
|
|
||||||
proc onNotificationClicked*(self: OsNotificationService, identifier: string) {.slot.} =
|
proc onNotificationClicked*(self: Service, identifier: string) {.slot.} =
|
||||||
## This slot is called once user clicks a notificaiton bubble, "identifier"
|
## This slot is called once user clicks a notificaiton bubble, "identifier"
|
||||||
## contains data which uniquely define that notification.
|
## contains data which uniquely define that notification.
|
||||||
self.status.osnotifications.onNotificationClicked(identifier)
|
let details = toOsNotificationDetails(parseJson(identifier))
|
||||||
|
self.events.emit(SIGNAL_OS_NOTIFICATION_CLICKED, OsNotificationsArgs(details: details))
|
||||||
proc onLoggedIn*(self: OsNotificationService) =
|
|
||||||
self.notification = newStatusOSNotification()
|
|
||||||
self.notificationSetUp = true
|
|
||||||
signalConnect(self.notification, "notificationClicked(QString)", self, "onNotificationClicked(QString)", 2)
|
|
Loading…
Reference in New Issue