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,33 +63,35 @@ 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) for to, muc := range config.Defaults {
def := &database.Notify{
Protocol: proto,
To: to,
RegexIn: make(map[string]*regexp.Regexp),
MaxPrioIn: log.DebugLevel,
}
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)
}
}
logger.Info("join muc after connect")
})
go func() { go func() {
cm.Run() cm.Run()
log.Panic("closed connection") log.Panic("closed connection")
}() }()
out.client = client
logger.WithField("jid", config.JID).Info("startup") logger.WithField("jid", config.JID).Info("startup")
for to, muc := range config.Defaults {
def := &database.Notify{
Protocol: proto,
To: to,
RegexIn: make(map[string]*regexp.Regexp),
MaxPrioIn: log.DebugLevel,
}
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 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 {