Conversations/src/eu/siacs/conversations/generator/PresenceGenerator.java

43 lines
1.3 KiB
Java
Raw Normal View History

package eu.siacs.conversations.generator;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.xmpp.stanzas.PresencePacket;
public class PresenceGenerator {
2014-07-12 11:13:18 +02:00
private PresencePacket subscription(String type, Contact contact) {
PresencePacket packet = new PresencePacket();
2014-07-12 11:13:18 +02:00
packet.setAttribute("type", type);
packet.setAttribute("to", contact.getJid());
packet.setAttribute("from", contact.getAccount().getJid());
return packet;
}
2014-07-12 11:13:18 +02:00
public PresencePacket requestPresenceUpdatesFrom(Contact contact) {
return subscription("subscribe", contact);
}
public PresencePacket stopPresenceUpdatesFrom(Contact contact) {
2014-07-12 11:13:18 +02:00
return subscription("unsubscribe", contact);
}
public PresencePacket stopPresenceUpdatesTo(Contact contact) {
2014-07-12 11:13:18 +02:00
return subscription("unsubscribed", contact);
}
public PresencePacket sendPresenceUpdatesTo(Contact contact) {
2014-07-12 11:13:18 +02:00
return subscription("subscribed", contact);
}
public PresencePacket sendPresence(Account account) {
PresencePacket packet = new PresencePacket();
packet.setAttribute("from", account.getFullJid());
String sig = account.getPgpSignature();
if (sig != null) {
packet.addChild("status").setContent("online");
packet.addChild("x", "jabber:x:signed").setContent(sig);
}
return packet;
}
}