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/status
|
||||||
import ../../../status/chat/chat
|
import ../../../status/chat/chat
|
||||||
import ./community_list
|
import ./community_list
|
||||||
|
@ -229,6 +229,18 @@ QtObject:
|
||||||
error "Error inviting to the community", msg = e.msg
|
error "Error inviting to the community", msg = e.msg
|
||||||
result = fmt"Error inviting to the community: {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.} =
|
proc exportComumnity*(self: CommunitiesView): string {.slot.} =
|
||||||
try:
|
try:
|
||||||
result = self.status.chat.exportCommunity(self.activeCommunity.communityItem.id)
|
result = self.status.chat.exportCommunity(self.activeCommunity.communityItem.id)
|
||||||
|
|
|
@ -429,9 +429,10 @@ proc leaveCommunity*(self: ChatModel, communityId: string) =
|
||||||
status_chat.leaveCommunity(communityId)
|
status_chat.leaveCommunity(communityId)
|
||||||
|
|
||||||
proc inviteUserToCommunity*(self: ChatModel, communityId: string, pubKey: string) =
|
proc inviteUserToCommunity*(self: ChatModel, communityId: string, pubKey: string) =
|
||||||
status_chat.inviteUserToCommunity(communityId, pubKey)
|
status_chat.inviteUsersToCommunity(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)
|
proc inviteUsersToCommunity*(self: ChatModel, communityId: string, pubKeys: seq[string]) =
|
||||||
|
status_chat.inviteUsersToCommunity(communityId, pubKeys)
|
||||||
|
|
||||||
proc removeUserFromCommunity*(self: ChatModel, communityId: string, pubKey: string) =
|
proc removeUserFromCommunity*(self: ChatModel, communityId: string, pubKey: string) =
|
||||||
status_chat.removeUserFromCommunity(communityId, pubKey)
|
status_chat.removeUserFromCommunity(communityId, pubKey)
|
||||||
|
|
|
@ -305,8 +305,11 @@ proc joinCommunity*(communityId: string) =
|
||||||
proc leaveCommunity*(communityId: string) =
|
proc leaveCommunity*(communityId: string) =
|
||||||
discard callPrivateRPC("leaveCommunity".prefix, %*[communityId])
|
discard callPrivateRPC("leaveCommunity".prefix, %*[communityId])
|
||||||
|
|
||||||
proc inviteUserToCommunity*(communityId: string, pubKey: string) =
|
proc inviteUsersToCommunity*(communityId: string, pubKeys: seq[string]) =
|
||||||
discard callPrivateRPC("inviteUserToCommunity".prefix, %*[communityId, pubKey])
|
discard callPrivateRPC("inviteUsersToCommunity".prefix, %*[{
|
||||||
|
"communityId": communityId,
|
||||||
|
"users": pubKeys
|
||||||
|
}])
|
||||||
|
|
||||||
proc exportCommunity*(communityId: string):string =
|
proc exportCommunity*(communityId: string):string =
|
||||||
result = callPrivateRPC("exportCommunity".prefix, %*[communityId]).parseJson()["result"].getStr
|
result = callPrivateRPC("exportCommunity".prefix, %*[communityId]).parseJson()["result"].getStr
|
||||||
|
|
|
@ -113,13 +113,13 @@ ModalPopup {
|
||||||
//% "Invite"
|
//% "Invite"
|
||||||
text: qsTrId("invite-button")
|
text: qsTrId("invite-button")
|
||||||
onClicked : {
|
onClicked : {
|
||||||
console.log('invite')
|
const error = chatsModel.communities.inviteUsersToCommunity(JSON.stringify(popup.pubKeys))
|
||||||
popup.pubKeys.forEach(function (pubKey) {
|
// TODO show error to user also should we show success?
|
||||||
const error = chatsModel.inviteUserToCommunity(pubKey)
|
if (error) {
|
||||||
if (error) {
|
console.error('Error inviting', error)
|
||||||
console.log('do something?')
|
return
|
||||||
}
|
}
|
||||||
})
|
popup.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue