From be29dede666ef1f1284da1d8b97819261b5a001e Mon Sep 17 00:00:00 2001 From: Martin/Geno Date: Tue, 11 Sep 2018 20:09:59 +0200 Subject: [PATCH] [BUGFIX] join xmpp on startup --- logmania_example.conf | 4 ++++ output/xmpp/main.go | 44 ++++++++++++++++++++++++------------------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/logmania_example.conf b/logmania_example.conf index ca628fe..7d67b63 100644 --- a/logmania_example.conf +++ b/logmania_example.conf @@ -20,6 +20,10 @@ address = ":10001" type = "udp" address = ":10002" +# [input.logrus] - WIP + +[input.webhook] + ########## # Output # ########## diff --git a/output/xmpp/main.go b/output/xmpp/main.go index 8bcf6f8..fb622d3 100644 --- a/output/xmpp/main.go +++ b/output/xmpp/main.go @@ -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 }