restoring sendmessage yay

This commit is contained in:
erinn 2021-04-07 22:06:21 -07:00
parent 6e9d423d58
commit 0c963172ff
1 changed files with 50 additions and 0 deletions

50
lib.go
View File

@ -322,6 +322,44 @@ func ContactEvents() string {
}
}
//export c_AcceptContact
func c_AcceptContact(profilePtr *C.char, profileLen C.int, handlePtr *C.char, handleLen C.int) {
AcceptContact(C.GoStringN(profilePtr, profileLen), C.GoStringN(handlePtr, handleLen))
}
func AcceptContact(profile, handle string) {
err := application.GetPeer(profile).SetContactAuthorization(handle, model.AuthApproved)
if err != nil {
log.Errorf("error accepting contact: %s", err.Error())
}
}
//export c_BlockContact
func c_BlockContact(profilePtr *C.char, profileLen C.int, handlePtr *C.char, handleLen C.int) {
BlockContact(C.GoStringN(profilePtr, profileLen), C.GoStringN(handlePtr, handleLen))
}
func BlockContact(profile, handle string) {
err := application.GetPeer(profile).SetContactAuthorization(handle, model.AuthBlocked)
if err != nil {
log.Errorf("error blocking contact: %s", err.Error())
}
}
//export c_DebugResetContact
func c_DebugResetContact(profilePtr *C.char, profileLen C.int, handlePtr *C.char, handleLen C.int) {
DebugResetContact(C.GoStringN(profilePtr, profileLen), C.GoStringN(handlePtr, handleLen))
}
func DebugResetContact(profile, handle string) {
err := application.GetPeer(profile).SetContactAuthorization(handle, model.AuthUnknown)
if err != nil {
log.Errorf("error resetting contact: %s", err.Error())
} else {
log.Infof("reset contact! %s -> %s", profile, handle)
}
}
//export c_NumMessages
func c_NumMessages(profile_ptr *C.char, profile_len C.int, handle_ptr *C.char, handle_len C.int) (n int) {
profile := C.GoStringN(profile_ptr, profile_len)
@ -363,5 +401,17 @@ func GetMessages(profile, handle string, start, end int) string {
return string(bytes)
}
//export c_SendMessage
func c_SendMessage(profile_ptr *C.char, profile_len C.int, handle_ptr *C.char, handle_len C.int, msg_ptr *C.char, msg_len C.int) {
profile := C.GoStringN(profile_ptr, profile_len)
handle := C.GoStringN(handle_ptr, handle_len)
msg := C.GoStringN(msg_ptr, msg_len)
SendMessage(profile, handle, msg)
}
func SendMessage(profile, handle, msg string) {
application.GetPeer(profile).SendMessageToPeer(handle, msg)
}
// Leave as is, needed by ffi
func main() {}