PresenceGenerator.java

 1package eu.siacs.conversations.generator;
 2
 3import eu.siacs.conversations.entities.Account;
 4import eu.siacs.conversations.entities.Contact;
 5import eu.siacs.conversations.xmpp.stanzas.PresencePacket;
 6
 7public class PresenceGenerator {
 8
 9	public PresencePacket requestPresenceUpdatesFrom(Contact contact) {
10		PresencePacket packet = new PresencePacket();
11		packet.setAttribute("type", "subscribe");
12		packet.setAttribute("to", contact.getJid());
13		packet.setAttribute("from", contact.getAccount().getJid());
14		return packet;
15	}
16
17	public PresencePacket stopPresenceUpdatesFrom(Contact contact) {
18		PresencePacket packet = new PresencePacket();
19		packet.setAttribute("type", "unsubscribe");
20		packet.setAttribute("to", contact.getJid());
21		packet.setAttribute("from", contact.getAccount().getJid());
22		return packet;
23	}
24
25	public PresencePacket stopPresenceUpdatesTo(Contact contact) {
26		PresencePacket packet = new PresencePacket();
27		packet.setAttribute("type", "unsubscribed");
28		packet.setAttribute("to", contact.getJid());
29		packet.setAttribute("from", contact.getAccount().getJid());
30		return packet;
31	}
32
33	public PresencePacket sendPresenceUpdatesTo(Contact contact) {
34		PresencePacket packet = new PresencePacket();
35		packet.setAttribute("type", "subscribed");
36		packet.setAttribute("to", contact.getJid());
37		packet.setAttribute("from", contact.getAccount().getJid());
38		return packet;
39	}
40
41	public PresencePacket sendPresence(Account account) {
42		PresencePacket packet = new PresencePacket();
43		packet.setAttribute("from", account.getFullJid());
44		String sig = account.getPgpSignature();
45		if (sig != null) {
46			packet.addChild("status").setContent("online");
47			packet.addChild("x", "jabber:x:signed").setContent(sig);
48		}
49		return packet;
50	}
51}