From 1621818ecf919a029411a18b4245b695b0c63891 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Mon, 19 Jul 2021 15:46:11 -0400 Subject: [PATCH] feat(link): handle group chat invite links Fixes #2676 The group chat is still not usable. It is missing the feature to request access to the group chat. --- src/app/chat/views/groups.nim | 3 +++ src/status/chat.nim | 12 ++++++++++-- src/status/libstatus/chat.nim | 3 +++ ui/imports/Utils.qml | 20 ++++++++++++++++++-- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/app/chat/views/groups.nim b/src/app/chat/views/groups.nim index 2323ef3907..9b288326aa 100644 --- a/src/app/chat/views/groups.nim +++ b/src/app/chat/views/groups.nim @@ -37,6 +37,9 @@ QtObject: let pubKeysSeq = map(parseJson(pubKeys).getElems(), proc(x:JsonNode):string = x.getStr) self.status.chat.createGroup(groupName, pubKeysSeq) + proc joinGroupChatFromInvitation*(self: GroupsView, groupName: string, chatID: string, adminPK: string) {.slot.} = + self.status.chat.createGroupChatFromInvitation(groupName, chatID, adminPK) + proc addMembers*(self: GroupsView, chatId: string, pubKeys: string) {.slot.} = let pubKeysSeq = map(parseJson(pubKeys).getElems(), proc(x:JsonNode):string = x.getStr) self.status.chat.addGroupMembers(chatId, pubKeysSeq) diff --git a/src/status/chat.nim b/src/status/chat.nim index 35286034e0..6c2dd0712e 100644 --- a/src/status/chat.nim +++ b/src/status/chat.nim @@ -366,14 +366,22 @@ proc getUserName*(self: ChatModel, id: string, defaultUserName: string):string = else: return defaultUserName -proc createGroup*(self: ChatModel, groupName: string, pubKeys: seq[string]) = - var response = parseJson(status_chat.createGroup(groupName, pubKeys)) +proc processGroupChatCreation*(self: ChatModel, result: string) = + var response = parseJson(result) var (chats, messages) = formatChatUpdate(response) let chat = chats[0] self.channels[chat.id] = chat self.events.emit("chatUpdate", ChatUpdateArgs(messages: messages, chats: chats, contacts: @[])) self.events.emit("activeChannelChanged", ChatIdArg(chatId: chat.id)) +proc createGroup*(self: ChatModel, groupName: string, pubKeys: seq[string]) = + var result = status_chat.createGroup(groupName, pubKeys) + self.processGroupChatCreation(result) + +proc createGroupChatFromInvitation*(self: ChatModel, groupName: string, chatID: string, adminPK: string) = + var result = status_chat.createGroupChatFromInvitation(groupName, chatID, adminPK) + self.processGroupChatCreation(result) + proc addGroupMembers*(self: ChatModel, chatId: string, pubKeys: seq[string]) = var response = status_chat.addGroupMembers(chatId, pubKeys) self.emitUpdate(response) diff --git a/src/status/libstatus/chat.nim b/src/status/libstatus/chat.nim index fe2188cf0e..c14dca5705 100644 --- a/src/status/libstatus/chat.nim +++ b/src/status/libstatus/chat.nim @@ -253,6 +253,9 @@ proc renameGroup*(chatId: string, newName: string): string = proc createGroup*(groupName: string, pubKeys: seq[string]): string = callPrivateRPC("createGroupChatWithMembers".prefix, %* [nil, groupName, pubKeys]) +proc createGroupChatFromInvitation*(groupName: string, chatID: string, adminPK: string): string = + callPrivateRPC("createGroupChatFromInvitation".prefix, %* [groupName, chatID, adminPK]) + proc addGroupMembers*(chatId: string, pubKeys: seq[string]): string = callPrivateRPC("addMembersToGroupChat".prefix, %* [nil, chatId, pubKeys]) diff --git a/ui/imports/Utils.qml b/ui/imports/Utils.qml index cfbf332d75..45b7543c35 100644 --- a/ui/imports/Utils.qml +++ b/ui/imports/Utils.qml @@ -446,13 +446,29 @@ QtObject { return result } + // Group chat + index = link.lastIndexOf("/g/") + if (index > -1) { + let indexAdminPk = link.lastIndexOf("a=") + let indexChatName = link.lastIndexOf("a1=") + let indexChatId = link.lastIndexOf("a2=") + const pubKey = link.substring(indexAdminPk + 2, indexChatName - 1) + const chatName = link.substring(indexChatName + 3, indexChatId - 1) + const chatId = link.substring(indexChatId + 3, link.length) + result.title = qsTr("Join the %1 group chat").arg(chatName) + result.callback = function () { + chatsModel.groups.joinGroupChatFromInvitation(chatName, chatId, pubKey); + } + + return result + } + // Public chat // This needs to be the last check because it is as VERY loose check index = link.lastIndexOf("/") if (index > -1) { const chatId = link.substring(index + 1) - //% "Join the %1 public channel" - result.title = qsTrId("join-the--1-public-channel").arg(chatId) + result.title = qsTr("Join the %1 public channel").arg(chatId) result.callback = function () { chatsModel.channelView.joinPublicChat(chatId); }