aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorsteckbrief <steckbrief@chefmail.de>2017-08-06 14:28:00 +0200
committersteckbrief <steckbrief@chefmail.de>2017-08-06 14:28:00 +0200
commitbe1992ce897d3b0551e545646a3e0f45cc6dd8c2 (patch)
treec15c94ade61e5063095d8b429ae4acf85459493f /src
parentf8e083a32cb7232c9601f5011b14738d43bb3b06 (diff)
Implements XEP-0202 Entity Time, moves Software Version to xmpp package, moves namespace definitions for mam, carbons and avatar to xmpp package
Diffstat (limited to 'src')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/entities/MucOptions.java3
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/generator/AbstractGenerator.java8
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/generator/IqGenerator.java13
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/generator/MessageGenerator.java3
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/parser/IqParser.java12
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/parser/MessageParser.java50
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java5
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java10
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/xmpp/avatar/AvatarPacket.java8
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/xmpp/avatar/AvatarPacketGenerator.java16
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/xmpp/avatar/AvatarPacketParser.java4
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/xmpp/carbons/Carbons.java7
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/xmpp/chatstate/ChatState.java3
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/xmpp/iqversion/IqVersionPacket.java23
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/xmpp/iqversion/IqVersionPacketGenerator.java38
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/xmpp/mam/Mam.java7
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/xmpp/time/TimePacket.java35
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/xmpp/time/TimePacketGenerator.java38
18 files changed, 225 insertions, 58 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/entities/MucOptions.java b/src/main/java/de/thedevstack/conversationsplus/entities/MucOptions.java
index 32cdb1a9..abc45f0b 100644
--- a/src/main/java/de/thedevstack/conversationsplus/entities/MucOptions.java
+++ b/src/main/java/de/thedevstack/conversationsplus/entities/MucOptions.java
@@ -16,6 +16,7 @@ import de.thedevstack.conversationsplus.xmpp.forms.Field;
import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
import de.thedevstack.conversationsplus.dto.Avatar;
+import de.thedevstack.conversationsplus.xmpp.mam.Mam;
@SuppressLint("DefaultLocale")
public class MucOptions {
@@ -300,7 +301,7 @@ public class MucOptions {
public boolean mamSupport() {
// Update with "urn:xmpp:mam:1" once we support it
- return hasFeature("urn:xmpp:mam:0");
+ return hasFeature(Mam.NAMESPACE);
}
public boolean nonanonymous() {
diff --git a/src/main/java/de/thedevstack/conversationsplus/generator/AbstractGenerator.java b/src/main/java/de/thedevstack/conversationsplus/generator/AbstractGenerator.java
index abe137cf..7302b2df 100644
--- a/src/main/java/de/thedevstack/conversationsplus/generator/AbstractGenerator.java
+++ b/src/main/java/de/thedevstack/conversationsplus/generator/AbstractGenerator.java
@@ -13,6 +13,9 @@ import java.util.Locale;
import java.util.TimeZone;
import de.thedevstack.conversationsplus.ConversationsPlusApplication;
+import de.thedevstack.conversationsplus.xmpp.chatstate.ChatState;
+import de.thedevstack.conversationsplus.xmpp.iqversion.IqVersionPacket;
+import de.thedevstack.conversationsplus.xmpp.time.TimePacket;
import de.tzur.conversations.Settings;
import de.thedevstack.conversationsplus.crypto.axolotl.AxolotlService;
@@ -29,8 +32,9 @@ public abstract class AbstractGenerator {
"urn:xmpp:avatar:metadata+notify",
"http://jabber.org/protocol/nick+notify",
"urn:xmpp:ping",
- "jabber:iq:version",
- "http://jabber.org/protocol/chatstates",
+ TimePacket.NAMESPACE,
+ IqVersionPacket.NAMESPACE,
+ ChatState.NAMESPACE,
AxolotlService.PEP_DEVICE_LIST+"+notify"};
private static final String[] MESSAGE_CONFIRMATION_FEATURES = {
"urn:xmpp:chat-markers:0",
diff --git a/src/main/java/de/thedevstack/conversationsplus/generator/IqGenerator.java b/src/main/java/de/thedevstack/conversationsplus/generator/IqGenerator.java
index e3e13328..aa279e40 100644
--- a/src/main/java/de/thedevstack/conversationsplus/generator/IqGenerator.java
+++ b/src/main/java/de/thedevstack/conversationsplus/generator/IqGenerator.java
@@ -25,6 +25,7 @@ import de.thedevstack.conversationsplus.utils.Xmlns;
import de.thedevstack.conversationsplus.xml.Element;
import de.thedevstack.conversationsplus.xmpp.forms.Data;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
+import de.thedevstack.conversationsplus.xmpp.mam.Mam;
import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket;
public class IqGenerator extends AbstractGenerator {
@@ -46,14 +47,6 @@ public class IqGenerator extends AbstractGenerator {
return packet;
}
- public IqPacket versionResponse(final IqPacket request) {
- final IqPacket packet = request.generateResponse(IqPacket.TYPE.RESULT);
- Element query = packet.query("jabber:iq:version");
- query.addChild("name").setContent(ConversationsPlusApplication.getName());
- query.addChild("version").setContent(ConversationsPlusApplication.getVersion());
- return packet;
- }
-
protected IqPacket publish(final String node, final Element item) {
final IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
final Element pubsub = packet.addChild("pubsub",
@@ -155,10 +148,10 @@ public class IqGenerator extends AbstractGenerator {
public IqPacket queryMessageArchiveManagement(final MessageArchiveService.Query mam) {
final IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
- final Element query = packet.query("urn:xmpp:mam:0");
+ final Element query = packet.query(Mam.NAMESPACE);
query.setAttribute("queryid", mam.getQueryId());
final Data data = new Data();
- data.setFormType("urn:xmpp:mam:0");
+ data.setFormType(Mam.NAMESPACE);
if (mam.muc()) {
packet.setTo(mam.getWith());
} else if (mam.getWith()!=null) {
diff --git a/src/main/java/de/thedevstack/conversationsplus/generator/MessageGenerator.java b/src/main/java/de/thedevstack/conversationsplus/generator/MessageGenerator.java
index 678f2c75..e76d25f6 100644
--- a/src/main/java/de/thedevstack/conversationsplus/generator/MessageGenerator.java
+++ b/src/main/java/de/thedevstack/conversationsplus/generator/MessageGenerator.java
@@ -16,6 +16,7 @@ import de.thedevstack.conversationsplus.entities.Conversation;
import de.thedevstack.conversationsplus.entities.FileParams;
import de.thedevstack.conversationsplus.entities.Message;
import de.thedevstack.conversationsplus.xml.Element;
+import de.thedevstack.conversationsplus.xmpp.carbons.Carbons;
import de.thedevstack.conversationsplus.xmpp.chatstate.ChatState;
import de.thedevstack.conversationsplus.xmpp.httpuploadim.HttpUploadHint;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
@@ -81,7 +82,7 @@ public class MessageGenerator extends AbstractGenerator {
}
public static void addMessageHints(MessagePacket packet) {
- packet.addChild("private", "urn:xmpp:carbons:2");
+ packet.addChild("private", Carbons.NAMESPACE);
packet.addChild("no-copy", "urn:xmpp:hints");
packet.addChild("no-permanent-store", "urn:xmpp:hints");
packet.addChild("no-permanent-storage", "urn:xmpp:hints"); //do not copy this. this is wrong. it is *store*
diff --git a/src/main/java/de/thedevstack/conversationsplus/parser/IqParser.java b/src/main/java/de/thedevstack/conversationsplus/parser/IqParser.java
index 8af05df5..35b41d61 100644
--- a/src/main/java/de/thedevstack/conversationsplus/parser/IqParser.java
+++ b/src/main/java/de/thedevstack/conversationsplus/parser/IqParser.java
@@ -31,11 +31,16 @@ import de.thedevstack.conversationsplus.services.avatar.AvatarCache;
import de.thedevstack.conversationsplus.services.avatar.AvatarService;
import de.thedevstack.conversationsplus.services.XmppConnectionService;
import de.thedevstack.conversationsplus.utils.Xmlns;
+import de.thedevstack.conversationsplus.utils.XmppSendUtil;
import de.thedevstack.conversationsplus.xml.Element;
import de.thedevstack.conversationsplus.xmpp.OnIqPacketReceived;
import de.thedevstack.conversationsplus.xmpp.OnUpdateBlocklist;
+import de.thedevstack.conversationsplus.xmpp.iqversion.IqVersionPacket;
+import de.thedevstack.conversationsplus.xmpp.iqversion.IqVersionPacketGenerator;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket;
+import de.thedevstack.conversationsplus.xmpp.time.TimePacket;
+import de.thedevstack.conversationsplus.xmpp.time.TimePacketGenerator;
public class IqParser extends AbstractParser implements OnIqPacketReceived {
@@ -323,12 +328,13 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived {
} else if (packet.hasChild("query", "http://jabber.org/protocol/disco#info")) {
final IqPacket response = mXmppConnectionService.getIqGenerator().discoResponse(packet);
mXmppConnectionService.sendIqPacket(account, response, null);
- } else if (packet.hasChild("query","jabber:iq:version")) {
- final IqPacket response = mXmppConnectionService.getIqGenerator().versionResponse(packet);
- mXmppConnectionService.sendIqPacket(account,response,null);
+ } else if (packet.hasChild("query", IqVersionPacket.NAMESPACE)) {
+ XmppSendUtil.sendIqPacket(account, IqVersionPacketGenerator.generateResponse(packet), null);
} else if (packet.hasChild("ping", "urn:xmpp:ping")) {
final IqPacket response = packet.generateResponse(IqPacket.TYPE.RESULT);
mXmppConnectionService.sendIqPacket(account, response, null);
+ } else if (packet.hasChild("time", TimePacket.NAMESPACE)) {
+ XmppSendUtil.sendIqPacket(account, TimePacketGenerator.generateResponse(packet), null);
} else {
if (packet.getType() == IqPacket.TYPE.GET || packet.getType() == IqPacket.TYPE.SET) {
final IqPacket response = packet.generateResponse(IqPacket.TYPE.ERROR);
diff --git a/src/main/java/de/thedevstack/conversationsplus/parser/MessageParser.java b/src/main/java/de/thedevstack/conversationsplus/parser/MessageParser.java
index f282ae01..52d35f58 100644
--- a/src/main/java/de/thedevstack/conversationsplus/parser/MessageParser.java
+++ b/src/main/java/de/thedevstack/conversationsplus/parser/MessageParser.java
@@ -5,12 +5,18 @@ import android.util.Pair;
import de.thedevstack.conversationsplus.entities.FileParams;
import de.thedevstack.conversationsplus.enums.FileStatus;
+import de.thedevstack.conversationsplus.persistance.DatabaseBackend;
import de.thedevstack.conversationsplus.services.avatar.AvatarCache;
import de.thedevstack.conversationsplus.services.filetransfer.http.download.AutomaticFileDownload;
import de.thedevstack.conversationsplus.services.filetransfer.http.download.HttpRetrieveHead;
import de.thedevstack.conversationsplus.utils.MessageUtil;
+import de.thedevstack.conversationsplus.utils.UiUpdateHelper;
+import de.thedevstack.conversationsplus.utils.XmppSendUtil;
+import de.thedevstack.conversationsplus.xmpp.avatar.AvatarPacket;
import de.thedevstack.conversationsplus.xmpp.avatar.AvatarPacketParser;
+import de.thedevstack.conversationsplus.xmpp.carbons.Carbons;
import de.thedevstack.conversationsplus.xmpp.httpuploadim.HttpUploadHint;
+import de.thedevstack.conversationsplus.xmpp.mam.Mam;
import de.tzur.conversations.Settings;
import net.java.otr4j.session.Session;
@@ -99,7 +105,7 @@ public class MessageParser extends AbstractParser implements
return null;
} else if (body == null && status == SessionStatus.FINISHED) {
conversation.resetOtrSession();
- mXmppConnectionService.updateConversationUi();
+ UiUpdateHelper.updateConversationUi();
return null;
} else if (body == null || (body.isEmpty())) {
return null;
@@ -148,9 +154,9 @@ public class MessageParser extends AbstractParser implements
Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, jid, true);
if (!conversation.getMucOptions().online()) {
conversation.getMucOptions().setPassword(password);
- mXmppConnectionService.databaseBackend.updateConversation(conversation);
+ DatabaseBackend.getInstance().updateConversation(conversation);
mXmppConnectionService.joinMuc(conversation);
- mXmppConnectionService.updateConversationUi();
+ UiUpdateHelper.updateConversationUi();
}
return true;
}
@@ -189,24 +195,24 @@ public class MessageParser extends AbstractParser implements
private void parseEvent(final Element event, final Jid from, final Account account) {
Element items = event.findChild("items");
String node = items == null ? null : items.getAttribute("node");
- if ("urn:xmpp:avatar:metadata".equals(node)) {
+ if (AvatarPacket.NAMESPACE_AVATAR_METADATA.equals(node)) {
Avatar avatar = AvatarPacketParser.parseMetadata(items);
if (avatar != null) {
avatar.owner = from.toBareJid();
if (AvatarUtil.isAvatarCached(avatar)) {
if (account.getJid().toBareJid().equals(from)) {
if (account.setAvatar(avatar.getFilename())) {
- mXmppConnectionService.databaseBackend.updateAccount(account);
+ DatabaseBackend.getInstance().updateAccount(account);
}
AvatarCache.clear(account);
- mXmppConnectionService.updateConversationUi();
- mXmppConnectionService.updateAccountUi();
+ UiUpdateHelper.updateConversationUi();
+ UiUpdateHelper.updateAccountUi();
} else {
Contact contact = account.getRoster().getContact(from);
contact.setAvatar(avatar);
AvatarCache.clear(contact);
- mXmppConnectionService.updateConversationUi();
- mXmppConnectionService.updateRosterUi();
+ UiUpdateHelper.updateConversationUi();
+ UiUpdateHelper.updateRosterUi();
}
} else {
AvatarService.getInstance().fetchAvatar(account, avatar);
@@ -219,8 +225,8 @@ public class MessageParser extends AbstractParser implements
Contact contact = account.getRoster().getContact(from);
contact.setPresenceName(nick.getContent());
AvatarCache.clear(account);
- mXmppConnectionService.updateConversationUi();
- mXmppConnectionService.updateAccountUi();
+ UiUpdateHelper.updateConversationUi();
+ UiUpdateHelper.updateAccountUi();
}
} else if (ConversationsPlusPreferences.omemoEnabled() && AxolotlService.PEP_DEVICE_LIST.equals(node)) {
Log.d(Config.LOGTAG, AxolotlServiceImpl.getLogprefix(account)+"Received PEP device list update from "+ from + ", processing...");
@@ -228,7 +234,7 @@ public class MessageParser extends AbstractParser implements
Set<Integer> deviceIds = mXmppConnectionService.getIqParser().deviceIds(item);
AxolotlService axolotlService = account.getAxolotlService();
axolotlService.registerDevices(from, deviceIds);
- mXmppConnectionService.updateAccountUi();
+ UiUpdateHelper.updateAccountUi();
}
}
@@ -266,15 +272,15 @@ public class MessageParser extends AbstractParser implements
final boolean isForwarded;
boolean isCarbon = false;
String serverMsgId = null;
- final Element fin = original.findChild("fin", "urn:xmpp:mam:0");
+ final Element fin = original.findChild("fin", Mam.NAMESPACE);
if (fin != null) {
mXmppConnectionService.getMessageArchiveService().processFin(fin,original.getFrom());
return;
}
- final Element result = original.findChild("result","urn:xmpp:mam:0");
+ final Element result = original.findChild("result", Mam.NAMESPACE);
final MessageArchiveService.Query query = result == null ? null : mXmppConnectionService.getMessageArchiveService().findQuery(result.getAttribute("queryid"));
if (query != null && query.validFrom(original.getFrom())) {
- Pair<MessagePacket, Long> f = original.getForwardedMessagePacket("result", "urn:xmpp:mam:0");
+ Pair<MessagePacket, Long> f = original.getForwardedMessagePacket("result", Mam.NAMESPACE);
if (f == null) {
return;
}
@@ -288,8 +294,8 @@ public class MessageParser extends AbstractParser implements
return;
} else if (original.fromServer(account)) {
Pair<MessagePacket, Long> f;
- f = original.getForwardedMessagePacket("received", "urn:xmpp:carbons:2");
- f = f == null ? original.getForwardedMessagePacket("sent", "urn:xmpp:carbons:2") : f;
+ f = original.getForwardedMessagePacket("received", Carbons.NAMESPACE);
+ f = f == null ? original.getForwardedMessagePacket("sent", Carbons.NAMESPACE) : f;
packet = f != null ? f.first : original;
if (handleErrorMessage(account, packet)) {
return;
@@ -339,7 +345,7 @@ public class MessageParser extends AbstractParser implements
}
if (extractChatState(mXmppConnectionService.find(account, counterpart.toBareJid()), packet)) {
- mXmppConnectionService.updateConversationUi();
+ UiUpdateHelper.updateConversationUi();
}
if ((body != null || pgpEncrypted != null || axolotlEncrypted != null) && !isMucStatusMessage) {
@@ -455,7 +461,7 @@ public class MessageParser extends AbstractParser implements
}
if (query == null) {
- mXmppConnectionService.updateConversationUi();
+ UiUpdateHelper.updateConversationUi();
}
if (Settings.CONFIRM_MESSAGE_READ && remoteMsgId != null && !isForwarded && !isTypeGroupChat) {
@@ -477,7 +483,7 @@ public class MessageParser extends AbstractParser implements
}
}
if (message.getEncryption() == Message.ENCRYPTION_NONE || !ConversationsPlusPreferences.dontSaveEncrypted()) {
- mXmppConnectionService.databaseBackend.createMessage(message);
+ DatabaseBackend.getInstance().createMessage(message);
}
if (message.trusted()
&& message.treatAsDownloadable() != Message.Decision.NEVER
@@ -511,7 +517,7 @@ public class MessageParser extends AbstractParser implements
mXmppConnectionService.pushBookmarks(account);
}
}
- mXmppConnectionService.updateConversationUi();
+ UiUpdateHelper.updateConversationUi();
return;
}
}
@@ -580,7 +586,7 @@ public class MessageParser extends AbstractParser implements
packet,
receiptsNamespaces,
packet.getType());
- mXmppConnectionService.sendMessagePacket(account, receipt);
+ XmppSendUtil.sendMessagePacket(account, receipt);
}
}
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java b/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java
index 51aee921..ac6ef464 100644
--- a/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java
+++ b/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java
@@ -64,6 +64,7 @@ import de.thedevstack.conversationsplus.utils.MessageUtil;
import de.thedevstack.conversationsplus.utils.UiUpdateHelper;
import de.thedevstack.conversationsplus.utils.XmppConnectionServiceAccessor;
import de.thedevstack.conversationsplus.utils.XmppSendUtil;
+import de.thedevstack.conversationsplus.xmpp.mam.Mam;
import de.tzur.conversations.Settings;
import de.thedevstack.conversationsplus.Config;
import de.thedevstack.conversationsplus.R;
@@ -2621,11 +2622,11 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
public void fetchMamPreferences(Account account, final OnMamPreferencesFetched callback) {
IqPacket request = new IqPacket(IqPacket.TYPE.GET);
- request.addChild("prefs","urn:xmpp:mam:0");
+ request.addChild("prefs", Mam.NAMESPACE);
sendIqPacket(account, request, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
- Element prefs = packet.findChild("prefs","urn:xmpp:mam:0");
+ Element prefs = packet.findChild("prefs", Mam.NAMESPACE);
if (packet.getType() == IqPacket.TYPE.RESULT && prefs != null) {
callback.onPreferencesFetched(prefs);
} else {
diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java
index dfea06c8..54db5346 100644
--- a/src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java
+++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java
@@ -71,6 +71,7 @@ import de.thedevstack.conversationsplus.xml.Element;
import de.thedevstack.conversationsplus.xml.Tag;
import de.thedevstack.conversationsplus.xml.TagWriter;
import de.thedevstack.conversationsplus.xml.XmlReader;
+import de.thedevstack.conversationsplus.xmpp.carbons.Carbons;
import de.thedevstack.conversationsplus.xmpp.filetransfer.http.FileTransferHttp;
import de.thedevstack.conversationsplus.xmpp.filetransfer.http.upload.HttpUpload;
import de.thedevstack.conversationsplus.xmpp.forms.Data;
@@ -79,6 +80,7 @@ import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
import de.thedevstack.conversationsplus.xmpp.jingle.OnJinglePacketReceived;
import de.thedevstack.conversationsplus.xmpp.jingle.stanzas.JinglePacket;
+import de.thedevstack.conversationsplus.xmpp.mam.Mam;
import de.thedevstack.conversationsplus.xmpp.stanzas.AbstractAcknowledgeableStanza;
import de.thedevstack.conversationsplus.xmpp.stanzas.AbstractStanza;
import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket;
@@ -1133,7 +1135,7 @@ public class XmppConnection implements Runnable {
private void sendEnableCarbons() {
final IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
- iq.addChild("enable", "urn:xmpp:carbons:2");
+ iq.addChild("enable", Carbons.NAMESPACE);
this.sendIqPacket(iq, new OnIqPacketReceived() {
@Override
@@ -1490,7 +1492,7 @@ public class XmppConnection implements Runnable {
}
public boolean carbons() {
- return hasDiscoFeature(account.getServer(), "urn:xmpp:carbons:2");
+ return hasDiscoFeature(account.getServer(), Carbons.NAMESPACE);
}
public boolean blocking() {
@@ -1525,8 +1527,8 @@ public class XmppConnection implements Runnable {
}
public boolean mam() {
- return hasDiscoFeature(account.getJid().toBareJid(), "urn:xmpp:mam:0")
- || hasDiscoFeature(account.getServer(), "urn:xmpp:mam:0");
+ return hasDiscoFeature(account.getJid().toBareJid(), Mam.NAMESPACE)
+ || hasDiscoFeature(account.getServer(), Mam.NAMESPACE);
}
public boolean push() {
diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/avatar/AvatarPacket.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/avatar/AvatarPacket.java
new file mode 100644
index 00000000..86cb2274
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/avatar/AvatarPacket.java
@@ -0,0 +1,8 @@
+package de.thedevstack.conversationsplus.xmpp.avatar;
+
+/**
+ */
+public class AvatarPacket {
+ public static final String NAMESPACE_AVATAR_DATA = "urn:xmpp:avatar:data";
+ public static final String NAMESPACE_AVATAR_METADATA = "urn:xmpp:avatar:metadata";
+}
diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/avatar/AvatarPacketGenerator.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/avatar/AvatarPacketGenerator.java
index 4534e870..f9e04122 100644
--- a/src/main/java/de/thedevstack/conversationsplus/xmpp/avatar/AvatarPacketGenerator.java
+++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/avatar/AvatarPacketGenerator.java
@@ -9,11 +9,9 @@ import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket;
/**
* Generates the IQ Packets for handling Avatars
* as defined in XEP-0084.
- * @see {@link http://xmpp.org/extensions/xep-0084.html}
+ * @see http://xmpp.org/extensions/xep-0084.html
*/
public final class AvatarPacketGenerator {
- public static final String NAMESPACE_AVATAR_DATA = "urn:xmpp:avatar:data";
- public static final String NAMESPACE_AVATAR_METADATA = "urn:xmpp:avatar:metadata";
/**
* Generates an IqPacket for publishing avatar data.
@@ -37,9 +35,9 @@ public final class AvatarPacketGenerator {
public static IqPacket generatePublishAvatarPacket(Avatar avatar) {
final Element item = new Element("item");
item.setAttribute("id", avatar.sha1sum);
- final Element data = item.addChild("data", NAMESPACE_AVATAR_DATA);
+ final Element data = item.addChild("data", AvatarPacket.NAMESPACE_AVATAR_DATA);
data.setContent(avatar.image);
- return PubSubPacketGenerator.generatePubSubPublishPacket(NAMESPACE_AVATAR_DATA, item);
+ return PubSubPacketGenerator.generatePubSubPublishPacket(AvatarPacket.NAMESPACE_AVATAR_DATA, item);
}
/**
@@ -60,7 +58,7 @@ public final class AvatarPacketGenerator {
public static IqPacket generateRetrieveAvatarPacket(Avatar avatar) {
final Element item = new Element("item");
item.setAttribute("id", avatar.sha1sum);
- final IqPacket packet = PubSubPacketGenerator.generatePubSubRetrievePacket(NAMESPACE_AVATAR_DATA, item);
+ final IqPacket packet = PubSubPacketGenerator.generatePubSubRetrievePacket(AvatarPacket.NAMESPACE_AVATAR_DATA, item);
packet.setTo(avatar.owner);
return packet;
}
@@ -91,14 +89,14 @@ public final class AvatarPacketGenerator {
public static IqPacket generatePublishAvatarMetadataPacket(Avatar avatar) {
final Element item = new Element("item");
item.setAttribute("id", avatar.sha1sum);
- final Element metadata = item.addChild("metadata", NAMESPACE_AVATAR_METADATA);
+ final Element metadata = item.addChild("metadata", AvatarPacket.NAMESPACE_AVATAR_METADATA);
final Element info = metadata.addChild("info");
info.setAttribute("bytes", avatar.size);
info.setAttribute("id", avatar.sha1sum);
info.setAttribute("height", avatar.height);
info.setAttribute("width", avatar.height);
info.setAttribute("type", avatar.type);
- return PubSubPacketGenerator.generatePubSubPublishPacket(NAMESPACE_AVATAR_METADATA, item);
+ return PubSubPacketGenerator.generatePubSubPublishPacket(AvatarPacket.NAMESPACE_AVATAR_METADATA, item);
}
/**
@@ -108,7 +106,7 @@ public final class AvatarPacketGenerator {
* @return the IqPacket
*/
public static IqPacket generateRetrieveAvatarMetadataPacket(Jid to) {
- final IqPacket packet = PubSubPacketGenerator.generatePubSubRetrievePacket(NAMESPACE_AVATAR_METADATA, null);
+ final IqPacket packet = PubSubPacketGenerator.generatePubSubRetrievePacket(AvatarPacket.NAMESPACE_AVATAR_METADATA, null);
if (to != null) {
packet.setTo(to);
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/avatar/AvatarPacketParser.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/avatar/AvatarPacketParser.java
index 175f54bd..e9f90898 100644
--- a/src/main/java/de/thedevstack/conversationsplus/xmpp/avatar/AvatarPacketParser.java
+++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/avatar/AvatarPacketParser.java
@@ -8,7 +8,7 @@ import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket;
/**
* Parses the IQ Packets for handling Avatars
* as defined in XEP-0084.
- * @see {@link http://xmpp.org/extensions/xep-0084.html}
+ * @see <a href="http://xmpp.org/extensions/xep-0084.html">http://xmpp.org/extensions/xep-0084.html</a>
*/
public class AvatarPacketParser {
/**
@@ -22,7 +22,7 @@ public class AvatarPacketParser {
if (null != items) {
Element item = items.findChild("item");
if (null != item) {
- base64Avatar = item.findChildContent("data", AvatarPacketGenerator.NAMESPACE_AVATAR_DATA);
+ base64Avatar = item.findChildContent("data", AvatarPacket.NAMESPACE_AVATAR_DATA);
}
}
return base64Avatar;
diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/carbons/Carbons.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/carbons/Carbons.java
new file mode 100644
index 00000000..89b9317b
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/carbons/Carbons.java
@@ -0,0 +1,7 @@
+package de.thedevstack.conversationsplus.xmpp.carbons;
+
+/**
+ */
+public interface Carbons {
+ String NAMESPACE = "urn:xmpp:carbons:2";
+}
diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/chatstate/ChatState.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/chatstate/ChatState.java
index 323d99c2..805e1f33 100644
--- a/src/main/java/de/thedevstack/conversationsplus/xmpp/chatstate/ChatState.java
+++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/chatstate/ChatState.java
@@ -5,9 +5,9 @@ import de.thedevstack.conversationsplus.xml.Element;
public enum ChatState {
ACTIVE, INACTIVE, GONE, COMPOSING, PAUSED;
+ public static final String NAMESPACE = "http://jabber.org/protocol/chatstates";
public static ChatState parse(Element element) {
- final String NAMESPACE = "http://jabber.org/protocol/chatstates";
if (element.hasChild("active",NAMESPACE)) {
return ACTIVE;
} else if (element.hasChild("inactive",NAMESPACE)) {
@@ -24,7 +24,6 @@ public enum ChatState {
}
public static Element toElement(ChatState state) {
- final String NAMESPACE = "http://jabber.org/protocol/chatstates";
final Element element = new Element(state.toString().toLowerCase());
element.setAttribute("xmlns",NAMESPACE);
return element;
diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/iqversion/IqVersionPacket.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/iqversion/IqVersionPacket.java
new file mode 100644
index 00000000..a3cecdac
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/iqversion/IqVersionPacket.java
@@ -0,0 +1,23 @@
+package de.thedevstack.conversationsplus.xmpp.iqversion;
+
+import android.os.Build;
+
+import de.thedevstack.conversationsplus.ConversationsPlusApplication;
+import de.thedevstack.conversationsplus.xml.Element;
+import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket;
+
+/**
+ * Representation of an software version packet as defined in XEP-0092.
+ * @see <a href="http://xmpp.org/extensions/xep-0092.html">http://xmpp.org/extensions/xep-0092.html</a>
+ */
+public class IqVersionPacket extends IqPacket {
+ public static final String NAMESPACE = "jabber:iq:version";
+
+ IqVersionPacket() {
+ super(IqPacket.TYPE.RESULT);
+ Element query = this.addChild("query", NAMESPACE);
+ query.addChild("name").setContent(ConversationsPlusApplication.getName());
+ query.addChild("version").setContent(ConversationsPlusApplication.getVersion());
+ query.addChild("os").setContent("Android " + Build.VERSION.RELEASE);
+ }
+}
diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/iqversion/IqVersionPacketGenerator.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/iqversion/IqVersionPacketGenerator.java
new file mode 100644
index 00000000..97a7e90d
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/iqversion/IqVersionPacketGenerator.java
@@ -0,0 +1,38 @@
+package de.thedevstack.conversationsplus.xmpp.iqversion;
+
+import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket;
+
+/**
+ * Generates the IQ Packets for Software Version
+ * as defined in XEP-0092.
+ * @see <a href="http://xmpp.org/extensions/xep-0092.html">http://xmpp.org/extensions/xep-0092.html</a>
+ */
+public final class IqVersionPacketGenerator {
+
+ /**
+ * Generates the IqPacket to reply the software version.
+ * <pre>
+ * <iq from='juliet@capulet.com/balcony'
+ * type='result'
+ * to='romeo@montague.net/orchard'
+ * id='version_1'>
+ * <query xmlns='jabber:iq:version'>
+ * <name>Exodus</name>
+ * <version>0.7.0.4</version>
+ * <os>Windows-XP 5.01.2600</os>
+ * </query>
+ * </iq>
+ * </pre>
+ * @param packet the packet to respond to
+ * @return
+ */
+ public static IqVersionPacket generateResponse(IqPacket packet) {
+ IqVersionPacket iqVersionPacket = new IqVersionPacket();
+ iqVersionPacket.setTo(packet.getFrom());
+ iqVersionPacket.setId(packet.getId());
+
+ return iqVersionPacket;
+ }
+
+ private IqVersionPacketGenerator() {}
+}
diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/mam/Mam.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/mam/Mam.java
new file mode 100644
index 00000000..e2228b32
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/mam/Mam.java
@@ -0,0 +1,7 @@
+package de.thedevstack.conversationsplus.xmpp.mam;
+
+/**
+ */
+public interface Mam {
+ String NAMESPACE = "urn:xmpp:mam:0";
+}
diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/time/TimePacket.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/time/TimePacket.java
new file mode 100644
index 00000000..d8756d41
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/time/TimePacket.java
@@ -0,0 +1,35 @@
+package de.thedevstack.conversationsplus.xmpp.time;
+
+import java.util.Locale;
+import java.util.TimeZone;
+
+import de.thedevstack.conversationsplus.generator.AbstractGenerator;
+import de.thedevstack.conversationsplus.xml.Element;
+import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket;
+
+/**
+ * Representation of an software version packet as defined in XEP-0202.
+ * @see <a href="http://xmpp.org/extensions/xep-0202.html">http://xmpp.org/extensions/xep-0202.html</a>
+ */
+public class TimePacket extends IqPacket {
+ public static final String NAMESPACE = "urn:xmpp:time";
+
+ TimePacket() {
+ super(IqPacket.TYPE.RESULT);
+ Element time = this.addChild("time", NAMESPACE);
+ final long now = System.currentTimeMillis();
+ time.addChild("utc").setContent(AbstractGenerator.getTimestamp(now));
+ TimeZone ourTimezone = TimeZone.getDefault();
+ long offsetSeconds = ourTimezone.getOffset(now) / 1000;
+ long offsetMinutes = Math.abs((offsetSeconds % 3600) / 60);
+ long offsetHours = offsetSeconds / 3600;
+ String hours;
+ if (offsetHours < 0) {
+ hours = String.format(Locale.US, "%03d", offsetHours);
+ } else {
+ hours = String.format(Locale.US, "%02d", offsetHours);
+ }
+ String minutes = String.format(Locale.US, "%02d", offsetMinutes);
+ time.addChild("tzo").setContent(hours + ":" + minutes);
+ }
+}
diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/time/TimePacketGenerator.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/time/TimePacketGenerator.java
new file mode 100644
index 00000000..344beb9e
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/time/TimePacketGenerator.java
@@ -0,0 +1,38 @@
+package de.thedevstack.conversationsplus.xmpp.time;
+
+import de.thedevstack.conversationsplus.xmpp.iqversion.IqVersionPacket;
+import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket;
+
+/**
+ * Generates the IQ Packets for Entity Time
+ * as defined in XEP-0202.
+ * @see <a href="http://xmpp.org/extensions/xep-0202.html">http://xmpp.org/extensions/xep-0202.html</a>
+ */
+public final class TimePacketGenerator {
+
+ /**
+ * Generates the IqPacket to reply the entity time.
+ * <pre>
+ * <iq type='result'
+ * from='juliet@capulet.com/balcony'
+ * to='romeo@montague.net/orchard'
+ * id='time_1'>
+ * <time xmlns='urn:xmpp:time'>
+ * <tzo>-06:00</tzo>
+ * <utc>2006-12-19T17:58:35Z</utc>
+ * </time>
+ * </iq>
+ * </pre>
+ * @param packet
+ * @return
+ */
+ public static TimePacket generateResponse(IqPacket packet) {
+ TimePacket timePacket = new TimePacket();
+ timePacket.setTo(packet.getFrom());
+ timePacket.setId(packet.getId());
+
+ return timePacket;
+ }
+
+ private TimePacketGenerator() {}
+}