iterating on eventbus fields #196
|
@ -26,6 +26,8 @@ const (
|
||||||
NewMessageFromPeer = Type("NewMessageFromPeer")
|
NewMessageFromPeer = Type("NewMessageFromPeer")
|
||||||
|
|
||||||
SetProfileName = Type("SetProfileName")
|
SetProfileName = Type("SetProfileName")
|
||||||
|
|
||||||
|
RequestProfileSave = Type("RequestProfileSave")
|
||||||
)
|
)
|
||||||
|
|
||||||
// Field defines common event attributes
|
// Field defines common event attributes
|
||||||
|
|
|
@ -15,6 +15,7 @@ import (
|
||||||
"golang.org/x/crypto/ed25519"
|
"golang.org/x/crypto/ed25519"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// cwtchPeer manages incoming and outgoing connections and all processing for a Cwtch cwtchPeer
|
// cwtchPeer manages incoming and outgoing connections and all processing for a Cwtch cwtchPeer
|
||||||
|
@ -283,7 +284,7 @@ func (cp *cwtchPeer) eventHandler() {
|
||||||
ok, groupID, message := cp.Profile.AttemptDecryption([]byte(ev.Data[event.Ciphertext]), []byte(ev.Data[event.Signature]))
|
ok, groupID, message := cp.Profile.AttemptDecryption([]byte(ev.Data[event.Ciphertext]), []byte(ev.Data[event.Signature]))
|
||||||
log.Debugf("ok,gid,msg = %v,%v,%v", ok, groupID, message)
|
log.Debugf("ok,gid,msg = %v,%v,%v", ok, groupID, message)
|
||||||
if ok {
|
if ok {
|
||||||
cp.eventBus.Publish(event.NewEvent(event.NewMessageFromGroup, map[event.Field]string{event.TimestampReceived: message.Received.String(), event.TimestampSent: message.Timestamp.String(), event.Data: message.Message, event.GroupID: groupID, event.RemotePeer: message.PeerID}))
|
cp.eventBus.Publish(event.NewEvent(event.NewMessageFromGroup, map[event.Field]string{event.TimestampReceived: message.Received.Format(time.RFC3339Nano), event.TimestampSent: message.Timestamp.Format(time.RFC3339Nano), event.Data: message.Message, event.GroupID: groupID, event.RemotePeer: message.PeerID}))
|
||||||
}
|
}
|
||||||
case event.NewGroupInvite:
|
case event.NewGroupInvite:
|
||||||
var groupInvite protocol.GroupChatInvite
|
var groupInvite protocol.GroupChatInvite
|
||||||
|
|
|
@ -259,12 +259,12 @@ func (cph *CwtchPeerHandler) HandleGroupInvite(gci *protocol.GroupChatInvite) {
|
||||||
log.Debugf("Received GroupID from %v %v\n", cph.Onion, gci.String())
|
log.Debugf("Received GroupID from %v %v\n", cph.Onion, gci.String())
|
||||||
marshal, err := proto.Marshal(gci)
|
marshal, err := proto.Marshal(gci)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
cph.EventBus.Publish(event.NewEvent(event.NewGroupInvite, map[event.Field]string{event.TimestampReceived: time.Now().String(), event.RemotePeer: cph.Onion, event.GroupInvite: string(marshal)}))
|
cph.EventBus.Publish(event.NewEvent(event.NewGroupInvite, map[event.Field]string{event.TimestampReceived: time.Now().Format(time.RFC3339Nano), event.RemotePeer: cph.Onion, event.GroupInvite: string(marshal)}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// HandlePacket handles the Cwtch cwtchPeer Data Channel
|
// HandlePacket handles the Cwtch cwtchPeer Data Channel
|
||||||
func (cph *CwtchPeerHandler) HandlePacket(data []byte) []byte {
|
func (cph *CwtchPeerHandler) HandlePacket(data []byte) []byte {
|
||||||
cph.EventBus.Publish(event.NewEvent(event.NewMessageFromPeer, map[event.Field]string{event.TimestampReceived: time.Now().String(), event.RemotePeer: cph.Onion, event.Data: string(data)}))
|
cph.EventBus.Publish(event.NewEvent(event.NewMessageFromPeer, map[event.Field]string{event.TimestampReceived: time.Now().Format(time.RFC3339Nano), event.RemotePeer: cph.Onion, event.Data: string(data)}))
|
||||||
return []byte{} // TODO remove this
|
return []byte{} // TODO remove this
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue