~samwhited/xmpp

ref: c71a17569b03f07e0fc407f1da2094c1796cec90 xmpp/presence.go -rw-r--r-- 2.2 KiB
c71a1756Sam Whited ibr2: Add API stability disclaimer to docs 4 years ago
                                                                                
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2016 Sam Whited.
// Use of this source code is governed by the BSD 2-clause license that can be
// found in the LICENSE file.

package xmpp

import (
	"encoding/xml"

	"mellium.im/xmpp/jid"
)

// Presence is an XMPP stanza that is used as an indication that an entity is
// available for communication. It is used to set a status message, broadcast
// availability, and advertise entity capabilities. It can be directed
// (one-to-one), or used as a broadcast mechanism (one-to-many).
type Presence struct {
	XMLName xml.Name     `xml:"presence"`
	ID      string       `xml:"id,attr"`
	Inner   string       `xml:",innerxml"`
	To      *jid.JID     `xml:"to,attr"`
	From    *jid.JID     `xml:"from,attr"`
	Lang    string       `xml:"http://www.w3.org/XML/1998/namespace lang,attr,omitempty"`
	Type    presenceType `xml:"type,attr,omitempty"`
}

func (p Presence) copyPresence() Presence {
	return p
}

type presenceType int

const (
	// NoTypePresence is a special type that indicates that a stanza is a presence
	// stanza without a defined type (indicating availability on the network).
	NoTypePresence presenceType = iota

	// ErrorPresence indicates that an error has occurred regarding processing of
	// a previously sent presence stanza; if the presence stanza is of type
	// "error", it MUST include an <error/> child element
	ErrorPresence presenceType = iota

	// ProbePresence is a request for an entity's current presence. It should
	// generally only be generated and sent by servers on behalf of a user.
	ProbePresence

	// SubscribePresence is sent when the sender wishes to subscribe to the
	// recipient's presence.
	SubscribePresence

	// SubscribedPresence indicates that the sender has allowed the recipient to
	// receive future presence broadcasts.
	SubscribedPresence

	// UnavailablePresence indicates that the sender is no longer available for
	// communication.
	UnavailablePresence

	// UnsubscribePresence indicates that the sender is unsubscribing from the
	// receiver's presence.
	UnsubscribePresence

	// UnsubscribedPresence indicates that the subscription request has been
	// denied, or a previously granted subscription has been revoked.
	UnsubscribedPresence
)