fix(chat): use loader for ChatMessagesView instead ChatContentView

fixes: #10285
This commit is contained in:
Patryk Osmaczko 2023-04-17 22:43:23 +02:00 committed by osmaczko
parent 136635670e
commit ec7bd963e9
2 changed files with 54 additions and 58 deletions

View File

@ -135,40 +135,33 @@ Item {
id: chatRepeater id: chatRepeater
model: parentModule && parentModule.model model: parentModule && parentModule.model
delegate: Loader { ChatContentView {
id: chatLoader
// Channels/chats are not loaded by default and only load when first put active
active: model.loaderActive
width: parent.width width: parent.width
height: parent.height height: parent.height
visible: model.active visible: model.active && !root.rootStore.openCreateChat && isActiveChannel
chatMessagesLoader.active: model.loaderActive
sourceComponent: ChatContentView { rootStore: root.rootStore
visible: !root.rootStore.openCreateChat && isActiveChannel contactsStore: root.contactsStore
rootStore: root.rootStore emojiPopup: root.emojiPopup
contactsStore: root.contactsStore stickersPopup: root.stickersPopup
emojiPopup: root.emojiPopup sendTransactionNoEnsModal: cmpSendTransactionNoEns
stickersPopup: root.stickersPopup receiveTransactionModal: cmpReceiveTransaction
sendTransactionNoEnsModal: cmpSendTransactionNoEns sendTransactionWithEnsModal: cmpSendTransactionWithEns
receiveTransactionModal: cmpReceiveTransaction stickersLoaded: root.stickersLoaded
sendTransactionWithEnsModal: cmpSendTransactionWithEns isBlocked: model.blocked
stickersLoaded: root.stickersLoaded isUserAdded: root.isUserAdded
isBlocked: model.blocked isActiveChannel: model.active
isUserAdded: root.isUserAdded onOpenStickerPackPopup: {
isActiveChannel: chatLoader.visible root.openStickerPackPopup(stickerPackId)
onOpenStickerPackPopup: { }
root.openStickerPackPopup(stickerPackId) onOpenAppSearch: {
} root.openAppSearch();
onOpenAppSearch: { }
root.openAppSearch(); Component.onCompleted: {
} parentModule.prepareChatContentModuleForChatId(model.itemId)
Component.onCompleted: { chatContentModule = parentModule.getChatContentModule()
parentModule.prepareChatContentModuleForChatId(model.itemId) chatSectionModule = root.parentModule
chatContentModule = parentModule.getChatContentModule() root.checkForCreateChatOptions(model.itemId)
chatSectionModule = root.parentModule
root.checkForCreateChatOptions(model.itemId)
}
} }
} }
} }

View File

@ -36,9 +36,10 @@ ColumnLayout {
property var contactsStore property var contactsStore
property bool isActiveChannel: false property bool isActiveChannel: false
readonly property alias chatMessagesLoader: chatMessagesLoader
property var emojiPopup property var emojiPopup
property var stickersPopup property var stickersPopup
property alias textInputField: chatInput
property UsersStore usersStore: UsersStore {} property UsersStore usersStore: UsersStore {}
onChatContentModuleChanged: { onChatContentModuleChanged: {
@ -76,8 +77,7 @@ ColumnLayout {
} }
} }
MessageStore { readonly property var messageStore: MessageStore {
id: messageStore
messageModule: chatContentModule ? chatContentModule.messagesModule : null messageModule: chatContentModule ? chatContentModule.messagesModule : null
chatSectionModule: root.rootStore.chatCommunitySectionModule chatSectionModule: root.rootStore.chatCommunitySectionModule
} }
@ -137,33 +137,36 @@ ColumnLayout {
Layout.fillHeight: true Layout.fillHeight: true
clip: true clip: true
ChatMessagesView { Loader {
id: chatMessages id: chatMessagesLoader
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
chatContentModule: root.chatContentModule
rootStore: root.rootStore sourceComponent: ChatMessagesView {
contactsStore: root.contactsStore chatContentModule: root.chatContentModule
messageContextMenu: contextmenu rootStore: root.rootStore
messageStore: messageStore contactsStore: root.contactsStore
emojiPopup: root.emojiPopup messageContextMenu: contextmenu
stickersPopup: root.stickersPopup messageStore: root.messageStore
usersStore: root.usersStore emojiPopup: root.emojiPopup
stickersLoaded: root.stickersLoaded stickersPopup: root.stickersPopup
isChatBlocked: root.isBlocked || (chatContentModule && chatContentModule.chatDetails.type === Constants.chatType.oneToOne && !root.isUserAdded) usersStore: root.usersStore
channelEmoji: !chatContentModule ? "" : (chatContentModule.chatDetails.emoji || "") stickersLoaded: root.stickersLoaded
isActiveChannel: root.isActiveChannel isChatBlocked: root.isBlocked || (chatContentModule && chatContentModule.chatDetails.type === Constants.chatType.oneToOne && !root.isUserAdded)
onShowReplyArea: { channelEmoji: !chatContentModule ? "" : (chatContentModule.chatDetails.emoji || "")
let obj = messageStore.getMessageByIdAsJson(messageId) isActiveChannel: root.isActiveChannel
if (!obj) { onShowReplyArea: {
return let obj = messageStore.getMessageByIdAsJson(messageId)
if (!obj) {
return
}
chatInput.showReplyArea(messageId, obj.senderDisplayName, obj.messageText, obj.contentType, obj.messageImage, obj.sticker)
} }
chatInput.showReplyArea(messageId, obj.senderDisplayName, obj.messageText, obj.contentType, obj.messageImage, obj.sticker) onOpenStickerPackPopup: {
root.openStickerPackPopup(stickerPackId);
}
onEditModeChanged: if (!editModeOn) chatInput.forceInputActiveFocus()
} }
onOpenStickerPackPopup: {
root.openStickerPackPopup(stickerPackId);
}
onEditModeChanged: if (!editModeOn) chatInput.forceInputActiveFocus()
} }
Item { Item {