Merge pull request 'Accept/Reject Group Invite' (#31) from groups into trunk
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Reviewed-on: #31
This commit is contained in:
commit
3f07d9a134
2
go.mod
2
go.mod
|
@ -3,7 +3,7 @@ module git.openprivacy.ca/flutter/libcwtch-go
|
|||
go 1.15
|
||||
|
||||
require (
|
||||
cwtch.im/cwtch v0.6.7
|
||||
cwtch.im/cwtch v0.6.9
|
||||
git.openprivacy.ca/openprivacy/connectivity v1.4.2
|
||||
git.openprivacy.ca/openprivacy/log v1.0.2
|
||||
golang.org/x/mobile v0.0.0-20210220033013-bdb1ca9a1e08 // indirect
|
||||
|
|
4
go.sum
4
go.sum
|
@ -16,6 +16,10 @@ cwtch.im/cwtch v0.6.6 h1:GlEoAYfastcimhYsctLSbqql0RNz9t1jphAxTcCvu0M=
|
|||
cwtch.im/cwtch v0.6.6/go.mod h1:KDy4lWWxcYAjeKclwVFkoTQ2dWnZcM0k3Xck+zEuBmE=
|
||||
cwtch.im/cwtch v0.6.7 h1:HerkAptEtiDNeaeebgcOHAbkqpGnHo8mbmBtbgjc8PU=
|
||||
cwtch.im/cwtch v0.6.7/go.mod h1:KDy4lWWxcYAjeKclwVFkoTQ2dWnZcM0k3Xck+zEuBmE=
|
||||
cwtch.im/cwtch v0.6.8 h1:xwPrhqwc9S2+XIEPVL1JDrfJ0Ct7AtW5+K46g+mymdc=
|
||||
cwtch.im/cwtch v0.6.8/go.mod h1:KDy4lWWxcYAjeKclwVFkoTQ2dWnZcM0k3Xck+zEuBmE=
|
||||
cwtch.im/cwtch v0.6.9 h1:R4UgKd8ucw8qGZ0K0RrYB+tZrgCXJ83HsH/MrNfsqps=
|
||||
cwtch.im/cwtch v0.6.9/go.mod h1:KDy4lWWxcYAjeKclwVFkoTQ2dWnZcM0k3Xck+zEuBmE=
|
||||
cwtch.im/tapir v0.2.1 h1:t1YJB9q5sV1A9xwiiwL6WVfw3dwQWLoecunuzT1PQtw=
|
||||
cwtch.im/tapir v0.2.1/go.mod h1:xzzZ28adyUXNkYL1YodcHsAiTt3IJ8Loc29YVn9mIEQ=
|
||||
git.openprivacy.ca/cwtch.im/tapir v0.3.2 h1:thLWqqY1LkirWFcy9Tg6NgWeYbvo9xBm+s2XVnCIvpY=
|
||||
|
|
50
lib.go
50
lib.go
|
@ -30,7 +30,9 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
profileOnion = event.Field("profileOnion")
|
||||
// ProfileOnion is an event field that contains the handle for a given profile.
|
||||
// todo: this should probably be moved back into Cwtch, and renamed ProfileHandle (onions are too tor-specific)
|
||||
ProfileOnion = event.Field("ProfileOnion")
|
||||
)
|
||||
|
||||
var application app.Application
|
||||
|
@ -353,16 +355,40 @@ func c_AcceptContact(profilePtr *C.char, profileLen C.int, handlePtr *C.char, ha
|
|||
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 {
|
||||
eventHandler.Push(event.NewEvent(event.PeerStateChange, map[event.Field]string{
|
||||
profileOnion: profile,
|
||||
event.RemotePeer: handle,
|
||||
"authorization": string(model.AuthApproved),
|
||||
}))
|
||||
// AcceptContact takes in a profileOnion and a handle to either a group or a peer and authorizes the handle
|
||||
// for further action (e.g. messaging / connecting to the server / joining the group etc.)
|
||||
func AcceptContact(profileOnion string, handle string) {
|
||||
profile := application.GetPeer(profileOnion)
|
||||
profileHandler := utils.NewPeerHelper(profile)
|
||||
if profileHandler.IsGroup(handle) {
|
||||
profile.AcceptInvite(handle)
|
||||
} else {
|
||||
log.Errorf("error accepting contact: %s", err.Error())
|
||||
err := profile.SetContactAuthorization(handle, model.AuthApproved)
|
||||
if err == nil {
|
||||
eventHandler.Push(event.NewEvent(event.PeerStateChange, map[event.Field]string{
|
||||
ProfileOnion: profileOnion,
|
||||
event.RemotePeer: handle,
|
||||
"authorization": string(model.AuthApproved),
|
||||
}))
|
||||
} else {
|
||||
log.Errorf("error accepting contact: %s", err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//export c_RejectInvite
|
||||
func c_RejectInvite(profilePtr *C.char, profileLen C.int, handlePtr *C.char, handleLen C.int) {
|
||||
RejectInvite(C.GoStringN(profilePtr, profileLen), C.GoStringN(handlePtr, handleLen))
|
||||
}
|
||||
|
||||
// RejectInvite rejects a group invite
|
||||
func RejectInvite(profileOnion string, handle string) {
|
||||
log.Debugf("rejecting invite %v for %v", handle, profileOnion)
|
||||
profile := application.GetPeer(profileOnion)
|
||||
profileHandler := utils.NewPeerHelper(profile)
|
||||
if profileHandler.IsGroup(handle) {
|
||||
profile.RejectInvite(handle)
|
||||
log.Debugf("successfully rejected invite %v for %v", handle, profileOnion)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -375,7 +401,7 @@ func BlockContact(profile, handle string) {
|
|||
err := application.GetPeer(profile).SetContactAuthorization(handle, model.AuthBlocked)
|
||||
if err == nil {
|
||||
eventHandler.Push(event.NewEvent(event.PeerStateChange, map[event.Field]string{
|
||||
profileOnion: profile,
|
||||
ProfileOnion: profile,
|
||||
event.RemotePeer: handle,
|
||||
"authorization": string(model.AuthBlocked),
|
||||
}))
|
||||
|
@ -393,7 +419,7 @@ func DebugResetContact(profile, handle string) {
|
|||
err := application.GetPeer(profile).SetContactAuthorization(handle, model.AuthUnknown)
|
||||
if err == nil {
|
||||
application.GetPrimaryBus().Publish(event.NewEvent(event.PeerStateChange, map[event.Field]string{
|
||||
profileOnion: profile,
|
||||
ProfileOnion: profile,
|
||||
event.RemotePeer: handle,
|
||||
"authorization": string(model.AuthUnknown),
|
||||
}))
|
||||
|
|
|
@ -162,9 +162,6 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string {
|
|||
ph := NewPeerHelper(profile)
|
||||
cpicPath := ph.GetProfilePic(groupId)
|
||||
|
||||
// todo hack for now, auto accept groups
|
||||
profile.AcceptInvite(groupId)
|
||||
|
||||
authorization := model.AuthUnknown
|
||||
if group.Accepted {
|
||||
authorization = model.AuthApproved
|
||||
|
@ -344,6 +341,7 @@ func (eh *EventHandler) startHandlingPeer(onion string) {
|
|||
eventBus.Subscribe(event.PeerAcknowledgement, q)
|
||||
eventBus.Subscribe(event.NewMessageFromGroup, q)
|
||||
eventBus.Subscribe(event.NewGroupInvite, q)
|
||||
eventBus.Subscribe(event.AcceptGroupInvite, q)
|
||||
eventBus.Subscribe(event.SendMessageToGroupError, q)
|
||||
eventBus.Subscribe(event.SendMessageToPeerError, q)
|
||||
eventBus.Subscribe(event.ServerStateChange, q)
|
||||
|
|
Loading…
Reference in New Issue