fix: fix invite to use new API and remove the double msg send
This commit is contained in:
parent
941e9565ab
commit
da77487746
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue