From 0c73febf2c8703b0a9b6a377bb5ac7d13b582ea3 Mon Sep 17 00:00:00 2001 From: Sale Djenic Date: Mon, 20 Sep 2021 15:49:51 +0200 Subject: [PATCH] fix(@desktop/chat): channel links sends to main public channel instead of a channel in that community In case clicked channel: - exists in a community -> the app will switch you to it - doesn't exist in a community, but exists in the public chat list -> the app will switch to `Chat` section and also to the appropriate channel there - doesn't exist in a community and doesn't exist in the public chat list -> the app will switch to `Chat` section and join new channel Fixes: #3489 --- src/app/chat/view.nim | 7 ++-- src/app/chat/views/channel.nim | 5 +-- src/app/chat/views/channels_list.nim | 4 +- .../ChatColumn/MessageComponents/ChatText.qml | 39 ++++++++++++++----- vendor/status-lib | 2 +- 5 files changed, 39 insertions(+), 18 deletions(-) diff --git a/src/app/chat/view.nim b/src/app/chat/view.nim index 960762effb..9c5d703fe4 100644 --- a/src/app/chat/view.nim +++ b/src/app/chat/view.nim @@ -293,11 +293,12 @@ QtObject: proc getLinkPreviewData*(self: ChatsView, link: string, uuid: string) {.slot.} = self.getLinkPreviewData("linkPreviewDataReceived", link, uuid) - proc getChatType*(self: ChatsView, channel: string): int {.slot.} = + proc getChannel*(self: ChatsView, channel: string): string {.slot.} = let selectedChannel = self.channelView.getChannelById(channel) if selectedChannel == nil: - return -1 - selectedChannel.chatType.int + return "" + + result = Json.encode(selectedChannel.toJsonNode()) proc asyncActivityNotificationLoad*(self: ChatsView) {.slot.} = self.asyncActivityNotificationLoad("asyncActivityNotificationLoaded") diff --git a/src/app/chat/views/channel.nim b/src/app/chat/views/channel.nim index f874a68c14..96538e7e05 100644 --- a/src/app/chat/views/channel.nim +++ b/src/app/chat/views/channel.nim @@ -49,9 +49,8 @@ QtObject: let index = self.communities.activeCommunity.chats.chats.findIndexById(channel) if (index > -1): return self.communities.activeCommunity.chats.getChannel(index) - let chan = self.communities.activeCommunity.chats.getChannelByName(channel) - if not chan.isNil: - return chan + + return self.communities.activeCommunity.chats.getChannelByName(channel) proc getChannelById*(self: ChannelView, channel: string): Chat = if self.communities.activeCommunity.active: diff --git a/src/app/chat/views/channels_list.nim b/src/app/chat/views/channels_list.nim index 8327ff24e5..43f8fad1d5 100644 --- a/src/app/chat/views/channels_list.nim +++ b/src/app/chat/views/channels_list.nim @@ -125,7 +125,7 @@ QtObject: proc getChannel*(self: ChannelsList, index: int): Chat = if index < 0 or index >= self.chats.len: - return + return nil result = self.chats[index] @@ -146,6 +146,8 @@ QtObject: if chat.name == name: return chat + return nil + proc upsertChannel(self: ChannelsList, channel: Chat): int = let idx = self.chats.findIndexById(channel.id) if idx == -1: diff --git a/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/ChatText.qml b/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/ChatText.qml index 831e7d4e09..d3edb20396 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/ChatText.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/ChatText.qml @@ -44,21 +44,40 @@ Item { onLinkActivated: { if(link.startsWith("#")) { const channelName = link.substring(1); - const chatType = chatsModel.communities.activeCommunity.active ? Constants.chatTypeCommunity : Constants.chatTypePublic; - const foundChatType = chatsModel.getChatType(channelName); + const foundChannelObj = chatsModel.getChannel(channelName); - if(foundChatType === -1 || foundChatType !== Constants.chatTypePublic){ - chatsModel.channelView.joinPublicChat(channelName); - if(chatsModel.communities.activeCommunity.active) { - chatsModel.communities.activeCommunity.active = false + if (!foundChannelObj) + { + chatsModel.channelView.joinPublicChat(channelName) + if(chatsModel.communities.activeCommunity.active) + { + chatsModel.channelView.joinPublicChat(channelName) appMain.changeAppSection(Constants.chat) - } - } else { - appMain.changeAppSection(Constants.chat) + } + return + } + + let obj = JSON.parse(foundChannelObj) + + if(obj.chatType === -1 || obj.chatType === Constants.chatTypePublic) + { + if(chatsModel.communities.activeCommunity.active) + { + chatsModel.channelView.joinPublicChat(channelName) + appMain.changeAppSection(Constants.chat) + } + + chatsModel.channelView.setActiveChannel(channelName); + } + else if(obj.communityId === chatsModel.communities.activeCommunity.id && + obj.chatType === Constants.chatTypeCommunity && + chatsModel.channelView.activeChannel.id !== obj.id + ) + { chatsModel.channelView.setActiveChannel(channelName); } - return; + return } if (link.startsWith('//')) { diff --git a/vendor/status-lib b/vendor/status-lib index ea02568fbc..4f7e899953 160000 --- a/vendor/status-lib +++ b/vendor/status-lib @@ -1 +1 @@ -Subproject commit ea02568fbc1cdb22a2309dfcf1594a5934730581 +Subproject commit 4f7e899953843a316336fa72ae049f7880f6f7bd