aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/generator
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/eu/siacs/conversations/generator')
-rw-r--r--src/main/java/eu/siacs/conversations/generator/AbstractGenerator.java25
-rw-r--r--src/main/java/eu/siacs/conversations/generator/IqGenerator.java13
-rw-r--r--src/main/java/eu/siacs/conversations/generator/MessageGenerator.java36
3 files changed, 53 insertions, 21 deletions
diff --git a/src/main/java/eu/siacs/conversations/generator/AbstractGenerator.java b/src/main/java/eu/siacs/conversations/generator/AbstractGenerator.java
index 526e5b19..79626511 100644
--- a/src/main/java/eu/siacs/conversations/generator/AbstractGenerator.java
+++ b/src/main/java/eu/siacs/conversations/generator/AbstractGenerator.java
@@ -13,6 +13,7 @@ import java.util.Locale;
import java.util.TimeZone;
import eu.siacs.conversations.services.XmppConnectionService;
+import eu.siacs.conversations.utils.PhoneHelper;
public abstract class AbstractGenerator {
private final String[] FEATURES = {
@@ -25,15 +26,18 @@ public abstract class AbstractGenerator {
"http://jabber.org/protocol/caps",
"http://jabber.org/protocol/disco#info",
"urn:xmpp:avatar:metadata+notify",
- "urn:xmpp:ping"};
+ "urn:xmpp:ping",
+ "jabber:iq:version",
+ "http://jabber.org/protocol/chatstates"};
private final String[] MESSAGE_CONFIRMATION_FEATURES = {
"urn:xmpp:chat-markers:0",
"urn:xmpp:receipts"
};
- public final String IDENTITY_NAME = "Conversations 1.0";
+ private String mVersion = null;
+ public final String IDENTITY_NAME = "Conversations";
public final String IDENTITY_TYPE = "phone";
- private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
+ private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
protected XmppConnectionService mXmppConnectionService;
@@ -41,10 +45,21 @@ public abstract class AbstractGenerator {
this.mXmppConnectionService = service;
}
+ protected String getIdentityVersion() {
+ if (mVersion == null) {
+ this.mVersion = PhoneHelper.getVersionName(mXmppConnectionService);
+ }
+ return this.mVersion;
+ }
+
+ protected String getIdentityName() {
+ return IDENTITY_NAME + " " + getIdentityVersion();
+ }
+
public String getCapHash() {
StringBuilder s = new StringBuilder();
- s.append("client/" + IDENTITY_TYPE + "//" + IDENTITY_NAME + "<");
- MessageDigest md = null;
+ s.append("client/" + IDENTITY_TYPE + "//" + getIdentityName() + "<");
+ MessageDigest md;
try {
md = MessageDigest.getInstance("SHA-1");
} catch (NoSuchAlgorithmException e) {
diff --git a/src/main/java/eu/siacs/conversations/generator/IqGenerator.java b/src/main/java/eu/siacs/conversations/generator/IqGenerator.java
index 161e6f89..6bc629b5 100644
--- a/src/main/java/eu/siacs/conversations/generator/IqGenerator.java
+++ b/src/main/java/eu/siacs/conversations/generator/IqGenerator.java
@@ -8,6 +8,7 @@ import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.services.MessageArchiveService;
import eu.siacs.conversations.services.XmppConnectionService;
+import eu.siacs.conversations.utils.PhoneHelper;
import eu.siacs.conversations.utils.Xmlns;
import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.forms.Data;
@@ -30,14 +31,22 @@ public class IqGenerator extends AbstractGenerator {
query.setAttribute("node", request.query().getAttribute("node"));
final Element identity = query.addChild("identity");
identity.setAttribute("category", "client");
- identity.setAttribute("type", this.IDENTITY_TYPE);
- identity.setAttribute("name", IDENTITY_NAME);
+ identity.setAttribute("type", IDENTITY_TYPE);
+ identity.setAttribute("name", getIdentityName());
for (final String feature : getFeatures()) {
query.addChild("feature").setAttribute("var", feature);
}
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(IDENTITY_NAME);
+ query.addChild("version").setContent(getIdentityVersion());
+ 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",
diff --git a/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java b/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java
index 2ee636b5..8f6a90b9 100644
--- a/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java
+++ b/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java
@@ -12,6 +12,7 @@ import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.xml.Element;
+import eu.siacs.conversations.xmpp.chatstate.ChatState;
import eu.siacs.conversations.xmpp.jid.Jid;
import eu.siacs.conversations.xmpp.stanzas.MessagePacket;
@@ -34,6 +35,9 @@ public class MessageGenerator extends AbstractGenerator {
} else if (message.getType() == Message.TYPE_PRIVATE) {
packet.setTo(message.getCounterpart());
packet.setType(MessagePacket.TYPE_CHAT);
+ if (this.mXmppConnectionService.indicateReceived()) {
+ packet.addChild("request", "urn:xmpp:receipts");
+ }
} else {
packet.setTo(message.getCounterpart().toBareJid());
packet.setType(MessagePacket.TYPE_GROUPCHAT);
@@ -102,21 +106,12 @@ public class MessageGenerator extends AbstractGenerator {
return packet;
}
- public MessagePacket generateNotAcceptable(MessagePacket origin) {
- MessagePacket packet = generateError(origin);
- Element error = packet.addChild("error");
- error.setAttribute("type", "modify");
- error.setAttribute("code", "406");
- error.addChild("not-acceptable");
- return packet;
- }
-
- private MessagePacket generateError(MessagePacket origin) {
+ public MessagePacket generateChatState(Conversation conversation) {
+ final Account account = conversation.getAccount();
MessagePacket packet = new MessagePacket();
- packet.setId(origin.getId());
- packet.setTo(origin.getFrom());
- packet.setBody(origin.getBody());
- packet.setType(MessagePacket.TYPE_ERROR);
+ packet.setTo(conversation.getJid().toBareJid());
+ packet.setFrom(account.getJid());
+ packet.addChild(ChatState.toElement(conversation.getOutgoingChatState()));
return packet;
}
@@ -176,4 +171,17 @@ public class MessageGenerator extends AbstractGenerator {
received.setAttribute("id", originalMessage.getId());
return receivedPacket;
}
+
+ public MessagePacket generateOtrError(Jid to, String id) {
+ MessagePacket packet = new MessagePacket();
+ packet.setType(MessagePacket.TYPE_ERROR);
+ packet.setAttribute("id",id);
+ packet.setTo(to);
+ Element error = packet.addChild("error");
+ error.setAttribute("code","406");
+ error.setAttribute("type","modify");
+ error.addChild("not-acceptable","urn:ietf:params:xml:ns:xmpp-stanzas");
+ error.addChild("text").setContent("unreadable OTR message received");
+ return packet;
+ }
}