From f6d47085011fd035e2dddf979c7386f3ab4c8d22 Mon Sep 17 00:00:00 2001 From: erinn Date: Mon, 10 May 2021 16:58:25 -0700 Subject: [PATCH 1/2] adding sendinvitation --- lib.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/lib.go b/lib.go index e708e59..24813b0 100644 --- a/lib.go +++ b/lib.go @@ -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() From 54c2048f5878f6c0d287981d22cace7ba96dba10 Mon Sep 17 00:00:00 2001 From: erinn Date: Tue, 11 May 2021 15:35:58 -0700 Subject: [PATCH 2/2] addressing comments on #38 --- lib.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib.go b/lib.go index 478820a..c01444a 100644 --- a/lib.go +++ b/lib.go @@ -41,6 +41,12 @@ var acnQueue event.Queue var contactEventsQueue event.Queue var globalACN connectivity.ACN +// ChatMessage API currently not officially documented, see +// https://git.openprivacy.ca/cwtch.im/secure-development-handbook/issues/3 +// for latest updates for now +// +// A ChatMessage is the application-layer Cwtch message, delivered to the UI +// as serialized json. type ChatMessage struct { O int `json:"o"` D string `json:"d"` @@ -529,6 +535,9 @@ func c_SendInvitation(profile_ptr *C.char, profile_len C.int, handle_ptr *C.char SendInvitation(profile, handle, target) } +// Send an invitation from `profileOnion` to contact `handle` (peer or group) +// asking them to add the contact `target` (also peer or group). +// For groups, the profile must already have `target` as a contact. func SendInvitation(profileOnion, handle, target string) { profile := application.GetPeer(profileOnion) ph := utils.NewPeerHelper(profile) @@ -547,14 +556,8 @@ func SendInvitation(profileOnion, handle, target string) { 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)) + SendMessage(profileOnion, handle, string(inviteBytes)) } }