diff --git a/src/app/modules/main/chat_section/module.nim b/src/app/modules/main/chat_section/module.nim index c2edbc05d8..abb63388c3 100644 --- a/src/app/modules/main/chat_section/module.nim +++ b/src/app/modules/main/chat_section/module.nim @@ -130,10 +130,8 @@ method load*(self: Module) = self.view.load() if(self.controller.isCommunity()): - singletonInstance.engine.setRootContextProperty("communitySectionModule", self.viewVariant) self.buildCommunityUI() else: - singletonInstance.engine.setRootContextProperty("chatSectionModule", self.viewVariant) self.buildChatUI() self.inputAreaModule.load() @@ -189,4 +187,7 @@ method activeItemSubItemSet*(self: Module, itemId: string, subItemId: string) = let subItem = item.subItems.getItemById(subItemId) self.view.model().setActiveItemSubItem(itemId, subItemId) - self.view.activeItemSubItemSet(item, subItem) \ No newline at end of file + self.view.activeItemSubItemSet(item, subItem) + +method getChatSection*(self: Module): QVariant = + return self.viewVariant \ No newline at end of file diff --git a/src/app/modules/main/chat_section/private_interfaces/module_access_interface.nim b/src/app/modules/main/chat_section/private_interfaces/module_access_interface.nim index d057a91427..fa88ab80e7 100644 --- a/src/app/modules/main/chat_section/private_interfaces/module_access_interface.nim +++ b/src/app/modules/main/chat_section/private_interfaces/module_access_interface.nim @@ -1,3 +1,5 @@ +import NimQml + method delete*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") @@ -6,3 +8,6 @@ method load*(self: AccessInterface) {.base.} = method isLoaded*(self: AccessInterface): bool {.base.} = raise newException(ValueError, "No implementation available") + +method getChatSection*(self: AccessInterface): QVariant {.base.} = + raise newException(ValueError, "No implementation available") \ No newline at end of file diff --git a/src/app/modules/main/module.nim b/src/app/modules/main/module.nim index 326ee8c955..a4301b6587 100644 --- a/src/app/modules/main/module.nim +++ b/src/app/modules/main/module.nim @@ -275,3 +275,13 @@ method disableSection*[T](self: Module[T], sectionType: SectionType) = method setUserStatus*[T](self: Module[T], status: bool) = self.controller.setUserStatus(status) + +method getChatSection*[T](self: Module[T]): QVariant = + return self.chatSectionModule.getChatSection() + +method getCommunitySection*[T](self: Module[T], communityId: string): QVariant = + if(not self.communitySectionsModule.contains(communityId)): + echo "main-module, unexisting community key: ", communityId + return + + return self.communitySectionsModule[communityId].getChatSection() \ No newline at end of file diff --git a/src/app/modules/main/private_interfaces/module_view_delegate_interface.nim b/src/app/modules/main/private_interfaces/module_view_delegate_interface.nim index 2d07fe6236..d4f668f9aa 100644 --- a/src/app/modules/main/private_interfaces/module_view_delegate_interface.nim +++ b/src/app/modules/main/private_interfaces/module_view_delegate_interface.nim @@ -1,3 +1,4 @@ +import NimQml import ../item method viewDidLoad*(self: AccessInterface) {.base.} = @@ -10,4 +11,10 @@ method setActiveSection*(self: AccessInterface, item: Item) {.base.} = raise newException(ValueError, "No implementation available") method setUserStatus*(self: AccessInterface, status: bool) {.base.} = + raise newException(ValueError, "No implementation available") + +method getChatSection*(self: AccessInterface): QVariant {.base.} = + raise newException(ValueError, "No implementation available") + +method getCommunitySection*(self: AccessInterface, communityId: string): QVariant {.base.} = raise newException(ValueError, "No implementation available") \ No newline at end of file diff --git a/src/app/modules/main/view.nim b/src/app/modules/main/view.nim index 0fe3e0f361..945f3fdac9 100644 --- a/src/app/modules/main/view.nim +++ b/src/app/modules/main/view.nim @@ -10,6 +10,7 @@ QtObject: modelVariant: QVariant activeSection: ActiveSection activeSectionVariant: QVariant + tmpCommunityId: string # shouldn't be used anywhere except in setCommunitySection/getCommunitySection procs proc delete*(self: View) = self.model.delete @@ -99,3 +100,21 @@ QtObject: proc setUserStatus*(self: View, status: bool) {.slot.} = self.delegate.setUserStatus(status) + + # Since we cannot return QVariant from the proc which has arguments, so cannot have proc like this: + # getCommunitySection(self: View, communityId: string): QVariant {.slot.} + # we're using combinaiton of + # setCommunitySection/getCommunitySection procs + proc setCommunitySection*(self: View, communityId: string) {.slot.} = + self.tmpCommunityId = communityId + + proc getCommunitySection*(self: View): QVariant {.slot.} = + var communityVariant = self.delegate.getCommunitySection(self.tmpCommunityId) + self.tmpCommunityId = "" + if(communityVariant.isNil): + return newQVariant() + + return communityVariant + + proc getChatSection*(self: View): QVariant {.slot.} = + return self.delegate.getChatSection() \ No newline at end of file diff --git a/ui/app/AppLayouts/Chat/ChatLayout.qml b/ui/app/AppLayouts/Chat/ChatLayout.qml index 0e9464ee2f..17b93438c2 100644 --- a/ui/app/AppLayouts/Chat/ChatLayout.qml +++ b/ui/app/AppLayouts/Chat/ChatLayout.qml @@ -25,6 +25,8 @@ StatusAppThreePanelLayout { handle: SplitViewHandle { implicitWidth: 5 } + property var chatSectionModule // Everything here, within this component need to be set based on this property. + property var messageStore property alias chatColumn: chatColumn diff --git a/ui/app/AppMain.qml b/ui/app/AppMain.qml index 47c7aaa42a..4d7cbcfef0 100644 --- a/ui/app/AppMain.qml +++ b/ui/app/AppMain.qml @@ -2,6 +2,7 @@ import QtQuick 2.13 import QtQuick.Controls 2.13 import QtQuick.Layouts 1.13 import QtMultimedia 5.13 +import Qt.labs.qmlmodels 1.0 import utils 1.0 import shared 1.0 @@ -360,12 +361,21 @@ Item { } else if(mainModule.activeSection.sectionType === Constants.appSection.community) { - /*************************************/ - // This will be refactored later - chatsModel.communities.setActiveCommunity(mainModule.activeSection.id) - /*************************************/ + for(let i = this.children.length - 1; i >=0; i--) + { + var obj = this.children[i]; + if(obj && obj.sectionId == mainModule.activeSection.id) + { + /*************************************/ + // This will be refactored/removed later + chatsModel.communities.setActiveCommunity(mainModule.activeSection.id) + /*************************************/ - return 99 //Don't know why, but that's how it was in Utils::getAppSectionIndex function. + return i + } + } + + return 0 } else if(mainModule.activeSection.sectionType === Constants.appSection.wallet) { return 1 @@ -423,6 +433,10 @@ Item { onProfileButtonClicked: { appMain.changeAppSectionBySectionType(Constants.appSection.profile); } + + Component.onCompleted: { + chatSectionModule = mainModule.getChatSection() + } } WalletLayout { @@ -496,6 +510,33 @@ Item { Layout.alignment: Qt.AlignLeft | Qt.AlignTop Layout.fillHeight: true } + + Repeater{ + model: mainModule.sectionsModel + + delegate: DelegateChooser { + id: delegateChooser + role: "sectionType" + DelegateChoice { + roleValue: Constants.appSection.community + delegate: ChatLayout { + property string sectionId: model.id + Layout.fillWidth: true + Layout.alignment: Qt.AlignLeft | Qt.AlignTop + Layout.fillHeight: true + + onProfileButtonClicked: { + appMain.changeAppSectionBySectionType(Constants.appSection.profile); + } + + Component.onCompleted: { + mainModule.setCommunitySection(model.id) + chatSectionModule = mainModule.getCommunitySection() + } + } + } + } + } } Connections {