forked from jshiffer/go-xmpp
Merge pull request #70 from tcriess/master
Add SendPresence, add join muc with history, add function return valu…
This commit is contained in:
commit
12d5633a9d
4
xmpp.go
4
xmpp.go
@ -614,6 +614,10 @@ func (c *Client) SendOrg(org string) (n int, err error) {
|
|||||||
return fmt.Fprint(c.conn, org)
|
return fmt.Fprint(c.conn, org)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) SendPresence(presence Presence) (n int, err error) {
|
||||||
|
return fmt.Fprintf(c.conn, "<presence from='%s' to='%s'/>", xmlEscape(presence.From), xmlEscape(presence.To))
|
||||||
|
}
|
||||||
|
|
||||||
// SendHtml sends the message as HTML as defined by XEP-0071
|
// SendHtml sends the message as HTML as defined by XEP-0071
|
||||||
func (c *Client) SendHtml(chat Chat) (n int, err error) {
|
func (c *Client) SendHtml(chat Chat) (n int, err error) {
|
||||||
return fmt.Fprintf(c.conn, "<message to='%s' type='%s' xml:lang='en'>"+
|
return fmt.Fprintf(c.conn, "<message to='%s' type='%s' xml:lang='en'>"+
|
||||||
|
107
xmpp_muc.go
107
xmpp_muc.go
@ -9,39 +9,126 @@ package xmpp
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
"errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
nsMUC = "http://jabber.org/protocol/muc"
|
nsMUC = "http://jabber.org/protocol/muc"
|
||||||
nsMUCUser = "http://jabber.org/protocol/muc#user"
|
nsMUCUser = "http://jabber.org/protocol/muc#user"
|
||||||
|
NoHistory = 0
|
||||||
|
CharHistory = 1
|
||||||
|
StanzaHistory = 2
|
||||||
|
SecondsHistory = 3
|
||||||
|
SinceHistory = 4
|
||||||
)
|
)
|
||||||
|
|
||||||
// xep-0045 7.2
|
// Send sends room topic wrapped inside an XMPP message stanza body.
|
||||||
func (c *Client) JoinMUC(jid, nick string) {
|
func (c *Client) SendTopic(chat Chat) (n int, err error) {
|
||||||
|
return fmt.Fprintf(c.conn, "<message to='%s' type='%s' xml:lang='en'>"+"<subject>%s</subject></message>",
|
||||||
|
xmlEscape(chat.Remote), xmlEscape(chat.Type), xmlEscape(chat.Text))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) JoinMUCNoHistory(jid, nick string) (n int, err error) {
|
||||||
if nick == "" {
|
if nick == "" {
|
||||||
nick = c.jid
|
nick = c.jid
|
||||||
}
|
}
|
||||||
fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n"+
|
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n"+
|
||||||
"<x xmlns='%s' />\n"+
|
"<x xmlns='%s'>"+
|
||||||
|
"<history maxchars='0'/></x>\n"+
|
||||||
"</presence>",
|
"</presence>",
|
||||||
xmlEscape(jid), xmlEscape(nick), nsMUC)
|
xmlEscape(jid), xmlEscape(nick), nsMUC)
|
||||||
}
|
}
|
||||||
|
|
||||||
// xep-0045 7.2.6
|
// xep-0045 7.2
|
||||||
func (c *Client) JoinProtectedMUC(jid, nick string, password string) {
|
func (c *Client) JoinMUC(jid, nick string, history_type, history int, history_date *time.Time) (n int, err error) {
|
||||||
if nick == "" {
|
if nick == "" {
|
||||||
nick = c.jid
|
nick = c.jid
|
||||||
}
|
}
|
||||||
fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n"+
|
switch history_type {
|
||||||
|
case NoHistory:
|
||||||
|
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n" +
|
||||||
|
"<x xmlns='%s' />\n" +
|
||||||
|
"</presence>",
|
||||||
|
xmlEscape(jid), xmlEscape(nick), nsMUC)
|
||||||
|
case CharHistory:
|
||||||
|
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n" +
|
||||||
|
"<x xmlns='%s'>\n" +
|
||||||
|
"<history maxchars='%d'/></x>\n"+
|
||||||
|
"</presence>",
|
||||||
|
xmlEscape(jid), xmlEscape(nick), nsMUC, history)
|
||||||
|
case StanzaHistory:
|
||||||
|
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n" +
|
||||||
|
"<x xmlns='%s'>\n" +
|
||||||
|
"<history maxstanzas='%d'/></x>\n"+
|
||||||
|
"</presence>",
|
||||||
|
xmlEscape(jid), xmlEscape(nick), nsMUC, history)
|
||||||
|
case SecondsHistory:
|
||||||
|
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n" +
|
||||||
|
"<x xmlns='%s'>\n" +
|
||||||
|
"<history seconds='%d'/></x>\n"+
|
||||||
|
"</presence>",
|
||||||
|
xmlEscape(jid), xmlEscape(nick), nsMUC, history)
|
||||||
|
case SinceHistory:
|
||||||
|
if history_date != nil {
|
||||||
|
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n" +
|
||||||
|
"<x xmlns='%s'>\n" +
|
||||||
|
"<history since='%s'/></x>\n" +
|
||||||
|
"</presence>",
|
||||||
|
xmlEscape(jid), xmlEscape(nick), nsMUC, history_date.Format(time.RFC3339))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0, errors.New("Unknown history option")
|
||||||
|
}
|
||||||
|
|
||||||
|
// xep-0045 7.2.6
|
||||||
|
func (c *Client) JoinProtectedMUC(jid, nick string, password string, history_type, history int, history_date *time.Time) (n int, err error) {
|
||||||
|
if nick == "" {
|
||||||
|
nick = c.jid
|
||||||
|
}
|
||||||
|
switch history_type {
|
||||||
|
case NoHistory:
|
||||||
|
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n" +
|
||||||
"<x xmlns='%s'>\n" +
|
"<x xmlns='%s'>\n" +
|
||||||
"<password>%s</password>\n"+
|
"<password>%s</password>\n"+
|
||||||
"</x>\n"+
|
|
||||||
"</presence>",
|
"</presence>",
|
||||||
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password))
|
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password))
|
||||||
|
case CharHistory:
|
||||||
|
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n" +
|
||||||
|
"<x xmlns='%s'>\n" +
|
||||||
|
"<password>%s</password>\n"+
|
||||||
|
"<history maxchars='%d'/></x>\n"+
|
||||||
|
"</presence>",
|
||||||
|
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history)
|
||||||
|
case StanzaHistory:
|
||||||
|
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n" +
|
||||||
|
"<x xmlns='%s'>\n" +
|
||||||
|
"<password>%s</password>\n"+
|
||||||
|
"<history maxstanzas='%d'/></x>\n"+
|
||||||
|
"</presence>",
|
||||||
|
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history)
|
||||||
|
case SecondsHistory:
|
||||||
|
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n" +
|
||||||
|
"<x xmlns='%s'>\n" +
|
||||||
|
"<password>%s</password>\n"+
|
||||||
|
"<history seconds='%d'/></x>\n"+
|
||||||
|
"</presence>",
|
||||||
|
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history)
|
||||||
|
case SinceHistory:
|
||||||
|
if history_date != nil {
|
||||||
|
return fmt.Fprintf(c.conn, "<presence to='%s/%s'>\n" +
|
||||||
|
"<x xmlns='%s'>\n" +
|
||||||
|
"<password>%s</password>\n"+
|
||||||
|
"<history since='%s'/></x>\n" +
|
||||||
|
"</presence>",
|
||||||
|
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history_date.Format(time.RFC3339))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0, errors.New("Unknown history option")
|
||||||
}
|
}
|
||||||
|
|
||||||
// xep-0045 7.14
|
// xep-0045 7.14
|
||||||
func (c *Client) LeaveMUC(jid string) {
|
func (c *Client) LeaveMUC(jid string) (n int, err error) {
|
||||||
fmt.Fprintf(c.conn, "<presence from='%s' to='%s' type='unavailable' />",
|
return fmt.Fprintf(c.conn, "<presence from='%s' to='%s' type='unavailable' />",
|
||||||
c.jid, xmlEscape(jid))
|
c.jid, xmlEscape(jid))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user