[BUGFIX] join xmpp on startup

This commit is contained in:
Martin/Geno 2018-09-11 20:09:59 +02:00
parent dcd0bd0e8f
commit be29dede66
No known key found for this signature in database
GPG Key ID: 9D7D3C6BFF600C6A
2 changed files with 29 additions and 19 deletions

View File

@ -20,6 +20,10 @@ address = ":10001"
type = "udp"
address = ":10002"
# [input.logrus] - WIP
[input.webhook]
##########
# Output #
##########

View File

@ -135,25 +135,6 @@ func Init(configInterface interface{}, db *database.DB, bot *bot.Bot) output.Out
}
}
}()
for toAddr, toAddresses := range db.NotifiesByAddress {
if toAddresses.Protocol == protoGroup {
toJID := xmppbase.NewJID(toAddresses.To)
toJID.Resource = nickname
err := client.Send(&xmpp.PresenceClient{
To: toJID,
MUC: &xmuc.Base{
History: &xmuc.History{
MaxChars: &historyMaxChars,
},
},
})
if err != nil {
logger.Error("xmpp could not join ", toJID.String(), " error:", err)
} else {
channels[toAddr] = true
}
}
}
logger.WithField("jid", config.JID).Info("startup")
@ -164,6 +145,7 @@ func Init(configInterface interface{}, db *database.DB, bot *bot.Bot) output.Out
DisableTimestamp: true,
},
}
for to, muc := range config.Defaults {
def := &database.Notify{
Protocol: proto,
@ -171,12 +153,36 @@ func Init(configInterface interface{}, db *database.DB, bot *bot.Bot) output.Out
}
if muc {
def.Protocol = protoGroup
out.Join(to)
}
out.defaults = append(out.defaults, def)
}
for _, toAddresses := range db.NotifiesByAddress {
if toAddresses.Protocol == protoGroup {
out.Join(toAddresses.To)
}
}
return out
}
func (out *Output) Join(to string) {
toJID := xmppbase.NewJID(to)
toJID.Resource = nickname
err := out.client.Send(&xmpp.PresenceClient{
To: toJID,
MUC: &xmuc.Base{
History: &xmuc.History{
MaxChars: &historyMaxChars,
},
},
})
if err != nil {
logger.Error("xmpp could not join ", toJID.String(), " error:", err)
} else {
out.channels[to] = true
}
}
func (out *Output) Default() []*database.Notify {
return out.defaults
}