fix: fix invite to use new API and remove the double msg send

This commit is contained in:
Jonathan Rainville 2021-02-17 13:19:07 -05:00 committed by Iuri Matias
parent 941e9565ab
commit da77487746
4 changed files with 29 additions and 13 deletions

View File

@ -1,4 +1,4 @@
import NimQml, json, sequtils, chronicles, strutils, strformat
import NimQml, json, sequtils, chronicles, strutils, strformat, json
import ../../../status/status
import ../../../status/chat/chat
import ./community_list
@ -229,6 +229,18 @@ QtObject:
error "Error inviting to the community", msg = e.msg
result = fmt"Error inviting to the community: {e.msg}"
proc inviteUsersToCommunity*(self: CommunitiesView, pubKeysJSON: string): string {.slot.} =
try:
let pubKeysParsed = pubKeysJSON.parseJson
var pubKeys: seq[string] = @[]
for pubKey in pubKeysParsed:
pubKeys.add(pubKey.getStr)
self.status.chat.inviteUsersToCommunity(self.activeCommunity.id(), pubKeys)
except Exception as e:
error "Error inviting to the community", msg = e.msg
result = fmt"Error inviting to the community: {e.msg}"
proc exportComumnity*(self: CommunitiesView): string {.slot.} =
try:
result = self.status.chat.exportCommunity(self.activeCommunity.communityItem.id)

View File

@ -429,9 +429,10 @@ proc leaveCommunity*(self: ChatModel, communityId: string) =
status_chat.leaveCommunity(communityId)
proc inviteUserToCommunity*(self: ChatModel, communityId: string, pubKey: string) =
status_chat.inviteUserToCommunity(communityId, pubKey)
# After sending the invite, we send a message with the community ID so they can join
self.sendMessage(pubKey, "Upgrade here to see an invitation to community", "", ContentType.Community.int, communityId, true)
status_chat.inviteUsersToCommunity(communityId, @[pubKey])
proc inviteUsersToCommunity*(self: ChatModel, communityId: string, pubKeys: seq[string]) =
status_chat.inviteUsersToCommunity(communityId, pubKeys)
proc removeUserFromCommunity*(self: ChatModel, communityId: string, pubKey: string) =
status_chat.removeUserFromCommunity(communityId, pubKey)

View File

@ -305,8 +305,11 @@ proc joinCommunity*(communityId: string) =
proc leaveCommunity*(communityId: string) =
discard callPrivateRPC("leaveCommunity".prefix, %*[communityId])
proc inviteUserToCommunity*(communityId: string, pubKey: string) =
discard callPrivateRPC("inviteUserToCommunity".prefix, %*[communityId, pubKey])
proc inviteUsersToCommunity*(communityId: string, pubKeys: seq[string]) =
discard callPrivateRPC("inviteUsersToCommunity".prefix, %*[{
"communityId": communityId,
"users": pubKeys
}])
proc exportCommunity*(communityId: string):string =
result = callPrivateRPC("exportCommunity".prefix, %*[communityId]).parseJson()["result"].getStr

View File

@ -113,13 +113,13 @@ ModalPopup {
//% "Invite"
text: qsTrId("invite-button")
onClicked : {
console.log('invite')
popup.pubKeys.forEach(function (pubKey) {
const error = chatsModel.inviteUserToCommunity(pubKey)
if (error) {
console.log('do something?')
}
})
const error = chatsModel.communities.inviteUsersToCommunity(JSON.stringify(popup.pubKeys))
// TODO show error to user also should we show success?
if (error) {
console.error('Error inviting', error)
return
}
popup.close()
}
}
}