mirror of
https://github.com/FluuxIO/go-xmpp.git
synced 2024-11-26 20:32:02 -08:00
43 lines
835 B
Go
43 lines
835 B
Go
package main
|
|
|
|
import (
|
|
"github.com/bdlm/log"
|
|
|
|
"gosrc.io/xmpp"
|
|
"gosrc.io/xmpp/stanza"
|
|
)
|
|
|
|
// FIXME: Remove global variables
|
|
var mucsToLeave []string
|
|
|
|
func joinMUC(c xmpp.Sender, to, nick string) error {
|
|
|
|
toJID, err := xmpp.NewJid(to)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
toJID.Resource = nick
|
|
jid := toJID.Full()
|
|
|
|
mucsToLeave = append(mucsToLeave, jid)
|
|
|
|
return c.Send(stanza.Presence{Attrs: stanza.Attrs{To: jid},
|
|
Extensions: []stanza.PresExtension{
|
|
stanza.MucPresence{
|
|
History: stanza.History{MaxStanzas: stanza.NewNullableInt(0)},
|
|
}},
|
|
})
|
|
|
|
}
|
|
|
|
func leaveMUCs(c xmpp.Sender) {
|
|
for _, muc := range mucsToLeave {
|
|
if err := c.Send(stanza.Presence{Attrs: stanza.Attrs{
|
|
To: muc,
|
|
Type: stanza.PresenceTypeUnavailable,
|
|
}}); err != nil {
|
|
log.WithField("muc", muc).Errorf("error on leaving muc: %s", err)
|
|
}
|
|
}
|
|
}
|