From dbe87fafa8fb3c38d6cb22ac335cc76b70b607a6 Mon Sep 17 00:00:00 2001 From: bodqhrohro Date: Fri, 29 Nov 2019 02:51:41 +0200 Subject: Handle updates of user status --- xmpp/gateway/gateway.go | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) (limited to 'xmpp/gateway/gateway.go') diff --git a/xmpp/gateway/gateway.go b/xmpp/gateway/gateway.go index 11f68c1..be1f6a3 100644 --- a/xmpp/gateway/gateway.go +++ b/xmpp/gateway/gateway.go @@ -13,7 +13,7 @@ import ( ) // Queue stores presences to send later -type Queue map[string]*stanza.Presence +var Queue = make(map[string]*stanza.Presence) // Jid stores the component's JID object var Jid *xmpp.Jid @@ -101,32 +101,47 @@ func newPresence(bareJid string, to string, args ...args.V) stanza.Presence { }} if SPType.IsSet(args) { - presence.Attrs.Type = stanza.StanzaType(SPType.Get(args)) + t := SPType.Get(args) + if t != "" { + presence.Attrs.Type = stanza.StanzaType(t) + } } if SPShow.IsSet(args) { - presence.Show = stanza.PresenceShow(SPShow.Get(args)) + show := SPShow.Get(args) + if show != "" { + presence.Show = stanza.PresenceShow(show) + } } if SPStatus.IsSet(args) { - presence.Status = SPStatus.Get(args) + status := SPStatus.Get(args) + if status != "" { + presence.Status = status + } } if SPNickname.IsSet(args) { - presence.Extensions = append(presence.Extensions, extensions.PresenceNickExtension{ - Text: SPNickname.Get(args), - }) + nickname := SPNickname.Get(args) + if nickname != "" { + presence.Extensions = append(presence.Extensions, extensions.PresenceNickExtension{ + Text: nickname, + }) + } } if SPPhoto.IsSet(args) { - presence.Extensions = append(presence.Extensions, extensions.PresenceXVCardUpdateExtension{ - Photo: extensions.PresenceXVCardUpdatePhoto{ - Text: SPPhoto.Get(args), - }, - }) + photo := SPPhoto.Get(args) + if photo != "" { + presence.Extensions = append(presence.Extensions, extensions.PresenceXVCardUpdateExtension{ + Photo: extensions.PresenceXVCardUpdatePhoto{ + Text: photo, + }, + }) + } } return presence } // SendPresence creates and sends a presence stanza -func SendPresence(component *xmpp.Component, queue Queue, to string, args ...args.V) error { +func SendPresence(component *xmpp.Component, to string, args ...args.V) error { var logFrom string bareJid := Jid.Bare() if SPFrom.IsSet(args) { @@ -161,7 +176,7 @@ func SendPresence(component *xmpp.Component, queue Queue, to string, args ...arg return err } } else { - queue[presence.From+presence.To] = &presence + Queue[presence.From+presence.To] = &presence } return nil -- cgit v1.2.3