diff --git a/src/app/chat/view.nim b/src/app/chat/view.nim index 9f5c3f7dac..c690af362c 100644 --- a/src/app/chat/view.nim +++ b/src/app/chat/view.nim @@ -167,17 +167,24 @@ QtObject: return self.communities.activeCommunity.chats.getChannel(index) else: return self.chats.getChannel(index) + + proc getCommunityChannelById(self: ChatsView, channel: string): Chat = + 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 proc getChannelById*(self: ChatsView, channel: string): Chat = - if (self.communities.activeCommunity.active): - let index = self.communities.activeCommunity.chats.chats.findIndexById(channel) - if (index == -1): - return - return self.communities.activeCommunity.chats.getChannel(index) - else: - let index = self.chats.chats.findIndexById(channel) - if (index == -1): - return + if self.communities.activeCommunity.active: + result = self.getCommunityChannelById(channel) + if not result.isNil: + return result + # even if communities are active, if we don't find a chat, it's possibly + # because we are looking for a normal chat, so continue below + let index = self.chats.chats.findIndexById(channel) + if index > -1: return self.chats.getChannel(index) proc updateChannelInRightList*(self: ChatsView, channel: Chat) = @@ -579,8 +586,13 @@ QtObject: self.getLinkPreviewData("linkPreviewDataReceived", link, uuid) proc joinChat*(self: ChatsView, channel: string, chatTypeInt: int): int {.slot.} = - self.status.chat.join(channel, ChatType(chatTypeInt)) + var chatType = ChatType(chatTypeInt) + let selectedChannel = self.getChannelById(channel) + if not selectedChannel.isNil: + chatType = selectedChannel.chatType + self.status.chat.join(channel, chatType) self.setActiveChannel(channel) + chatType.int proc joinChatWithENS*(self: ChatsView, channel: string, ensName: string): int {.slot.} = self.status.chat.join(channel, ChatType.OneToOne, ensName=status_ens.addDomain(ensName)) diff --git a/src/status/signals/messages.nim b/src/status/signals/messages.nim index 39101cab59..f9a08e3de0 100644 --- a/src/status/signals/messages.nim +++ b/src/status/signals/messages.nim @@ -197,10 +197,12 @@ proc toCommunity*(jsonCommunity: JsonNode): Community = for chatId, chat in jsonCommunity{"chats"}: result.chats.add(Chat( id: result.id & chatId, + communityId: result.id, name: chat{"name"}.getStr, canPost: chat{"canPost"}.getBool, + chatType: ChatType.CommunityChat # TODO get this from access - chatType: ChatType.Public#chat{"permissions"}{"access"}.getInt, + #chat{"permissions"}{"access"}.getInt, )) if jsonCommunity.hasKey("members") and jsonCommunity["members"].kind != JNull: diff --git a/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/ChatText.qml b/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/ChatText.qml index a3edbd6354..79fb84384a 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/ChatText.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/ChatText.qml @@ -44,7 +44,12 @@ Item { clip: true onLinkActivated: function (link) { if(link.startsWith("#")) { - chatsModel.joinChat(link.substring(1), Constants.chatTypePublic); + const chatType = chatsModel.communities.activeCommunity.active ? Constants.chatTypeCommunity : Constants.chatTypePublic; + const foundChatType = chatsModel.joinChat(link.substring(1), chatType); + if (foundChatType === Constants.chatTypePublic && chatsModel.communities.activeCommunity.active) { + chatsModel.communities.activeCommunity.active = false + appMain.changeAppSection(Constants.chat) + } return; } diff --git a/ui/app/AppLayouts/Chat/components/ProfilePopup.qml b/ui/app/AppLayouts/Chat/components/ProfilePopup.qml index 4bda9c7a58..b32478b75e 100644 --- a/ui/app/AppLayouts/Chat/components/ProfilePopup.qml +++ b/ui/app/AppLayouts/Chat/components/ProfilePopup.qml @@ -337,8 +337,7 @@ ModalPopup { visible: !isBlocked && chatsModel.activeChannel.id !== popup.fromAuthor width: visible ? implicitWidth : 0 onClicked: { - if (tabBar.currentIndex !== 0) - tabBar.currentIndex = 0 + appMain.changeAppSection(Constants.chat) chatsModel.joinChat(fromAuthor, Constants.chatTypeOneToOne) popup.close() } diff --git a/ui/app/AppMain.qml b/ui/app/AppMain.qml index 11fb1f12d5..583970bcd5 100644 --- a/ui/app/AppMain.qml +++ b/ui/app/AppMain.qml @@ -362,6 +362,7 @@ RowLayout { } function changeAppSection(section) { + chatsModel.communities.activeCommunity.active = false sLayout.currentIndex = Utils.getAppSectionIndex(section) }