Refactor to start removing global variables

This commit is contained in:
Mickael Remond
2019-07-27 18:06:55 -07:00
parent a3867dd0b3
commit 7ab6c3a62d
2 changed files with 66 additions and 64 deletions
+4 -18
View File
@@ -7,33 +7,19 @@ import (
"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},
func joinMUC(c xmpp.Sender, toJID *xmpp.Jid) error {
return c.Send(stanza.Presence{Attrs: stanza.Attrs{To: toJID.Full()},
Extensions: []stanza.PresExtension{
stanza.MucPresence{
History: stanza.History{MaxStanzas: stanza.NewNullableInt(0)},
}},
})
}
func leaveMUCs(c xmpp.Sender) {
func leaveMUCs(c xmpp.Sender, mucsToLeave []*xmpp.Jid) {
for _, muc := range mucsToLeave {
if err := c.Send(stanza.Presence{Attrs: stanza.Attrs{
To: muc,
To: muc.Full(),
Type: stanza.PresenceTypeUnavailable,
}}); err != nil {
log.WithField("muc", muc).Errorf("error on leaving muc: %s", err)