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 private PresencePacket subscription(String type, Contact contact) {
10 PresencePacket packet = new PresencePacket();
11 packet.setAttribute("type", type);
12 packet.setAttribute("to", contact.getJid());
13 packet.setAttribute("from", contact.getAccount().getJid());
14 return packet;
15 }
16
17 public PresencePacket requestPresenceUpdatesFrom(Contact contact) {
18 return subscription("subscribe", contact);
19 }
20
21 public PresencePacket stopPresenceUpdatesFrom(Contact contact) {
22 return subscription("unsubscribe", contact);
23 }
24
25 public PresencePacket stopPresenceUpdatesTo(Contact contact) {
26 return subscription("unsubscribed", contact);
27 }
28
29 public PresencePacket sendPresenceUpdatesTo(Contact contact) {
30 return subscription("subscribed", contact);
31 }
32
33 public PresencePacket sendPresence(Account account) {
34 PresencePacket packet = new PresencePacket();
35 packet.setAttribute("from", account.getFullJid());
36 String sig = account.getPgpSignature();
37 if (sig != null) {
38 packet.addChild("status").setContent("online");
39 packet.addChild("x", "jabber:x:signed").setContent(sig);
40 }
41 return packet;
42 }
43}