forked from xmppo/go-xmpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xmpp_muc.go
47 lines (41 loc) · 1.1 KB
/
xmpp_muc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright 2013 Flo Lauber <[email protected]>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// TODO(flo):
// - support password protected MUC rooms
// - cleanup signatures of join/leave functions
package xmpp
import (
"fmt"
)
const (
nsMUC = "http://jabber.org/protocol/muc"
nsMUCUser = "http://jabber.org/protocol/muc#user"
)
// xep-0045 7.2
func (c *Client) JoinMUC(jid, nick string) {
if nick == "" {
nick = c.jid
}
fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n"+
"<x xmlns='%s' />\n"+
"</presence>",
xmlEscape(jid), xmlEscape(nick), nsMUC)
}
// xep-0045 7.2.6
func (c *Client) JoinProtectedMUC(jid, nick string, password string) {
if nick == "" {
nick = c.jid
}
fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n"+
"<x xmlns='%s'>\n"+
"<password>%s</password>\n"+
"</x>\n"+
"</presence>",
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password))
}
// xep-0045 7.14
func (c *Client) LeaveMUC(jid string) {
fmt.Fprintf(c.conn, "<presence from='%s' to='%s' type='unavailable' />",
c.jid, xmlEscape(jid))
}