fix - join as postup
This commit is contained in:
parent
8b8d136779
commit
c3d91aea98
|
@ -6,6 +6,7 @@ import (
|
||||||
"github.com/bdlm/log"
|
"github.com/bdlm/log"
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
"gosrc.io/xmpp"
|
"gosrc.io/xmpp"
|
||||||
|
"gosrc.io/xmpp/stanza"
|
||||||
|
|
||||||
"dev.sum7.eu/genofire/logmania/bot"
|
"dev.sum7.eu/genofire/logmania/bot"
|
||||||
"dev.sum7.eu/genofire/logmania/database"
|
"dev.sum7.eu/genofire/logmania/database"
|
||||||
|
@ -25,12 +26,13 @@ type Output struct {
|
||||||
defaults []*database.Notify
|
defaults []*database.Notify
|
||||||
channels map[string]bool
|
channels map[string]bool
|
||||||
bot *bot.Bot
|
bot *bot.Bot
|
||||||
client *xmpp.Client
|
client xmpp.Sender
|
||||||
botOut chan interface{}
|
botOut chan interface{}
|
||||||
logOut chan interface{}
|
logOut chan interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 +55,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,39 +64,34 @@ 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.Sender) {
|
||||||
cm := xmpp.NewStreamManager(client, nil)
|
for to, muc := range config.Defaults {
|
||||||
go func() {
|
def := &database.Notify{
|
||||||
cm.Run()
|
Protocol: proto,
|
||||||
log.Panic("closed connection")
|
|
||||||
}()
|
|
||||||
|
|
||||||
logger.WithField("jid", config.JID).Info("startup")
|
|
||||||
|
|
||||||
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,
|
|
||||||
To: to,
|
To: to,
|
||||||
RegexIn: make(map[string]*regexp.Regexp),
|
RegexIn: make(map[string]*regexp.Regexp),
|
||||||
MaxPrioIn: log.DebugLevel,
|
MaxPrioIn: log.DebugLevel,
|
||||||
}
|
}
|
||||||
out.Join(to)
|
if muc {
|
||||||
|
def.Protocol = protoGroup
|
||||||
|
out.Join(to)
|
||||||
|
}
|
||||||
|
out.defaults = append(out.defaults, def)
|
||||||
}
|
}
|
||||||
out.defaults = append(out.defaults, def)
|
for _, toAddresses := range db.NotifiesByAddress {
|
||||||
}
|
if toAddresses.Protocol == protoGroup {
|
||||||
for _, toAddresses := range db.NotifiesByAddress {
|
out.Join(toAddresses.To)
|
||||||
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")
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,9 +106,9 @@ func (out *Output) Close() {
|
||||||
logger.Error("xmpp could generate jid to leave ", jid, " error:", err)
|
logger.Error("xmpp could generate jid to leave ", jid, " error:", err)
|
||||||
}
|
}
|
||||||
toJID.Resource = nickname
|
toJID.Resource = nickname
|
||||||
err = out.client.Send(xmpp.Presence{Attrs: xmpp.Attrs{
|
err = out.client.Send(stanza.Presence{Attrs: stanza.Attrs{
|
||||||
To: toJID.Full(),
|
To: toJID.Full(),
|
||||||
Type: xmpp.PresenceTypeUnavailable,
|
Type: stanza.PresenceTypeUnavailable,
|
||||||
}})
|
}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("xmpp could not leave ", toJID.Full(), " error:", err)
|
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)
|
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 {
|
||||||
|
|
Loading…
Reference in New Issue