fix - join as postup

This commit is contained in:
Martin/Geno 2019-06-24 17:44:48 +02:00
parent efaab7e2dd
commit 8d2c4941c3
No known key found for this signature in database
GPG Key ID: 9D7D3C6BFF600C6A
2 changed files with 27 additions and 21 deletions

View File

@ -31,6 +31,7 @@ type Output struct {
} }
type OutputConfig struct { type OutputConfig struct {
Address string `mapstructure:"address"`
JID string `mapstructure:"jid"` JID string `mapstructure:"jid"`
Password string `mapstructure:"password"` Password string `mapstructure:"password"`
Defaults map[string]bool `mapstructure:"default"` Defaults map[string]bool `mapstructure:"default"`
@ -53,6 +54,7 @@ func Init(configInterface interface{}, db *database.DB, bot *bot.Bot) output.Out
router.HandleFunc("presence", out.recvPresence) router.HandleFunc("presence", out.recvPresence)
client, err := xmpp.NewClient(xmpp.Config{ client, err := xmpp.NewClient(xmpp.Config{
Address: config.Address,
Jid: config.JID, Jid: config.JID,
Password: config.Password, Password: config.Password,
}, router) }, router)
@ -61,15 +63,7 @@ func Init(configInterface interface{}, db *database.DB, bot *bot.Bot) output.Out
logger.Error(err) logger.Error(err)
return nil return nil
} }
out.client = client cm := xmpp.NewStreamManager(client, func(c xmpp.StreamClient) {
cm := xmpp.NewStreamManager(client, nil)
go func() {
cm.Run()
log.Panic("closed connection")
}()
logger.WithField("jid", config.JID).Info("startup")
for to, muc := range config.Defaults { for to, muc := range config.Defaults {
def := &database.Notify{ def := &database.Notify{
Protocol: proto, Protocol: proto,
@ -88,6 +82,16 @@ func Init(configInterface interface{}, db *database.DB, bot *bot.Bot) output.Out
out.Join(toAddresses.To) out.Join(toAddresses.To)
} }
} }
logger.Info("join muc after connect")
})
go func() {
cm.Run()
log.Panic("closed connection")
}()
out.client = client
logger.WithField("jid", config.JID).Info("startup")
return out return out
} }

View File

@ -15,11 +15,13 @@ func (out *Output) Join(to string) {
logger.Error("xmpp could not generate jid to join ", to, " error:", err) logger.Error("xmpp could not generate jid to join ", to, " error:", err)
return return
} }
maxstanzas := 0
toJID.Resource = nickname toJID.Resource = nickname
err = out.client.Send(xmpp.Presence{Attrs: xmpp.Attrs{To: toJID.Full()}, err = out.client.Send(xmpp.Presence{Attrs: xmpp.Attrs{To: toJID.Full()},
Extensions: []xmpp.PresExtension{ Extensions: []xmpp.PresExtension{
xmpp.MucPresence{ xmpp.MucPresence{
History: xmpp.History{MaxStanzas: 0}, History: xmpp.History{MaxStanzas: &maxstanzas},
}}, }},
}) })
if err != nil { if err != nil {