fix(@desktop/sections): do not unload chat and communities sections during the switching between the sections

This commit is contained in:
mprakhov 2023-03-17 19:58:07 +01:00 committed by Mykhailo Prakhov
parent 8ef495c604
commit 8d955265dc
7 changed files with 58 additions and 18 deletions

View File

@ -40,6 +40,8 @@ type
BannedMembersModel BannedMembersModel
Encrypted Encrypted
CommunityTokensModel CommunityTokensModel
DeclinedMemberRequestsModel
AmIBanned
QtObject: QtObject:
type type
@ -109,6 +111,8 @@ QtObject:
ModelRole.BannedMembersModel.int:"bannedMembers", ModelRole.BannedMembersModel.int:"bannedMembers",
ModelRole.Encrypted.int:"encrypted", ModelRole.Encrypted.int:"encrypted",
ModelRole.CommunityTokensModel.int:"communityTokens", ModelRole.CommunityTokensModel.int:"communityTokens",
ModelRole.DeclinedMemberRequestsModel.int:"declinedMemberRequests",
ModelRole.AmIBanned.int:"amIBanned"
}.toTable }.toTable
method data(self: SectionModel, index: QModelIndex, role: int): QVariant = method data(self: SectionModel, index: QModelIndex, role: int): QVariant =
@ -186,6 +190,10 @@ QtObject:
result = newQVariant(item.encrypted) result = newQVariant(item.encrypted)
of ModelRole.CommunityTokensModel: of ModelRole.CommunityTokensModel:
result = newQVariant(item.communityTokens) result = newQVariant(item.communityTokens)
of ModelRole.DeclinedMemberRequestsModel:
result = newQVariant(item.declinedMemberRequests)
of ModelRole.AmIBanned:
result = newQVariant(item.amIBanned)
proc isItemExist(self: SectionModel, id: string): bool = proc isItemExist(self: SectionModel, id: string): bool =
for it in self.items: for it in self.items:
@ -278,7 +286,9 @@ QtObject:
ModelRole.PinMessageAllMembersEnabled.int, ModelRole.PinMessageAllMembersEnabled.int,
ModelRole.BannedMembersModel.int, ModelRole.BannedMembersModel.int,
ModelRole.Encrypted.int, ModelRole.Encrypted.int,
ModelRole.CommunityTokensModel.int ModelRole.CommunityTokensModel.int,
ModelRole.DeclinedMemberRequestsModel.int,
ModelRole.AmIBanned.int
]) ])
proc getNthEnabledItem*(self: SectionModel, nth: int): SectionItem = proc getNthEnabledItem*(self: SectionModel, nth: int): SectionItem =

View File

@ -1,7 +1,7 @@
from scripts.global_names import * from scripts.global_names import *
# Main: # Main:
mainWindow_communityColumnView_CommunityColumnView = {"container": statusDesktop_mainWindow, "objectName": "communityColumnView", "type": "CommunityColumnView"} mainWindow_communityColumnView_CommunityColumnView = {"container": statusDesktop_mainWindow, "objectName": "communityColumnView", "type": "CommunityColumnView", "visible": True}
mainWindow_communityHeader_StatusChatInfoButton = {"container": statusDesktop_mainWindow, "objectName": "communityHeaderButton", "type": "StatusChatInfoButton", "visible": True} mainWindow_communityHeader_StatusChatInfoButton = {"container": statusDesktop_mainWindow, "objectName": "communityHeaderButton", "type": "StatusChatInfoButton", "visible": True}
community_ChatInfo_Name_Text = {"container": mainWindow_communityHeader_StatusChatInfoButton, "objectName": "statusChatInfoButtonNameText", "type": "StatusBaseText", "visible": True} community_ChatInfo_Name_Text = {"container": mainWindow_communityHeader_StatusChatInfoButton, "objectName": "statusChatInfoButtonNameText", "type": "StatusBaseText", "visible": True}
mainWindow_createChannelOrCategoryBtn_StatusBaseText = {"container": statusDesktop_mainWindow, "objectName": "createChannelOrCategoryBtn", "type": "StatusBaseText", "visible": True} mainWindow_createChannelOrCategoryBtn_StatusBaseText = {"container": statusDesktop_mainWindow, "objectName": "createChannelOrCategoryBtn", "type": "StatusBaseText", "visible": True}

View File

@ -18,6 +18,8 @@ StackLayout {
readonly property var contactsStore: rootStore.contactsStore readonly property var contactsStore: rootStore.contactsStore
readonly property var permissionsStore: rootStore.permissionsStore readonly property var permissionsStore: rootStore.permissionsStore
property var sectionItemModel
property var emojiPopup property var emojiPopup
property var stickersPopup property var stickersPopup
signal importCommunityClicked() signal importCommunityClicked()
@ -34,7 +36,7 @@ StackLayout {
MembershipRequestsPopup { MembershipRequestsPopup {
anchors.centerIn: parent anchors.centerIn: parent
store: root.rootStore store: root.rootStore
communityData: store.mainModuleInst ? store.mainModuleInst.activeSection || {} : {} communityData: sectionItemModel
onClosed: { onClosed: {
destroy() destroy()
} }
@ -51,7 +53,7 @@ StackLayout {
id: joinCommunityViewComponent id: joinCommunityViewComponent
JoinCommunityView { JoinCommunityView {
id: joinCommunityView id: joinCommunityView
readonly property var communityData: root.rootStore.mainModuleInst ? root.rootStore.mainModuleInst.activeSection || {} : {} readonly property var communityData: sectionItemModel
name: communityData.name name: communityData.name
communityDesc: communityData.description communityDesc: communityData.description
color: communityData.color color: communityData.color
@ -94,6 +96,7 @@ StackLayout {
stickersPopup: root.stickersPopup stickersPopup: root.stickersPopup
contactsStore: root.contactsStore contactsStore: root.contactsStore
rootStore: root.rootStore rootStore: root.rootStore
sectionItemModel: root.sectionItemModel
membershipRequestPopup: membershipRequestPopupComponent membershipRequestPopup: membershipRequestPopupComponent
onCommunityInfoButtonClicked: root.currentIndex = 1 onCommunityInfoButtonClicked: root.currentIndex = 1
@ -122,8 +125,7 @@ StackLayout {
hasAddedContacts: root.contactsStore.myContactsModel.count > 0 hasAddedContacts: root.contactsStore.myContactsModel.count > 0
chatCommunitySectionModule: root.rootStore.chatCommunitySectionModule chatCommunitySectionModule: root.rootStore.chatCommunitySectionModule
community: root.rootStore.mainModuleInst ? root.rootStore.mainModuleInst.activeSection community: sectionItemModel
|| ({}) : ({})
onBackToCommunityClicked: root.currentIndex = 0 onBackToCommunityClicked: root.currentIndex = 0

View File

@ -28,6 +28,7 @@ StatusSectionLayout {
property bool hasAddedContacts: root.contactsStore.myContactsModel.count > 0 property bool hasAddedContacts: root.contactsStore.myContactsModel.count > 0
property RootStore rootStore property RootStore rootStore
property var sectionItemModel
property Component membershipRequestPopup property Component membershipRequestPopup
property var emojiPopup property var emojiPopup
@ -156,6 +157,7 @@ StatusSectionLayout {
id: communtiyColumnComponent id: communtiyColumnComponent
CommunityColumnView { CommunityColumnView {
communitySectionModule: root.rootStore.chatCommunitySectionModule communitySectionModule: root.rootStore.chatCommunitySectionModule
communityData: sectionItemModel
store: root.rootStore store: root.rootStore
emojiPopup: root.emojiPopup emojiPopup: root.emojiPopup
hasAddedContacts: root.hasAddedContacts hasAddedContacts: root.hasAddedContacts

View File

@ -32,7 +32,7 @@ Item {
property var store property var store
property bool hasAddedContacts: false property bool hasAddedContacts: false
property var communityData: store.mainModuleInst ? store.mainModuleInst.activeSection || ({}) : ({}) property var communityData
property Component membershipRequestPopup property Component membershipRequestPopup
signal infoButtonClicked signal infoButtonClicked

View File

@ -42,8 +42,8 @@ StatusSectionLayout {
// {name: qsTr("Token sales"), icon: "token-sale"}, // {name: qsTr("Token sales"), icon: "token-sale"},
// {name: qsTr("Subscriptions"), icon: "subscription"}, // {name: qsTr("Subscriptions"), icon: "subscription"},
property var rootStore property var rootStore
property var community
property var chatCommunitySectionModule property var chatCommunitySectionModule
property var community
property bool hasAddedContacts: false property bool hasAddedContacts: false
property var transactionStore: TransactionStore {} property var transactionStore: TransactionStore {}
@ -231,7 +231,7 @@ StatusSectionLayout {
CommunityMembersSettingsPanel { CommunityMembersSettingsPanel {
membersModel: root.community.members membersModel: root.community.members
bannedMembersModel: root.community.bannedMembers bannedMembersModel: root.community.bannedMembers
pendingMemberRequestsModel: root.community.pendingMemberRequests pendingMemberRequestsModel: root.community.pendingRequestsToJoin
declinedMemberRequestsModel: root.community.declinedMemberRequests declinedMemberRequestsModel: root.community.declinedMemberRequests
editable: root.community.amISectionAdmin editable: root.community.amISectionAdmin
communityName: root.community.name communityName: root.community.name

View File

@ -778,7 +778,12 @@ Item {
restoreMode: Binding.RestoreBindingOrValue restoreMode: Binding.RestoreBindingOrValue
} }
rootStore: appMain.rootChatStore rootStore: ChatStores.RootStore {
contactsStore: appMain.rootStore.contactStore
emojiReactionsModel: appMain.rootStore.emojiReactionsModel
openCreateChat: createChatView.opened
chatCommunitySectionModule: appMain.rootStore.mainModuleInst.getChatSectionModule()
}
emojiPopup: statusEmojiPopup emojiPopup: statusEmojiPopup
stickersPopup: statusStickersPopupLoader.item stickersPopup: statusStickersPopupLoader.item
@ -799,7 +804,10 @@ Item {
} }
Component.onCompleted: { Component.onCompleted: {
rootStore.chatCommunitySectionModule = appMain.rootStore.mainModuleInst.getChatSectionModule() // Do not unload section data from the memory in order not
// to reset scroll, not send text input and etc during the
// sections switching
personalChatLayoutLoader.active = true
} }
} }
} }
@ -866,9 +874,12 @@ Item {
roleValue: Constants.appSection.community roleValue: Constants.appSection.community
delegate: Loader { delegate: Loader {
id: communityLoader
readonly property string sectionId: model.id readonly property string sectionId: model.id
active: sectionId === appMain.rootStore.mainModuleInst.activeSection.id
asynchronous: true asynchronous: true
active: sectionId === appMain.rootStore.mainModuleInst.activeSection.id
Layout.fillWidth: true Layout.fillWidth: true
Layout.alignment: Qt.AlignLeft | Qt.AlignTop Layout.alignment: Qt.AlignLeft | Qt.AlignTop
Layout.fillHeight: true Layout.fillHeight: true
@ -886,8 +897,17 @@ Item {
emojiPopup: statusEmojiPopup emojiPopup: statusEmojiPopup
stickersPopup: statusStickersPopupLoader.item stickersPopup: statusStickersPopupLoader.item
sectionItemModel: model
rootStore: appMain.rootChatStore rootStore: ChatStores.RootStore {
contactsStore: appMain.rootStore.contactStore
emojiReactionsModel: appMain.rootStore.emojiReactionsModel
openCreateChat: createChatView.opened
chatCommunitySectionModule: {
appMain.rootStore.mainModuleInst.prepareCommunitySectionModuleForCommunityId(model.id)
return appMain.rootStore.mainModuleInst.getCommunitySectionModule()
}
}
onProfileButtonClicked: { onProfileButtonClicked: {
Global.changeAppSectionBySectionType(Constants.appSection.profile); Global.changeAppSectionBySectionType(Constants.appSection.profile);
@ -898,10 +918,10 @@ Item {
} }
Component.onCompleted: { Component.onCompleted: {
// we cannot return QVariant if we pass another parameter in a function call // Do not unload section data from the memory in order not
// that's why we're using it this way // to reset scroll, not send text input and etc during the
appMain.rootStore.mainModuleInst.prepareCommunitySectionModuleForCommunityId(model.id) // sections switching
rootStore.chatCommunitySectionModule = appMain.rootStore.mainModuleInst.getCommunitySectionModule() communityLoader.active = true
} }
} }
} }
@ -927,7 +947,13 @@ Item {
anchors.rightMargin - anchors.leftMargin : 0 anchors.rightMargin - anchors.leftMargin : 0
sourceComponent: CreateChatView { sourceComponent: CreateChatView {
rootStore: appMain.rootChatStore rootStore: ChatStores.RootStore {
contactsStore: appMain.rootStore.contactStore
emojiReactionsModel: appMain.rootStore.emojiReactionsModel
openCreateChat: createChatView.opened
chatCommunitySectionModule: appMain.rootStore.mainModuleInst.getChatSectionModule()
}
emojiPopup: statusEmojiPopup emojiPopup: statusEmojiPopup
stickersPopup: statusStickersPopupLoader.item stickersPopup: statusStickersPopupLoader.item
} }