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.
This commit is contained in:
parent
a811ee215c
commit
1621818ecf
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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])
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue