mirror of
https://github.com/status-im/status-desktop.git
synced 2025-01-20 03:20:24 +00:00
refactor(@desktop/general): notifications set for certain app sections
This commit is contained in:
parent
6e3b065d34
commit
b15c348931
@ -288,7 +288,7 @@ proc load(self: AppController) =
|
||||
self.buildAndRegisterUserProfile()
|
||||
|
||||
# load main module
|
||||
self.mainModule.load()
|
||||
self.mainModule.load(self.chatService, self.communityService)
|
||||
|
||||
proc userLoggedIn*(self: AppController) =
|
||||
#################################################
|
||||
|
@ -57,7 +57,7 @@ QtObject:
|
||||
proc getHasNotification(self: ActiveSection): bool {.slot.} =
|
||||
return self.item.hasNotification
|
||||
|
||||
QtProperty[int] hasNotification:
|
||||
QtProperty[bool] hasNotification:
|
||||
read = getHasNotification
|
||||
|
||||
proc getNotificationCount(self: ActiveSection): int {.slot.} =
|
||||
@ -66,10 +66,4 @@ QtObject:
|
||||
QtProperty[int] notificationCount:
|
||||
read = getNotificationCount
|
||||
|
||||
proc getActive(self: ActiveSection): bool {.slot.} =
|
||||
return self.item.active
|
||||
|
||||
QtProperty[int] active:
|
||||
read = getActive
|
||||
|
||||
|
@ -4,6 +4,7 @@ import ../../core/global_singleton
|
||||
import ../../../app_service/service/settings/service_interface as settings_service
|
||||
import ../../../app_service/service/keychain/service as keychain_service
|
||||
import ../../../app_service/service/accounts/service_interface as accounts_service
|
||||
import ../../../app_service/service/chat/service as chat_service
|
||||
import ../../../app_service/service/community/service as community_service
|
||||
|
||||
import eventemitter
|
||||
@ -18,6 +19,7 @@ type
|
||||
settingsService: settings_service.ServiceInterface
|
||||
keychainService: keychain_service.Service
|
||||
accountsService: accounts_service.ServiceInterface
|
||||
chatService: chat_service.ServiceInterface
|
||||
communityService: community_service.ServiceInterface
|
||||
activeSectionId: string
|
||||
|
||||
@ -26,6 +28,7 @@ proc newController*(delegate: io_interface.AccessInterface,
|
||||
settingsService: settings_service.ServiceInterface,
|
||||
keychainService: keychain_service.Service,
|
||||
accountsService: accounts_service.ServiceInterface,
|
||||
chatService: chat_service.ServiceInterface,
|
||||
communityService: community_service.ServiceInterface):
|
||||
Controller =
|
||||
result = Controller()
|
||||
@ -34,6 +37,7 @@ proc newController*(delegate: io_interface.AccessInterface,
|
||||
result.settingsService = settingsService
|
||||
result.keychainService = keychainService
|
||||
result.accountsService = accountsService
|
||||
result.chatService = chatService
|
||||
result.communityService = communityService
|
||||
|
||||
method delete*(self: Controller) =
|
||||
@ -65,7 +69,7 @@ method init*(self: Controller) =
|
||||
## self.delegate.disableSection(sectionType)
|
||||
discard
|
||||
|
||||
method getCommunities*(self: Controller): seq[community_service.CommunityDto] =
|
||||
method getCommunities*(self: Controller): seq[CommunityDto] =
|
||||
return self.communityService.getCommunities()
|
||||
|
||||
method checkForStoringPassword*(self: Controller) =
|
||||
@ -105,7 +109,29 @@ method setActiveSection*(self: Controller, sectionId: string, sectionType: Secti
|
||||
singletonInstance.localAccountSensitiveSettings.setActiveSection(self.activeSectionId)
|
||||
|
||||
self.delegate.activeSectionSet(self.activeSectionId)
|
||||
|
||||
|
||||
method getNumOfNotificaitonsForChat*(self: Controller): tuple[unviewed:int, mentions:int] =
|
||||
result.unviewed = 0
|
||||
result.mentions = 0
|
||||
let chats = self.chatService.getAllChats()
|
||||
for chat in chats:
|
||||
if(chat.chatType == ChatType.Timeline or chat.chatType == ChatType.CommunityChat):
|
||||
continue
|
||||
|
||||
result.unviewed += chat.unviewedMessagesCount
|
||||
result.mentions += chat.unviewedMentionsCount
|
||||
|
||||
method getNumOfNotificaitonsForCommunity*(self: Controller, communityId: string): tuple[unviewed:int, mentions:int] =
|
||||
result.unviewed = 0
|
||||
result.mentions = 0
|
||||
let chats = self.chatService.getAllChats()
|
||||
for chat in chats:
|
||||
if(chat.communityId != communityId):
|
||||
continue
|
||||
|
||||
result.unviewed += chat.unviewedMessagesCount
|
||||
result.mentions += chat.unviewedMentionsCount
|
||||
|
||||
method setUserStatus*(self: Controller, status: bool) =
|
||||
self.settingsService.setSendUserStatus(status)
|
||||
singletonInstance.userProfile.setUserStatus(status)
|
||||
singletonInstance.userProfile.setUserStatus(status)
|
@ -23,5 +23,12 @@ method storePassword*(self: AccessInterface, password: string) {.base.} =
|
||||
method setActiveSection*(self: AccessInterface, sectionId: string, sectionType: SectionType) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method getNumOfNotificaitonsForChat*(self: AccessInterface): tuple[unviewed:int, mentions:int] {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method getNumOfNotificaitonsForCommunity*(self: AccessInterface, communityId: string): tuple[unviewed:int, mentions:int]
|
||||
{.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method setUserStatus*(self: AccessInterface, status: bool) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
@ -1,6 +1,6 @@
|
||||
import NimQml, Tables
|
||||
|
||||
import io_interface, view, controller, item
|
||||
import io_interface, view, controller, item, model
|
||||
import ../../core/global_singleton
|
||||
|
||||
import chat_section/module as chat_section_module
|
||||
@ -9,7 +9,6 @@ import browser_section/module as browser_section_module
|
||||
import profile_section/module as profile_section_module
|
||||
|
||||
import ../../../app_service/service/keychain/service as keychain_service
|
||||
# import ../../../app_service/service/accounts/service_interface as accounts_service
|
||||
import ../../../app_service/service/chat/service as chat_service
|
||||
import ../../../app_service/service/community/service as community_service
|
||||
import ../../../app_service/service/token/service as token_service
|
||||
@ -74,31 +73,18 @@ proc newModule*[T](
|
||||
result.view = view.newView(result)
|
||||
result.viewVariant = newQVariant(result.view)
|
||||
result.controller = controller.newController(result, events, settingsService, keychainService, accountsService,
|
||||
communityService)
|
||||
chatService, communityService)
|
||||
result.moduleLoaded = false
|
||||
|
||||
# Submodules
|
||||
result.chatSectionModule = chat_section_module.newModule(result, "chat",
|
||||
false, chatService, communityService)
|
||||
result.chatSectionModule = chat_section_module.newModule(result, "chat", false, chatService, communityService)
|
||||
result.communitySectionsModule = initOrderedTable[string, chat_section_module.AccessInterface]()
|
||||
let communities = result.controller.getCommunities()
|
||||
for c in communities:
|
||||
result.communitySectionsModule[c.id] = chat_section_module.newModule(
|
||||
result, c.id, true, chatService, communityService
|
||||
)
|
||||
|
||||
result.walletSectionModule = wallet_section_module.newModule[Module[T]](
|
||||
result,
|
||||
events,
|
||||
tokenService,
|
||||
transactionService,
|
||||
collectible_service,
|
||||
walletAccountService,
|
||||
settingService
|
||||
)
|
||||
|
||||
result.browserSectionModule = browser_section_module.newModule(result, bookmarkService, settingsService, dappPermissionsService, providerService)
|
||||
result.profileSectionModule = profile_section_module.newModule(result, events, accountsService, settingsService, profileService, contactsService, aboutService, languageService, mnemonicService, privacyService)
|
||||
result.walletSectionModule = wallet_section_module.newModule[Module[T]](result, events, tokenService,
|
||||
transactionService, collectible_service, walletAccountService, settingService)
|
||||
result.browserSectionModule = browser_section_module.newModule(result, bookmarkService, settingsService,
|
||||
dappPermissionsService, providerService)
|
||||
result.profileSectionModule = profile_section_module.newModule(result, events, accountsService, settingsService,
|
||||
profileService, contactsService, aboutService, languageService, mnemonicService, privacyService)
|
||||
|
||||
method delete*[T](self: Module[T]) =
|
||||
self.chatSectionModule.delete
|
||||
@ -112,25 +98,37 @@ method delete*[T](self: Module[T]) =
|
||||
self.viewVariant.delete
|
||||
self.controller.delete
|
||||
|
||||
method load*[T](self: Module[T]) =
|
||||
method load*[T](self: Module[T], chatService: chat_service.Service,
|
||||
communityService: community_service.Service) =
|
||||
singletonInstance.engine.setRootContextProperty("mainModule", self.viewVariant)
|
||||
self.controller.init()
|
||||
self.view.load()
|
||||
|
||||
# Create community modules here, since we don't know earlier how many communities we have.
|
||||
let communities = self.controller.getCommunities()
|
||||
for c in communities:
|
||||
self.communitySectionsModule[c.id] = chat_section_module.newModule(self, c.id, true, chatService, communityService)
|
||||
|
||||
var activeSection: Item
|
||||
var activeSectionId = singletonInstance.localAccountSensitiveSettings.getActiveSection()
|
||||
|
||||
# Chat Section
|
||||
let chatSectionItem = initItem("chat", SectionType.Chat, "Chat", "", "chat", "", false, 0, true)
|
||||
let (unviewedCount, mentionsCount) = self.controller.getNumOfNotificaitonsForChat()
|
||||
let hasNotification = unviewedCount > 0 or mentionsCount > 0
|
||||
let notificationsCount = mentionsCount
|
||||
let chatSectionItem = initItem("chat", SectionType.Chat, "Chat", "", "chat", "", hasNotification, notificationsCount,
|
||||
false, true)
|
||||
self.view.addItem(chatSectionItem)
|
||||
if(activeSectionId == chatSectionItem.id):
|
||||
activeSection = chatSectionItem
|
||||
|
||||
# Community Section
|
||||
let communities = self.controller.getCommunities()
|
||||
for c in communities:
|
||||
let communitySectionItem = initItem(c.id, SectionType.Community, c.name, c.images.thumbnail, "", c.color, false, 0,
|
||||
false, singletonInstance.localAccountSensitiveSettings.getCommunitiesEnabled())
|
||||
let (unviewedCount, mentionsCount) = self.controller.getNumOfNotificaitonsForCommunity(c.id)
|
||||
let hasNotification = unviewedCount > 0 or mentionsCount > 0
|
||||
let notificationsCount = mentionsCount # we need to add here number of requests
|
||||
let communitySectionItem = initItem(c.id, SectionType.Community, c.name, c.images.thumbnail, "", c.color,
|
||||
hasNotification, notificationsCount, false, singletonInstance.localAccountSensitiveSettings.getCommunitiesEnabled())
|
||||
self.view.addItem(communitySectionItem)
|
||||
if(activeSectionId == communitySectionItem.id):
|
||||
activeSection = communitySectionItem
|
||||
@ -249,19 +247,26 @@ method emitStoringPasswordSuccess*[T](self: Module[T]) =
|
||||
|
||||
method setActiveSection*[T](self: Module[T], item: Item) =
|
||||
if(item.isEmpty()):
|
||||
echo "section is empty and cannot be made an active one"
|
||||
echo "section is empty and cannot be made as active one"
|
||||
return
|
||||
|
||||
self.controller.setActiveSection(item.id, item.sectionType)
|
||||
|
||||
method activeSectionSet*[T](self: Module[T], sectionId: string) =
|
||||
self.view.activeSectionSet(sectionId)
|
||||
let item = self.view.model().getItemById(sectionId)
|
||||
if(item.isEmpty()):
|
||||
# should never be here
|
||||
echo "main-module, incorrect section id: ", sectionId
|
||||
return
|
||||
|
||||
self.view.model().setActiveSection(sectionId)
|
||||
self.view.activeSectionSet(item)
|
||||
|
||||
method enableSection*[T](self: Module[T], sectionType: SectionType) =
|
||||
self.view.enableSection(sectionType)
|
||||
self.view.model().enableSection(sectionType)
|
||||
|
||||
method disableSection*[T](self: Module[T], sectionType: SectionType) =
|
||||
self.view.disableSection(sectionType)
|
||||
|
||||
method setUserStatus*[T](self: Module[T], status: bool) =
|
||||
self.controller.setUserStatus(status)
|
||||
self.controller.setUserStatus(status)
|
||||
|
@ -1,7 +1,11 @@
|
||||
import ../../../../app_service/service/chat/service as chat_service
|
||||
import ../../../../app_service/service/community/service as community_service
|
||||
|
||||
method delete*(self: AccessInterface) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method load*(self: AccessInterface) {.base.} =
|
||||
method load*(self: AccessInterface, chatService: chat_service.Service, communityService: community_service.Service,)
|
||||
{.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method checkForStoringPassword*(self: AccessInterface) {.base.} =
|
||||
|
@ -34,6 +34,9 @@ QtObject:
|
||||
proc addItem*(self: View, item: Item) =
|
||||
self.model.addItem(item)
|
||||
|
||||
proc model*(self: View): Model =
|
||||
return self.model
|
||||
|
||||
proc modelChanged*(self: View) {.signal.}
|
||||
|
||||
proc getModel(self: View): QVariant {.slot.} =
|
||||
@ -70,12 +73,8 @@ QtObject:
|
||||
read = getActiveSection
|
||||
notify = activeSectionChanged
|
||||
|
||||
proc activeSectionSet*(self: View, sectionId: string) =
|
||||
self.model.setActiveSection(sectionId)
|
||||
|
||||
let item = self.model.getItemById(sectionId)
|
||||
proc activeSectionSet*(self: View, item: Item) =
|
||||
self.activeSection.setActiveSectionData(item)
|
||||
|
||||
self.activeSectionChanged()
|
||||
|
||||
proc setActiveSectionById*(self: View, sectionId: string) {.slot.} =
|
||||
@ -99,4 +98,4 @@ QtObject:
|
||||
self.model.disableSection(sectionType)
|
||||
|
||||
proc setUserStatus*(self: View, status: bool) {.slot.} =
|
||||
self.delegate.setUserStatus(status)
|
||||
self.delegate.setUserStatus(status)
|
||||
|
@ -23,8 +23,7 @@ method init*(self: Service) =
|
||||
try:
|
||||
let response = status_go.getChats()
|
||||
|
||||
let chats = map(response.result.getElems(),
|
||||
proc(x: JsonNode): ChatDto = x.toChatDto())
|
||||
let chats = map(response.result.getElems(), proc(x: JsonNode): ChatDto = x.toChatDto())
|
||||
|
||||
for chat in chats:
|
||||
if chat.active and chat.chatType != ChatType.Unknown:
|
||||
@ -33,4 +32,8 @@ method init*(self: Service) =
|
||||
except Exception as e:
|
||||
let errDesription = e.msg
|
||||
error "error: ", errDesription
|
||||
return
|
||||
return
|
||||
|
||||
method getAllChats*(self: Service): seq[ChatDto] =
|
||||
return toSeq(self.chats.values)
|
||||
|
||||
|
@ -11,3 +11,7 @@ method delete*(self: ServiceInterface) {.base.} =
|
||||
|
||||
method init*(self: ServiceInterface) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method getAllChats*(self: ServiceInterface): seq[ChatDto] {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
|
@ -19,7 +19,7 @@ type Chat* = object
|
||||
color*: string
|
||||
emoji*: string
|
||||
description*: string
|
||||
#members*: seq[ChatMember] ???? It's always null and a question why do we need it here within this context ????
|
||||
#members*: seq[ChatMember] ???? It's always null and a question is why do we need it here within this context ????
|
||||
permissions*: Permission
|
||||
canPost*: bool
|
||||
position*: int
|
||||
@ -82,7 +82,7 @@ proc toChat(jsonObj: JsonNode): Chat =
|
||||
result.permissions = toPermission(permissionObj)
|
||||
discard jsonObj.getProp("canPost", result.canPost)
|
||||
discard jsonObj.getProp("position", result.position)
|
||||
discard jsonObj.getProp("categoryId", result.categoryId)
|
||||
discard jsonObj.getProp("categoryID", result.categoryId)
|
||||
|
||||
proc toCategory(jsonObj: JsonNode): Category =
|
||||
result = Category()
|
||||
|
Loading…
x
Reference in New Issue
Block a user