diff --git a/xmpp/component.go b/xmpp/component.go index 4f5ad79..fb5732e 100644 --- a/xmpp/component.go +++ b/xmpp/component.go @@ -90,7 +90,9 @@ func heartbeat(component *xmpp.Component) { if err != nil { gateway.LogBadPresence(presence) } else { + gateway.QueueLock.Lock() delete(gateway.Queue, key) + gateway.QueueLock.Unlock() } } diff --git a/xmpp/gateway/gateway.go b/xmpp/gateway/gateway.go index a4f3aca..779c6fe 100644 --- a/xmpp/gateway/gateway.go +++ b/xmpp/gateway/gateway.go @@ -3,6 +3,7 @@ package gateway import ( "encoding/xml" "strings" + "sync" "dev.narayana.im/narayana/telegabber/xmpp/extensions" @@ -14,6 +15,7 @@ import ( // Queue stores presences to send later var Queue = make(map[string]*stanza.Presence) +var QueueLock = sync.Mutex{} // Jid stores the component's JID object var Jid *stanza.Jid @@ -178,7 +180,9 @@ func SendPresence(component *xmpp.Component, to string, args ...args.V) error { return err } } else { + QueueLock.Lock() Queue[presence.From+presence.To] = &presence + QueueLock.Unlock() } return nil