aboutsummaryrefslogtreecommitdiff
path: root/xmpp
diff options
context:
space:
mode:
authorbodqhrohro <bodqhrohro@gmail.com>2019-11-29 03:51:41 +0300
committerbodqhrohro <bodqhrohro@gmail.com>2019-11-29 03:51:41 +0300
commitdbe87fafa8fb3c38d6cb22ac335cc76b70b607a6 (patch)
tree784f16c7e27444c03b865e1f4c03aadac1f18bf8 /xmpp
parentbcf222b53db2199cb6c784ac8c5b7105d794b6c9 (diff)
Handle updates of user status
Diffstat (limited to 'xmpp')
-rw-r--r--xmpp/component.go9
-rw-r--r--xmpp/gateway/gateway.go43
2 files changed, 32 insertions, 20 deletions
diff --git a/xmpp/component.go b/xmpp/component.go
index c0b4a23..57d9c7b 100644
--- a/xmpp/component.go
+++ b/xmpp/component.go
@@ -17,7 +17,6 @@ const pollingInterval time.Duration = 1e7
var tgConf config.TelegramConfig
var sessions map[string]*telegram.Client
-var queue gateway.Queue
var db persistence.SessionsYamlDB
// NewComponent starts a new component and wraps it in
@@ -30,8 +29,6 @@ func NewComponent(conf config.XMPPConfig, tc config.TelegramConfig) (*xmpp.Strea
return nil, nil, err
}
- queue = make(gateway.Queue)
-
tgConf = tc
options := xmpp.ComponentOptions{
@@ -69,7 +66,7 @@ func heartbeat(component *xmpp.Component) {
for jid := range sessions {
for {
- err = gateway.SendPresence(component, queue, jid, probeType)
+ err = gateway.SendPresence(component, jid, probeType)
if err == nil {
break
}
@@ -80,12 +77,12 @@ func heartbeat(component *xmpp.Component) {
log.Info("Starting heartbeat queue")
for {
- for key, presence := range queue {
+ for key, presence := range gateway.Queue {
err = component.Send(presence)
if err != nil {
gateway.LogBadPresence(err, presence)
} else {
- delete(queue, key)
+ delete(gateway.Queue, key)
}
}
time.Sleep(60e9)
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