diff options
author | bodqhrohro <bodqhrohro@gmail.com> | 2019-11-29 03:51:41 +0300 |
---|---|---|
committer | bodqhrohro <bodqhrohro@gmail.com> | 2019-11-29 03:51:41 +0300 |
commit | dbe87fafa8fb3c38d6cb22ac335cc76b70b607a6 (patch) | |
tree | 784f16c7e27444c03b865e1f4c03aadac1f18bf8 /xmpp/gateway/gateway.go | |
parent | bcf222b53db2199cb6c784ac8c5b7105d794b6c9 (diff) |
Handle updates of user status
Diffstat (limited to 'xmpp/gateway/gateway.go')
-rw-r--r-- | xmpp/gateway/gateway.go | 43 |
1 files changed, 29 insertions, 14 deletions
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 |