readd deletecontact and wire in
This commit is contained in:
parent
3dc5dbb38e
commit
60caa08868
|
@ -129,6 +129,9 @@ const (
|
|||
// Data [serialized *model.Group]
|
||||
GroupCreated = Type("GroupCreated")
|
||||
|
||||
// RemotePeer
|
||||
DeleteContact = Type("DeleteContact")
|
||||
|
||||
// PeerStateChange servers as a new incoming connection message as well, and can/is consumed by frontends to alert of new p2p connections
|
||||
// RemotePeer
|
||||
// ConnectionState
|
||||
|
|
|
@ -614,8 +614,13 @@ func (cp *cwtchPeer) FetchConversationInfo(handle string) (*model.Conversation,
|
|||
func (cp *cwtchPeer) DeleteConversation(id int) error {
|
||||
cp.mutex.Lock()
|
||||
defer cp.mutex.Unlock()
|
||||
ci, err := cp.storage.GetConversation(id)
|
||||
if err == nil && ci != nil {
|
||||
cp.eventBus.Publish(event.NewEventList(event.DeleteContact, event.RemotePeer, ci.Handle))
|
||||
return cp.storage.DeleteConversation(id)
|
||||
}
|
||||
return fmt.Errorf("could not delete conversation, did not exist")
|
||||
}
|
||||
|
||||
// SetConversationAttribute sets the conversation attribute at path to value
|
||||
func (cp *cwtchPeer) SetConversationAttribute(id int, path attr.ScopedZonedPath, value string) error {
|
||||
|
|
|
@ -101,6 +101,7 @@ func NewProtocolEngine(identity primitives.Identity, privateKey ed25519.PrivateK
|
|||
engine.eventManager.Subscribe(event.SendMessageToPeer, engine.queue)
|
||||
engine.eventManager.Subscribe(event.SendGetValMessageToPeer, engine.queue)
|
||||
engine.eventManager.Subscribe(event.SendRetValMessageToPeer, engine.queue)
|
||||
engine.eventManager.Subscribe(event.DeleteContact, engine.queue)
|
||||
|
||||
engine.eventManager.Subscribe(event.UpdateConversationAuthorization, engine.queue)
|
||||
engine.eventManager.Subscribe(event.BlockUnknownPeers, engine.queue)
|
||||
|
@ -159,6 +160,11 @@ func (e *engine) eventHandler() {
|
|||
go e.peerWithTokenServer(ev.Data[event.GroupServer], ev.Data[event.ServerTokenOnion], ev.Data[event.ServerTokenY], signature)
|
||||
case event.LeaveServer:
|
||||
e.leaveServer(ev.Data[event.GroupServer])
|
||||
case event.DeleteContact:
|
||||
onion := ev.Data[event.RemotePeer]
|
||||
// We remove this peer from out blocklist which will prevent them from contacting us if we have "block unknown peers" turned on.
|
||||
e.authorizations.Delete(ev.Data[event.RemotePeer])
|
||||
e.deleteConnection(onion)
|
||||
case event.SendMessageToGroup:
|
||||
ciphertext, _ := base64.StdEncoding.DecodeString(ev.Data[event.Ciphertext])
|
||||
signature, _ := base64.StdEncoding.DecodeString(ev.Data[event.Signature])
|
||||
|
@ -525,6 +531,13 @@ func (e *engine) sendRetValToPeer(eventID, onion, val, existsStr string) error {
|
|||
return e.sendPeerMessage(onion, pmodel.PeerMessage{ID: eventID, Context: event.ContextRetVal, Data: message})
|
||||
}
|
||||
|
||||
func (e *engine) deleteConnection(id string) {
|
||||
conn, err := e.service.GetConnection(id)
|
||||
if err == nil {
|
||||
conn.Close()
|
||||
}
|
||||
}
|
||||
|
||||
// receiveGroupMessage is a callback function that processes GroupMessages from a given server
|
||||
func (e *engine) receiveGroupMessage(server string, gm *groups.EncryptedGroupMessage) {
|
||||
// Publish Event so that a Profile Engine can deal with it.
|
||||
|
|
Loading…
Reference in New Issue