From 47d154689309b9a1e319a4b91a35165a6c84f0f7 Mon Sep 17 00:00:00 2001 From: Sale Djenic Date: Thu, 8 Jul 2021 17:39:39 +0200 Subject: [PATCH] fix(@desktop/chat): app crash when you leave a chat The issue is happening randomly. I managed to catch it few times and hopefully fix it. Problem was in leave proc in src/status/chat.nim cause we were sending activeChannelChanged signal from it what started setting activeChannel to the value of the backToFirstChat variable, and while that process was in progress setActiveChannelByIndex was called from activeChannel what caused another emit of activeChannelChanged signal while the previous one was not completed. That caused new setting of activeChannel with active channel index 0, what caused an app crash. This is fixed by setting active channel to the first one from the list when we get a signal that any channel from the list is removed. This way activeChannelChanged is broadcasted to the other parts correctly. Fixes: #2825 --- src/app/chat/views/channel.nim | 4 ++++ src/status/chat.nim | 1 - ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml | 8 ++++---- ui/app/AppLayouts/Chat/ChatColumn/Message.qml | 3 ++- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/app/chat/views/channel.nim b/src/app/chat/views/channel.nim index fc8d2d9813..d03fd2af70 100644 --- a/src/app/chat/views/channel.nim +++ b/src/app/chat/views/channel.nim @@ -294,3 +294,7 @@ QtObject: chatItemView.setChatItem(chat) self.chatItemViews[id] = chatItemView return chatItemView + + proc removeChat*(self: ChannelView, chatId: string) = + discard self.chats.removeChatItemFromList(chatId) + self.setActiveChannel(backToFirstChat) diff --git a/src/status/chat.nim b/src/status/chat.nim index 889c44c675..9359008c7a 100644 --- a/src/status/chat.nim +++ b/src/status/chat.nim @@ -219,7 +219,6 @@ proc leave*(self: ChatModel, chatId: string) = self.channels.del(chatId) discard status_chat.clearChatHistory(chatId) self.events.emit("channelLeft", ChatIdArg(chatId: chatId)) - self.events.emit("activeChannelChanged", ChatIdArg(chatId: backToFirstChat)) proc clearHistory*(self: ChatModel, chatId: string) = discard status_chat.clearChatHistory(chatId) diff --git a/ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml b/ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml index 80ab8a2527..0cd6442840 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml @@ -118,16 +118,16 @@ SplitView { radius: 16 } onClicked: { - svRoot.newMessages = 0 + newMessages = 0 scrollDownButton.visible = false chatLogView.scrollToBottom(true) } StyledText { id: nbMessages - visible: svRoot.newMessages > 0 + visible: newMessages > 0 width: visible ? implicitWidth : 0 - text: svRoot.newMessages + text: newMessages anchors.verticalCenter: parent.verticalCenter anchors.left: parent.left color: Style.current.pillButtonTextColor @@ -202,7 +202,7 @@ SplitView { onNewMessagePushed: { if (!chatLogView.scrollToBottom()) { - svRoot.newMessages++ + newMessages++ } } diff --git a/ui/app/AppLayouts/Chat/ChatColumn/Message.qml b/ui/app/AppLayouts/Chat/ChatColumn/Message.qml index 5d96a80a8e..091a2a0a33 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/Message.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/Message.qml @@ -309,7 +309,8 @@ Item { } return gapNowAndOldest < maxGapInSeconds && gapNowAndJoined > maxGapInSeconds - && (chatsModel.channelView.activeChannel.chatType !== Constants.chatTypePrivateGroupChat || chatsModel.channelView.activeChannel.isMember) + && (chatsModel.channelView.activeChannel.chatType !== Constants.chatTypePrivateGroupChat + || chatsModel.channelView.activeChannel.isMember) } height: childrenRect.height + Style.current.smallPadding * 2 anchors.left: parent.left