refactor(general): chat section modules notified about the section change

This commit is contained in:
Sale Djenic 2021-11-09 15:13:01 +01:00
parent fd3303a4e8
commit 9045b0bbc4
8 changed files with 94 additions and 27 deletions

View File

@ -0,0 +1,27 @@
const CHAT_SECTION_ID* = "chat"
const CHAT_SECTION_NAME* = "Chat"
const CHAT_SECTION_ICON* = "chat"
const WALLET_SECTION_ID* = "wallet"
const WALLET_SECTION_NAME* = "Wallet"
const WALLET_SECTION_ICON* = "wallet"
const WALLETV2_SECTION_ID* = "walletV2"
const WALLETV2_SECTION_NAME* = "WalletV2"
const WALLETV2_SECTION_ICON* = "cancel"
const BROWSER_SECTION_ID* = "browser"
const BROWSER_SECTION_NAME* = "Browser"
const BROWSER_SECTION_ICON* = "browser"
const TIMELINE_SECTION_ID* = "timeline"
const TIMELINE_SECTION_NAME* = "Timeline"
const TIMELINE_SECTION_ICON* = "status-update"
const NODEMANAGEMENT_SECTION_ID* = "nodeManagement"
const NODEMANAGEMENT_SECTION_NAME* = "Node Management"
const NODEMANAGEMENT_SECTION_ICON* = "node"
const SETTINGS_SECTION_ID* = "profileSettings"
const SETTINGS_SECTION_NAME* = "Settings"
const SETTINGS_SECTION_ICON* = "status-update"

View File

@ -12,7 +12,7 @@ export controller_interface
type
Controller* = ref object of controller_interface.AccessInterface
delegate: io_interface.AccessInterface
id: string
sectionId: string
isCommunityModule: bool
activeItemId: string
activeSubItemId: string
@ -20,13 +20,13 @@ type
communityService: community_service.ServiceInterface
messageService: message_service.Service
proc newController*(delegate: io_interface.AccessInterface, id: string, isCommunity: bool,
proc newController*(delegate: io_interface.AccessInterface, sectionId: string, isCommunity: bool,
chatService: chat_service.ServiceInterface,
communityService: community_service.ServiceInterface,
messageService: message_service.Service): Controller =
result = Controller()
result.delegate = delegate
result.id = id
result.sectionId = sectionId
result.isCommunityModule = isCommunity
result.chatService = chatService
result.communityService = communityService
@ -38,8 +38,14 @@ method delete*(self: Controller) =
method init*(self: Controller) =
discard
method getId*(self: Controller): string =
return self.id
method getMySectionId*(self: Controller): string =
return self.sectionId
method getActiveChatId*(self: Controller): string =
if(self.activeSubItemId.len > 0):
return self.activeSubItemId
else:
return self.activeItemId
method isCommunity*(self: Controller): bool =
return self.isCommunityModule
@ -64,10 +70,7 @@ method setActiveItemSubItem*(self: Controller, itemId: string, subItemId: string
self.activeItemId = itemId
self.activeSubItemId = subItemId
if(self.activeSubItemId.len > 0):
self.messageService.loadInitialMessagesForChat(self.activeSubItemId)
else:
self.messageService.loadInitialMessagesForChat(self.activeItemId)
self.messageService.asyncLoadInitialMessagesForChat(self.getActiveChatId())
# We need to take other actions here like notify status go that unviewed mentions count is updated and so...

View File

@ -11,7 +11,10 @@ method delete*(self: AccessInterface) {.base.} =
method init*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method getId*(self: AccessInterface): string {.base.} =
method getMySectionId*(self: AccessInterface): string {.base.} =
raise newException(ValueError, "No implementation available")
method getActiveChatId*(self: AccessInterface): string {.base.} =
raise newException(ValueError, "No implementation available")
method isCommunity*(self: AccessInterface): bool {.base.} =

View File

@ -26,7 +26,7 @@ type
chatContentModule: OrderedTable[string, chat_content_module.AccessInterface]
moduleLoaded: bool
proc newModule*(delegate: delegate_interface.AccessInterface, events: EventEmitter, id: string, isCommunity: bool,
proc newModule*(delegate: delegate_interface.AccessInterface, events: EventEmitter, sectionId: string, isCommunity: bool,
chatService: chat_service.Service, communityService: community_service.Service,
messageService: message_service.Service):
Module =
@ -34,7 +34,8 @@ proc newModule*(delegate: delegate_interface.AccessInterface, events: EventEmitt
result.delegate = delegate
result.view = view.newView(result)
result.viewVariant = newQVariant(result.view)
result.controller = controller.newController(result, id, isCommunity, chatService, communityService, messageService)
result.controller = controller.newController(result, sectionId, isCommunity, chatService, communityService,
messageService)
result.moduleLoaded = false
result.chatContentModule = initOrderedTable[string, chat_content_module.AccessInterface]()
@ -185,6 +186,8 @@ method activeItemSubItemSet*(self: Module, itemId: string, subItemId: string) =
self.view.model().setActiveItemSubItem(itemId, subItemId)
self.view.activeItemSubItemSet(item, subItem)
self.delegate.onActiveChatChange(self.controller.getMySectionId(), self.controller.getActiveChatId())
method getModuleAsVariant*(self: Module): QVariant =
return self.viewVariant
@ -193,4 +196,10 @@ method getChatContentModule*(self: Module, chatId: string): QVariant =
error "unexisting chat key: ", chatId
return
return self.chatContentModule[chatId].getModuleAsVariant()
return self.chatContentModule[chatId].getModuleAsVariant()
method onActiveSectionChange*(self: Module, sectionId: string) =
if(sectionId != self.controller.getMySectionId()):
return
self.delegate.onActiveChatChange(self.controller.getMySectionId(), self.controller.getActiveChatId())

View File

@ -17,4 +17,7 @@ method isLoaded*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")
method getModuleAsVariant*(self: AccessInterface): QVariant {.base.} =
raise newException(ValueError, "No implementation available")
method onActiveSectionChange*(self: AccessInterface, sectionId: string) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -110,7 +110,6 @@ method setActiveSection*(self: Controller, sectionId: string, sectionType: Secti
if(sectionType == SectionType.Chat or sectionType != SectionType.Community):
# We need to take other actions here, in case of Chat or Community sections like
# notify status go that unviewed mentions count is updated and so...
# and then in case all is good, notify the view about the chage so it can update the UI
echo "deal with appropriate service..."
singletonInstance.localAccountSensitiveSettings.setActiveSection(self.activeSectionId)

View File

@ -1,6 +1,7 @@
import NimQml, Tables
import io_interface, view, controller, item, model
import ../../boot/app_sections_config as conf
import ../../core/global_singleton
import chat_section/module as chat_section_module
@ -70,7 +71,7 @@ proc newModule*[T](
mnemonicService: mnemonic_service.ServiceInterface,
privacyService: privacy_service.ServiceInterface,
providerService: provider_service.ServiceInterface
): Module[T] =
): Module[T] =
result = Module[T]()
result.delegate = delegate
result.view = view.newView(result)
@ -80,8 +81,8 @@ proc newModule*[T](
result.moduleLoaded = false
# Submodules
result.chatSectionModule = chat_section_module.newModule(result, events, "chat", false, chatService, communityService,
messageService)
result.chatSectionModule = chat_section_module.newModule(result, events, conf.CHAT_SECTION_ID, false, chatService,
communityService, messageService)
result.communitySectionsModule = initOrderedTable[string, chat_section_module.AccessInterface]()
result.walletSectionModule = wallet_section_module.newModule[Module[T]](result, events, tokenService,
transactionService, collectible_service, walletAccountService, settingService)
@ -121,7 +122,8 @@ method load*[T](self: Module[T], events: EventEmitter, chatService: chat_service
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,
let chatSectionItem = initItem(conf.CHAT_SECTION_ID, SectionType.Chat, conf.CHAT_SECTION_NAME, "",
conf.CHAT_SECTION_ICON, "", hasNotification, notificationsCount,
false, true)
self.view.addItem(chatSectionItem)
if(activeSectionId == chatSectionItem.id):
@ -139,43 +141,48 @@ method load*[T](self: Module[T], events: EventEmitter, chatService: chat_service
activeSection = communitySectionItem
# Wallet Section
let walletSectionItem = initItem("wallet", SectionType.Wallet, "Wallet", "", "wallet", "", false, 0, false,
let walletSectionItem = initItem(conf.WALLET_SECTION_ID, SectionType.Wallet, conf.WALLET_SECTION_NAME, "",
conf.WALLET_SECTION_ICON, "", false, 0, false,
singletonInstance.localAccountSensitiveSettings.getIsWalletEnabled())
self.view.addItem(walletSectionItem)
if(activeSectionId == walletSectionItem.id):
activeSection = walletSectionItem
# WalletV2 Section
let walletV2SectionItem = initItem("walletV2", SectionType.WalletV2, "WalletV2", "", "cancel", "", false, 0, false,
let walletV2SectionItem = initItem(conf.WALLETV2_SECTION_ID, SectionType.WalletV2, conf.WALLETV2_SECTION_NAME, "",
conf.WALLETV2_SECTION_ICON, "", false, 0, false,
singletonInstance.localAccountSensitiveSettings.getIsWalletV2Enabled())
self.view.addItem(walletV2SectionItem)
if(activeSectionId == walletV2SectionItem.id):
activeSection = walletV2SectionItem
# Browser Section
let browserSectionItem = initItem("browser", SectionType.Browser, "Browser", "", "browser", "", false, 0, false,
let browserSectionItem = initItem(conf.BROWSER_SECTION_ID, SectionType.Browser, conf.BROWSER_SECTION_NAME, "",
conf.BROWSER_SECTION_ICON, "", false, 0, false,
singletonInstance.localAccountSensitiveSettings.getIsBrowserEnabled())
self.view.addItem(browserSectionItem)
if(activeSectionId == browserSectionItem.id):
activeSection = browserSectionItem
# Timeline Section
let timelineSectionItem = initItem("timeline", SectionType.Timeline, "Timeline", "", "status-update", "", false, 0,
let timelineSectionItem = initItem(conf.TIMELINE_SECTION_ID, SectionType.Timeline, conf.TIMELINE_SECTION_NAME, "",
conf.TIMELINE_SECTION_ICON, "", false, 0,
false, singletonInstance.localAccountSensitiveSettings.getTimelineEnabled())
self.view.addItem(timelineSectionItem)
if(activeSectionId == timelineSectionItem.id):
activeSection = timelineSectionItem
# Node Management Section
let nodeManagementSectionItem = initItem("nodeManagement", SectionType.NodeManagement, "Node Management", "", "node",
"", false, 0, false, singletonInstance.localAccountSensitiveSettings.getNodeManagementEnabled())
let nodeManagementSectionItem = initItem(conf.NODEMANAGEMENT_SECTION_ID, SectionType.NodeManagement,
conf.NODEMANAGEMENT_SECTION_NAME, "", conf.NODEMANAGEMENT_SECTION_ICON, "", false, 0, false,
singletonInstance.localAccountSensitiveSettings.getNodeManagementEnabled())
self.view.addItem(nodeManagementSectionItem)
if(activeSectionId == nodeManagementSectionItem.id):
activeSection = nodeManagementSectionItem
# Profile Section
let profileSettingsSectionItem = initItem("profileSettings", SectionType.ProfileSettings, "Settings", "",
"status-update", "", false, 0, false, true)
let profileSettingsSectionItem = initItem(conf.SETTINGS_SECTION_ID, SectionType.ProfileSettings,
conf.SETTINGS_SECTION_NAME, "", conf.SETTINGS_SECTION_ICON, "", false, 0, false, true)
self.view.addItem(profileSettingsSectionItem)
if(activeSectionId == profileSettingsSectionItem.id):
activeSection = profileSettingsSectionItem
@ -257,6 +264,14 @@ method setActiveSection*[T](self: Module[T], item: Item) =
self.controller.setActiveSection(item.id, item.sectionType)
proc notifySubModulesAboutChange[T](self: Module[T], sectionId: string) =
self.chatSectionModule.onActiveSectionChange(sectionId)
for cModule in self.communitySectionsModule.values:
cModule.onActiveSectionChange(sectionId)
# If there is a need other section may be notified the same way from here...
method activeSectionSet*[T](self: Module[T], sectionId: string) =
let item = self.view.model().getItemById(sectionId)
if(item.isEmpty()):
@ -267,6 +282,8 @@ method activeSectionSet*[T](self: Module[T], sectionId: string) =
self.view.model().setActiveSection(sectionId)
self.view.activeSectionSet(item)
self.notifySubModulesAboutChange(sectionId)
method enableSection*[T](self: Module[T], sectionType: SectionType) =
self.view.model().enableSection(sectionType)
@ -284,4 +301,7 @@ method getCommunitySectionModule*[T](self: Module[T], communityId: string): QVar
echo "main-module, unexisting community key: ", communityId
return
return self.communitySectionsModule[communityId].getModuleAsVariant()
return self.communitySectionsModule[communityId].getModuleAsVariant()
method onActiveChatChange*[T](self: Module[T], sectionId: string, chatId: string) =
discard

View File

@ -1,2 +1,5 @@
method chatSectionDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method onActiveChatChange*(self: AccessInterface, sectionId: string, chatId: string) {.base.} =
raise newException(ValueError, "No implementation available")