41 lines
779 B
Go
41 lines
779 B
Go
package runtime
|
|
|
|
import (
|
|
"github.com/bdlm/log"
|
|
"gosrc.io/xmpp"
|
|
"gosrc.io/xmpp/stanza"
|
|
)
|
|
|
|
var mucs []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()
|
|
|
|
mucs = append(mucs, jid)
|
|
|
|
return c.Send(stanza.Presence{Attrs: stanza.Attrs{To: jid},
|
|
Extensions: []stanza.PresExtension{
|
|
stanza.MucPresence{
|
|
History: stanza.History{MaxStanzas: stanza.NewNullableInt(0)},
|
|
}},
|
|
})
|
|
|
|
}
|
|
|
|
func LeaveAllMUCs(c xmpp.Sender) {
|
|
|
|
for _, muc := range mucs {
|
|
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)
|
|
}
|
|
}
|
|
}
|