aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/generator/PresenceGenerator.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/generator/PresenceGenerator.java')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/generator/PresenceGenerator.java87
1 files changed, 71 insertions, 16 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/generator/PresenceGenerator.java b/src/main/java/de/thedevstack/conversationsplus/generator/PresenceGenerator.java
index f370c6e0..fbe7c911 100644
--- a/src/main/java/de/thedevstack/conversationsplus/generator/PresenceGenerator.java
+++ b/src/main/java/de/thedevstack/conversationsplus/generator/PresenceGenerator.java
@@ -2,41 +2,55 @@ package de.thedevstack.conversationsplus.generator;
import de.thedevstack.conversationsplus.entities.Account;
import de.thedevstack.conversationsplus.entities.Contact;
+import de.thedevstack.conversationsplus.entities.MucOptions;
import de.thedevstack.conversationsplus.entities.Presence;
import de.thedevstack.conversationsplus.xml.Element;
+import de.thedevstack.conversationsplus.xmpp.jid.Jid;
import de.thedevstack.conversationsplus.xmpp.stanzas.PresencePacket;
public class PresenceGenerator extends AbstractGenerator {
- private PresencePacket subscription(String type, Contact contact) {
+ private static PresencePacket generatePresencePacket(String type, Jid from, Jid to) {
PresencePacket packet = new PresencePacket();
+ if (null != type) {
packet.setAttribute("type", type);
- packet.setTo(contact.getJid());
- packet.setFrom(contact.getAccount().getJid().toBareJid());
+ }
+
+ if (null != to) {
+ packet.setTo(to);
+ }
+
+ if (null != from) {
+ packet.setFrom(from);
+ }
+
return packet;
+
}
- public PresencePacket requestPresenceUpdatesFrom(Contact contact) {
+ private static PresencePacket subscription(String type, Contact contact) {
+ return generatePresencePacket(type, contact.getAccount().getJid().toBareJid(), contact.getJid());
+ }
+
+ public static PresencePacket requestPresenceUpdatesFrom(Contact contact) {
return subscription("subscribe", contact);
}
- public PresencePacket stopPresenceUpdatesFrom(Contact contact) {
+ public static PresencePacket stopPresenceUpdatesFrom(Contact contact) {
return subscription("unsubscribe", contact);
}
- public PresencePacket stopPresenceUpdatesTo(Contact contact) {
+ public static PresencePacket stopPresenceUpdatesTo(Contact contact) {
return subscription("unsubscribed", contact);
}
- public PresencePacket sendPresenceUpdatesTo(Contact contact) {
+ public static PresencePacket sendPresenceUpdatesTo(Contact contact) {
return subscription("subscribed", contact);
}
- public PresencePacket selfPresence(Account account, Presence.Status status) {
- PresencePacket packet = new PresencePacket();
- if(status.toShowString() != null) {
- packet.addChild("show").setContent(status.toShowString());
- }
+ public static PresencePacket selfPresence(Account account, Presence.Status status) {
+ PresencePacket packet = new PresencePacket(status);
+
packet.setFrom(account.getJid());
String sig = account.getPgpSignature();
if (sig != null) {
@@ -53,10 +67,51 @@ public class PresenceGenerator extends AbstractGenerator {
return packet;
}
- public PresencePacket sendOfflinePresence(Account account) {
- PresencePacket packet = new PresencePacket();
- packet.setFrom(account.getJid());
- packet.setAttribute("type","unavailable");
+ private static PresencePacket generateOfflinePresencePacket(Jid from, Jid to) {
+ return generatePresencePacket("unavailable", from, to);
+
+ }
+
+ public static PresencePacket generateOfflinePresencePacketTo(Account account, Jid to) {
+ return generateOfflinePresencePacket(account.getJid(), to);
+ }
+
+ public static PresencePacket generateOfflinePresencePacket(Account account) {
+ return generateOfflinePresencePacket(account.getJid(), null);
+ }
+
+ public static PresencePacket generateMucJoin(Account account, Jid joinJid, MucOptions mucOptions, long lastMessageTransmitted) {
+ PresencePacket packet = generatePresencePacket(null, account.getJid(), joinJid);
+ Element x = packet.addChild("x", "http://jabber.org/protocol/muc");
+ if (mucOptions.getPassword() != null) {
+ x.addChild("password").setContent(mucOptions.getPassword());
+ }
+
+ Element historyElement = x.addChild("history");
+ if (mucOptions.mamSupport()) {
+ // Use MAM instead of the limited muc history to get history
+ historyElement.setAttribute("maxchars", "0");
+ } else {
+ // Fallback to muc history
+ historyElement.setAttribute("since", PresenceGenerator.getTimestamp(lastMessageTransmitted));
+ }
+ String sig = account.getPgpSignature();
+ if (sig != null) {
+ packet.addChild("x", "jabber:x:signed").setContent(sig);
+ }
+
+ return packet;
+ }
+
+ public static PresencePacket generateMucRename(Account account, Jid joinJid) {
+ PresencePacket packet = generatePresencePacket(null, account.getJid(), joinJid);
+
+ String sig = account.getPgpSignature();
+ if (sig != null) {
+ packet.addChild("status").setContent("online");
+ packet.addChild("x", "jabber:x:signed").setContent(sig);
+ }
+
return packet;
}
}