fix - join as postup
This commit is contained in:
parent
8b8d136779
commit
c3d91aea98
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/bdlm/log"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"gosrc.io/xmpp"
|
||||
"gosrc.io/xmpp/stanza"
|
||||
|
||||
"dev.sum7.eu/genofire/logmania/bot"
|
||||
"dev.sum7.eu/genofire/logmania/database"
|
||||
|
@ -25,12 +26,13 @@ type Output struct {
|
|||
defaults []*database.Notify
|
||||
channels map[string]bool
|
||||
bot *bot.Bot
|
||||
client *xmpp.Client
|
||||
client xmpp.Sender
|
||||
botOut chan interface{}
|
||||
logOut chan interface{}
|
||||
}
|
||||
|
||||
type OutputConfig struct {
|
||||
Address string `mapstructure:"address"`
|
||||
JID string `mapstructure:"jid"`
|
||||
Password string `mapstructure:"password"`
|
||||
Defaults map[string]bool `mapstructure:"default"`
|
||||
|
@ -53,6 +55,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,30 +64,16 @@ 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)
|
||||
go func() {
|
||||
cm.Run()
|
||||
log.Panic("closed connection")
|
||||
}()
|
||||
|
||||
logger.WithField("jid", config.JID).Info("startup")
|
||||
|
||||
cm := xmpp.NewStreamManager(client, func(c xmpp.Sender) {
|
||||
for to, muc := range config.Defaults {
|
||||
var def *database.Notify
|
||||
pro := proto
|
||||
if muc {
|
||||
pro = protoGroup
|
||||
}
|
||||
if dbNotify, ok := db.NotifiesByAddress[pro+":"+to]; ok {
|
||||
def = dbNotify
|
||||
} else {
|
||||
def = &database.Notify{
|
||||
Protocol: pro,
|
||||
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)
|
||||
|
@ -94,6 +83,15 @@ func Init(configInterface interface{}, db *database.DB, bot *bot.Bot) output.Out
|
|||
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
|
||||
}
|
||||
|
||||
|
@ -108,9 +106,9 @@ func (out *Output) Close() {
|
|||
logger.Error("xmpp could generate jid to leave ", jid, " error:", err)
|
||||
}
|
||||
toJID.Resource = nickname
|
||||
err = out.client.Send(xmpp.Presence{Attrs: xmpp.Attrs{
|
||||
err = out.client.Send(stanza.Presence{Attrs: stanza.Attrs{
|
||||
To: toJID.Full(),
|
||||
Type: xmpp.PresenceTypeUnavailable,
|
||||
Type: stanza.PresenceTypeUnavailable,
|
||||
}})
|
||||
if err != nil {
|
||||
logger.Error("xmpp could not leave ", toJID.Full(), " error:", err)
|
||||
|
|
|
@ -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