Added a JID.Bare() function, to product the bare JID as defined in the RFC.
authorChris Jones <chris@cjones.org>
Sat, 09 Nov 2013 12:22:01 -0700
changeset 179 4477c9f31f43
parent 178 ccfebbd9f49b
child 180 3010996c1928
Added a JID.Bare() function, to product the bare JID as defined in the RFC.
xmpp/structs.go
--- a/xmpp/structs.go	Sat Nov 09 12:09:37 2013 -0700
+++ b/xmpp/structs.go	Sat Nov 09 12:22:01 2013 -0700
@@ -183,6 +183,15 @@
 	return string(j[slash+1:])
 }
 
+// Returns the bare JID, which is the JID without the resource part.
+func (j JID) Bare() JID {
+	node := j.Node()
+	if node == "" {
+		return JID(j.Domain())
+	}
+	return JID(fmt.Sprintf("%s@%s", node, j.Domain()))
+}
+
 func (s *stream) String() string {
 	var buf bytes.Buffer
 	buf.WriteString(`<stream:stream xmlns="`)