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
This commit is contained in:
Sale Djenic 2021-09-20 15:49:51 +02:00 committed by Iuri Matias
parent b5e8132859
commit 0c73febf2c
5 changed files with 39 additions and 18 deletions

View File

@ -293,11 +293,12 @@ QtObject:
proc getLinkPreviewData*(self: ChatsView, link: string, uuid: string) {.slot.} = proc getLinkPreviewData*(self: ChatsView, link: string, uuid: string) {.slot.} =
self.getLinkPreviewData("linkPreviewDataReceived", link, uuid) 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) let selectedChannel = self.channelView.getChannelById(channel)
if selectedChannel == nil: if selectedChannel == nil:
return -1 return ""
selectedChannel.chatType.int
result = Json.encode(selectedChannel.toJsonNode())
proc asyncActivityNotificationLoad*(self: ChatsView) {.slot.} = proc asyncActivityNotificationLoad*(self: ChatsView) {.slot.} =
self.asyncActivityNotificationLoad("asyncActivityNotificationLoaded") self.asyncActivityNotificationLoad("asyncActivityNotificationLoaded")

View File

@ -49,9 +49,8 @@ QtObject:
let index = self.communities.activeCommunity.chats.chats.findIndexById(channel) let index = self.communities.activeCommunity.chats.chats.findIndexById(channel)
if (index > -1): if (index > -1):
return self.communities.activeCommunity.chats.getChannel(index) return self.communities.activeCommunity.chats.getChannel(index)
let chan = self.communities.activeCommunity.chats.getChannelByName(channel)
if not chan.isNil: return self.communities.activeCommunity.chats.getChannelByName(channel)
return chan
proc getChannelById*(self: ChannelView, channel: string): Chat = proc getChannelById*(self: ChannelView, channel: string): Chat =
if self.communities.activeCommunity.active: if self.communities.activeCommunity.active:

View File

@ -125,7 +125,7 @@ QtObject:
proc getChannel*(self: ChannelsList, index: int): Chat = proc getChannel*(self: ChannelsList, index: int): Chat =
if index < 0 or index >= self.chats.len: if index < 0 or index >= self.chats.len:
return return nil
result = self.chats[index] result = self.chats[index]
@ -146,6 +146,8 @@ QtObject:
if chat.name == name: if chat.name == name:
return chat return chat
return nil
proc upsertChannel(self: ChannelsList, channel: Chat): int = proc upsertChannel(self: ChannelsList, channel: Chat): int =
let idx = self.chats.findIndexById(channel.id) let idx = self.chats.findIndexById(channel.id)
if idx == -1: if idx == -1:

View File

@ -44,21 +44,40 @@ Item {
onLinkActivated: { onLinkActivated: {
if(link.startsWith("#")) { if(link.startsWith("#")) {
const channelName = link.substring(1); const channelName = link.substring(1);
const chatType = chatsModel.communities.activeCommunity.active ? Constants.chatTypeCommunity : Constants.chatTypePublic; const foundChannelObj = chatsModel.getChannel(channelName);
const foundChatType = chatsModel.getChatType(channelName);
if(foundChatType === -1 || foundChatType !== Constants.chatTypePublic){ if (!foundChannelObj)
chatsModel.channelView.joinPublicChat(channelName); {
if(chatsModel.communities.activeCommunity.active) { chatsModel.channelView.joinPublicChat(channelName)
chatsModel.communities.activeCommunity.active = false if(chatsModel.communities.activeCommunity.active)
{
chatsModel.channelView.joinPublicChat(channelName)
appMain.changeAppSection(Constants.chat) appMain.changeAppSection(Constants.chat)
} }
} else { return
appMain.changeAppSection(Constants.chat) }
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); chatsModel.channelView.setActiveChannel(channelName);
} }
return; return
} }
if (link.startsWith('//')) { if (link.startsWith('//')) {

2
vendor/status-lib vendored

@ -1 +1 @@
Subproject commit ea02568fbc1cdb22a2309dfcf1594a5934730581 Subproject commit 4f7e899953843a316336fa72ae049f7880f6f7bd