fix - join as postup
This commit is contained in:
parent
efaab7e2dd
commit
8d2c4941c3
|
@ -31,6 +31,7 @@ type Output struct {
|
|||
}
|
||||
|
||||
type OutputConfig struct {
|
||||
Address string `mapstructure:"address"`
|
||||
JID string `mapstructure:"jid"`
|
||||
Password string `mapstructure:"password"`
|
||||
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)
|
||||
|
||||
client, err := xmpp.NewClient(xmpp.Config{
|
||||
Address: config.Address,
|
||||
Jid: config.JID,
|
||||
Password: config.Password,
|
||||
}, router)
|
||||
|
@ -61,33 +63,35 @@ func Init(configInterface interface{}, db *database.DB, bot *bot.Bot) output.Out
|
|||
logger.Error(err)
|
||||
return nil
|
||||
}
|
||||
out.client = client
|
||||
cm := xmpp.NewStreamManager(client, nil)
|
||||
cm := xmpp.NewStreamManager(client, func(c xmpp.StreamClient) {
|
||||
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() {
|
||||
cm.Run()
|
||||
log.Panic("closed connection")
|
||||
}()
|
||||
out.client = client
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
@ -15,11 +15,13 @@ func (out *Output) Join(to string) {
|
|||
logger.Error("xmpp could not generate jid to join ", to, " error:", err)
|
||||
return
|
||||
}
|
||||
maxstanzas := 0
|
||||
toJID.Resource = nickname
|
||||
|
||||
err = out.client.Send(xmpp.Presence{Attrs: xmpp.Attrs{To: toJID.Full()},
|
||||
Extensions: []xmpp.PresExtension{
|
||||
xmpp.MucPresence{
|
||||
History: xmpp.History{MaxStanzas: 0},
|
||||
History: xmpp.History{MaxStanzas: &maxstanzas},
|
||||
}},
|
||||
})
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue