adding sendinvitation

This commit is contained in:
erinn 2021-05-10 16:58:25 -07:00
parent df414ed23f
commit f6d4708501
1 changed files with 42 additions and 0 deletions

42
lib.go
View File

@ -41,6 +41,11 @@ var acnQueue event.Queue
var contactEventsQueue event.Queue
var globalACN connectivity.ACN
type ChatMessage struct {
O int `json:"o"`
D string `json:"d"`
}
//export c_StartCwtch
func c_StartCwtch(dir_c *C.char, len C.int, tor_c *C.char, torLen C.int) {
dir := C.GoStringN(dir_c, len)
@ -515,6 +520,43 @@ func SendMessage(profileOnion, handle, msg string) {
}
}
//export c_SendInvitation
func c_SendInvitation(profile_ptr *C.char, profile_len C.int, handle_ptr *C.char, handle_len C.int, target_ptr *C.char, target_len C.int) {
profile := C.GoStringN(profile_ptr, profile_len)
handle := C.GoStringN(handle_ptr, handle_len)
target := C.GoStringN(target_ptr, target_len)
SendInvitation(profile, handle, target)
}
func SendInvitation(profileOnion, handle, target string) {
profile := application.GetPeer(profileOnion)
ph := utils.NewPeerHelper(profile)
var invite ChatMessage
if ph.IsGroup(target) {
bundle, _ := profile.GetContact(profile.GetGroup(target).GroupServer).GetAttribute(string(model.BundleType))
inviteStr, err := profile.GetGroup(target).Invite()
if err == nil {
invite = ChatMessage{O: 101, D: fmt.Sprintf("tofubundle:server:%s||%s", base64.StdEncoding.EncodeToString([]byte(bundle)), inviteStr)}
}
} else {
invite = ChatMessage{O: 100, D: target}
}
inviteBytes, err := json.Marshal(invite)
if err != nil {
log.Errorf("malformed invite: %v", err)
} else if ph.IsGroup(handle) {
groupHandler, groupHandlerErr := groups.ExperimentGate(utils.ReadGlobalSettings().Experiments)
if groupHandlerErr == nil {
groupHandler.SendMessage(profile, handle, string(inviteBytes))
}
} else {
contactHandler, _ := contact.FunctionalityGate(utils.ReadGlobalSettings().Experiments)
contactHandler.SendMessage(profile, handle, string(inviteBytes))
}
}
//export c_ResetTor
func c_ResetTor() {
ResetTor()