diff --git a/src/app/modules/main/communities/io_interface.nim b/src/app/modules/main/communities/io_interface.nim index 58c4e8246e..5b0edeb3cf 100644 --- a/src/app/modules/main/communities/io_interface.nim +++ b/src/app/modules/main/communities/io_interface.nim @@ -26,6 +26,9 @@ method setCuratedCommunities*(self: AccessInterface, curatedCommunities: seq[Com method getCommunityItem*(self: AccessInterface, community: CommunityDto): SectionItem {.base.} = raise newException(ValueError, "No implementation available") +method navigateToCommunity*(self: AccessInterface, communityId: string) {.base.} = + raise newException(ValueError, "No implementation available") + method spectateCommunity*(self: AccessInterface, communityId: string): string {.base.} = raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/communities/module.nim b/src/app/modules/main/communities/module.nim index 07d69a1b9f..7f88926d28 100644 --- a/src/app/modules/main/communities/module.nim +++ b/src/app/modules/main/communities/module.nim @@ -176,6 +176,13 @@ method communityAdded*(self: Module, community: CommunityDto) = method spectateCommunity*(self: Module, communityId: string): string = self.controller.spectateCommunity(communityId) +method navigateToCommunity*(self: Module, communityId: string) = + let community = self.view.model().getItemById(communityId) + if community.isEmpty() or not (community.spectated() or community.joined()): + discard self.controller.spectateCommunity(communityId) + else: + self.delegate.setActiveSectionById(communityId) + method communityEdited*(self: Module, community: CommunityDto) = self.view.model().editItem(self.getCommunityItem(community)) self.view.communityChanged(community.id) diff --git a/src/app/modules/main/communities/view.nim b/src/app/modules/main/communities/view.nim index 6459738fdb..dac6f4e5c6 100644 --- a/src/app/modules/main/communities/view.nim +++ b/src/app/modules/main/communities/view.nim @@ -76,7 +76,7 @@ QtObject: result.discordChannelsModel = newDiscordChannelsModel() result.discordChannelsModelVariant = newQVariant(result.discordChannelsModel) result.discordOldestMessageTimestamp = 0 - result.discordDataExtractionInProgress = false + result.discordDataExtractionInProgress = false result.discordImportWarningsCount = 0 result.discordImportErrorsCount = 0 result.discordImportProgress = 0 @@ -315,7 +315,10 @@ QtObject: read = getDiscordImportCommunityName notify = discordImportCommunityNameChanged - proc spectateCommunity*(self: View, communityId: string, ensName: string) {.slot.} = + proc navigateToCommunity*(self: View, communityId: string) {.slot.} = + self.delegate.navigateToCommunity(communityId) + + proc spectateCommunity*(self: View, communityId: string) {.slot.} = discard self.delegate.spectateCommunity(communityId) proc createCommunity*(self: View, name: string, diff --git a/src/app/modules/main/io_interface.nim b/src/app/modules/main/io_interface.nim index 97e9502590..b8af6cc030 100644 --- a/src/app/modules/main/io_interface.nim +++ b/src/app/modules/main/io_interface.nim @@ -168,6 +168,9 @@ method storePassword*(self: AccessInterface, password: string) {.base.} = method setActiveSection*(self: AccessInterface, item: SectionItem) {.base.} = raise newException(ValueError, "No implementation available") +method setActiveSectionById*(self: AccessInterface, id: string) {.base.} = + raise newException(ValueError, "No implementation available") + method onChatLeft*(self: AccessInterface, chatId: string) = raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/module.nim b/src/app/modules/main/module.nim index cb2ba2bc29..7959b87695 100644 --- a/src/app/modules/main/module.nim +++ b/src/app/modules/main/module.nim @@ -578,6 +578,10 @@ method setActiveSection*[T](self: Module[T], item: SectionItem) = return self.controller.setActiveSection(item.id) +method setActiveSectionById*[T](self: Module[T], id: string) = + let item = self.view.model().getItemById(id) + self.setActiveSection(item) + proc notifySubModulesAboutChange[T](self: Module[T], sectionId: string) = for cModule in self.channelGroupModules.values: cModule.onActiveSectionChange(sectionId) diff --git a/src/app/modules/main/view.nim b/src/app/modules/main/view.nim index 4ee034d584..87f896a75a 100644 --- a/src/app/modules/main/view.nim +++ b/src/app/modules/main/view.nim @@ -150,8 +150,7 @@ QtObject: self.delegate.setActiveSection(item) proc setActiveSectionById*(self: View, sectionId: string) {.slot.} = - let item = self.model.getItemById(sectionId) - self.delegate.setActiveSection(item) + self.delegate.setActiveSectionById(sectionId) proc setActiveSectionBySectionType*(self: View, sectionType: int) {.slot.} = ## This will try to set a section with passed sectionType to active one, in case of communities the first community diff --git a/storybook/pages/CommunitiesPortalLayoutPage.qml b/storybook/pages/CommunitiesPortalLayoutPage.qml index 5343e7000f..4194205b5f 100644 --- a/storybook/pages/CommunitiesPortalLayoutPage.qml +++ b/storybook/pages/CommunitiesPortalLayoutPage.qml @@ -40,8 +40,8 @@ SplitView { } } - function setActiveCommunity() { - logs.logEvent("CommunitiesStore::setActiveCommunity", ["communityId"], arguments) + function navigateToCommunity() { + logs.logEvent("CommunitiesStore::navigateToCommunity", ["communityId"], arguments) } } diff --git a/ui/app/AppLayouts/CommunitiesPortal/CommunitiesPortalLayout.qml b/ui/app/AppLayouts/CommunitiesPortal/CommunitiesPortalLayout.qml index 00847cdecd..b544570753 100644 --- a/ui/app/AppLayouts/CommunitiesPortal/CommunitiesPortalLayout.qml +++ b/ui/app/AppLayouts/CommunitiesPortal/CommunitiesPortalLayout.qml @@ -52,10 +52,6 @@ StatusSectionLayout { readonly property int preventShadowClipMargin: 40 readonly property bool searchMode: searcher.text.length > 0 - - function navigateToCommunity(communityId) { - root.communitiesStore.setActiveCommunity(communityId) - } } SortFilterProxyModel { @@ -178,7 +174,7 @@ StatusSectionLayout { model: filteredCommunitiesModel searchLayout: d.searchMode - onCardClicked: d.navigateToCommunity(communityId) + onCardClicked: root.communitiesStore.navigateToCommunity(communityId) } StatusBaseText { diff --git a/ui/app/AppLayouts/CommunitiesPortal/stores/CommunitiesStore.qml b/ui/app/AppLayouts/CommunitiesPortal/stores/CommunitiesStore.qml index a62c82afa8..4b795b512d 100644 --- a/ui/app/AppLayouts/CommunitiesPortal/stores/CommunitiesStore.qml +++ b/ui/app/AppLayouts/CommunitiesPortal/stores/CommunitiesStore.qml @@ -88,6 +88,10 @@ QtObject { mainModule.setActiveSectionById(communityId); } + function navigateToCommunity(communityId) { + root.communitiesModuleInst.navigateToCommunity(communityId) + } + function setFileListItems(filePaths) { root.communitiesModuleInst.setFileListItems(filePaths) }