allow custom message handling #325

Merged
sarah merged 18 commits from specify-events into master 2020-10-22 23:34:22 +00:00
1 changed files with 8 additions and 4 deletions
Showing only changes of commit 509e5c95ba - Show all commits

View File

@ -50,6 +50,7 @@ type CwtchPeer interface {
InviteOnionToGroup(string, string) error InviteOnionToGroup(string, string) error
SendMessageToPeer(string, string) string SendMessageToPeer(string, string) string
SendGetValToPeer(string, string, string) SendGetValToPeer(string, string, string)
StoreMessage(onion string, messageTxt string, sent time.Time)
SetContactAuthorization(string, model.Authorization) error SetContactAuthorization(string, model.Authorization) error
ProcessInvite(string, string) (string, error) ProcessInvite(string, string) (string, error)
@ -566,6 +567,12 @@ func (cp *cwtchPeer) Shutdown() {
cp.queue.Shutdown() cp.queue.Shutdown()
} }
func (cp *cwtchPeer) StoreMessage(onion string, messageTxt string, sent time.Time) {
cp.mutex.Lock()
cp.Profile.AddMessageToContactTimeline(onion, messageTxt, sent)
cp.mutex.Unlock()
}
// eventHandler process events from other subsystems // eventHandler process events from other subsystems
func (cp *cwtchPeer) eventHandler() { func (cp *cwtchPeer) eventHandler() {
for { for {
@ -583,10 +590,7 @@ func (cp *cwtchPeer) eventHandler() {
} }
case event.NewMessageFromPeer: //event.TimestampReceived, event.RemotePeer, event.Data case event.NewMessageFromPeer: //event.TimestampReceived, event.RemotePeer, event.Data
ts, _ := time.Parse(time.RFC3339Nano, ev.Data[event.TimestampReceived]) cp.StoreMessage(ev.Data[event.RemotePeer], ev.Data[event.Data], ts)
cp.mutex.Lock()
cp.Profile.AddMessageToContactTimeline(ev.Data[event.RemotePeer], ev.Data[event.Data], ts)
cp.mutex.Unlock()
case event.PeerAcknowledgement: case event.PeerAcknowledgement:
cp.mutex.Lock() cp.mutex.Lock()