aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/eu/siacs/conversations/generator/MessageGenerator.java36
-rw-r--r--src/eu/siacs/conversations/parser/AbstractParser.java26
-rw-r--r--src/eu/siacs/conversations/parser/MessageParser.java8
-rw-r--r--src/eu/siacs/conversations/services/XmppConnectionService.java6
-rw-r--r--src/eu/siacs/conversations/xmpp/XmppConnection.java1
5 files changed, 63 insertions, 14 deletions
diff --git a/src/eu/siacs/conversations/generator/MessageGenerator.java b/src/eu/siacs/conversations/generator/MessageGenerator.java
index 57b21fcf..a0bb7fb8 100644
--- a/src/eu/siacs/conversations/generator/MessageGenerator.java
+++ b/src/eu/siacs/conversations/generator/MessageGenerator.java
@@ -1,14 +1,19 @@
package eu.siacs.conversations.generator;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.TimeZone;
+
import net.java.otr4j.OtrException;
import net.java.otr4j.session.Session;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
+import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.stanzas.MessagePacket;
public class MessageGenerator {
- private MessagePacket preparePacket(Message message) {
+ private MessagePacket preparePacket(Message message, boolean addDelay) {
Conversation conversation = message.getConversation();
Account account = conversation.getAccount();
MessagePacket packet = new MessagePacket();
@@ -21,15 +26,30 @@ public class MessageGenerator {
}
packet.setFrom(account.getFullJid());
packet.setId(message.getUuid());
+ if (addDelay) {
+ addDelay(packet,message.getTimeSent());
+ }
return packet;
}
+ private void addDelay(MessagePacket packet, long timestamp) {
+ final SimpleDateFormat mDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
+ mDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
+ Element delay = packet.addChild("delay", "urn:xmpp:delay");
+ Date date = new Date(timestamp);
+ delay.setAttribute("stamp", mDateFormat.format(date));
+ }
+
public MessagePacket generateOtrChat(Message message) throws OtrException {
+ return generateOtrChat(message, false);
+ }
+
+ public MessagePacket generateOtrChat(Message message, boolean addDelay) throws OtrException {
Session otrSession = message.getConversation().getOtrSession();
if (otrSession==null) {
throw new OtrException(null);
}
- MessagePacket packet = preparePacket(message);
+ MessagePacket packet = preparePacket(message,addDelay);
packet.addChild("private", "urn:xmpp:carbons:2");
packet.addChild("no-copy", "urn:xmpp:hints");
packet.setBody(otrSession.transformSending(message
@@ -38,13 +58,21 @@ public class MessageGenerator {
}
public MessagePacket generateChat(Message message) {
- MessagePacket packet = preparePacket(message);
+ return generateChat(message, false);
+ }
+
+ public MessagePacket generateChat(Message message, boolean addDelay) {
+ MessagePacket packet = preparePacket(message,addDelay);
packet.setBody(message.getBody());
return packet;
}
public MessagePacket generatePgpChat(Message message) {
- MessagePacket packet = preparePacket(message);
+ return generatePgpChat(message, false);
+ }
+
+ public MessagePacket generatePgpChat(Message message, boolean addDelay) {
+ MessagePacket packet = preparePacket(message,addDelay);
packet.setBody("This is an XEP-0027 encryted message");
if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
packet.addChild("x", "jabber:x:encrypted").setContent(
diff --git a/src/eu/siacs/conversations/parser/AbstractParser.java b/src/eu/siacs/conversations/parser/AbstractParser.java
index 2bd839f1..c06a5cbd 100644
--- a/src/eu/siacs/conversations/parser/AbstractParser.java
+++ b/src/eu/siacs/conversations/parser/AbstractParser.java
@@ -4,6 +4,7 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
+import android.util.Log;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.services.XmppConnectionService;
@@ -18,19 +19,34 @@ public abstract class AbstractParser {
}
protected long getTimestamp(Element packet) {
+ long now = System.currentTimeMillis();
if (packet.hasChild("delay")) {
try {
String stamp = packet.findChild("delay").getAttribute(
"stamp");
stamp = stamp.replace("Z", "+0000");
- Date date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
- .parse(stamp);
- return date.getTime();
+ if (stamp.contains(".")) {
+ Date date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
+ .parse(stamp);
+ if (now<date.getTime()) {
+ return now;
+ } else {
+ return date.getTime();
+ }
+ } else {
+ Date date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
+ .parse(stamp);
+ if (now<date.getTime()) {
+ return now;
+ } else {
+ return date.getTime();
+ }
+ }
} catch (ParseException e) {
- return System.currentTimeMillis();
+ return now;
}
} else {
- return System.currentTimeMillis();
+ return now;
}
}
diff --git a/src/eu/siacs/conversations/parser/MessageParser.java b/src/eu/siacs/conversations/parser/MessageParser.java
index a435d055..e99892a0 100644
--- a/src/eu/siacs/conversations/parser/MessageParser.java
+++ b/src/eu/siacs/conversations/parser/MessageParser.java
@@ -18,20 +18,24 @@ public class MessageParser extends AbstractParser {
}
public Message parseChat(MessagePacket packet, Account account) {
+ Log.d("xmppService","received message: "+packet.toString());
String[] fromParts = packet.getFrom().split("/");
Conversation conversation = mXmppConnectionService
.findOrCreateConversation(account, fromParts[0], false);
conversation.setLatestMarkableMessageId(getMarkableMessageId(packet));
updateLastseen(packet, account,true);
String pgpBody = getPgpBody(packet);
+ Message finishedMessage;
if (pgpBody != null) {
- return new Message(conversation, packet.getFrom(), pgpBody,
+ finishedMessage = new Message(conversation, packet.getFrom(), pgpBody,
Message.ENCRYPTION_PGP, Message.STATUS_RECIEVED);
} else {
- return new Message(conversation, packet.getFrom(),
+ finishedMessage = new Message(conversation, packet.getFrom(),
packet.getBody(), Message.ENCRYPTION_NONE,
Message.STATUS_RECIEVED);
}
+ finishedMessage.setTime(getTimestamp(packet));
+ return finishedMessage;
}
public Message parseOtrChat(MessagePacket packet, Account account) {
diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java
index b3cb8430..356342b4 100644
--- a/src/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/eu/siacs/conversations/services/XmppConnectionService.java
@@ -763,9 +763,9 @@ public class XmppConnectionService extends Service {
if (message.getType() == Message.TYPE_TEXT) {
MessagePacket packet = null;
if (message.getEncryption() == Message.ENCRYPTION_NONE) {
- packet = mMessageGenerator.generateChat(message);
+ packet = mMessageGenerator.generateChat(message,true);
} else if ((message.getEncryption() == Message.ENCRYPTION_DECRYPTED)||(message.getEncryption() == Message.ENCRYPTION_PGP)) {
- packet = mMessageGenerator.generatePgpChat(message);
+ packet = mMessageGenerator.generatePgpChat(message,true);
} else if (message.getEncryption() == Message.ENCRYPTION_OTR) {
Presences presences = message.getConversation().getContact()
.getPresences();
@@ -1207,7 +1207,7 @@ public class XmppConnectionService extends Service {
msg.setPresence(otrSession.getSessionID().getUserID());
if (msg.getType() == Message.TYPE_TEXT) {
try {
- MessagePacket outPacket = mMessageGenerator.generateOtrChat(msg);
+ MessagePacket outPacket = mMessageGenerator.generateOtrChat(msg,true);
msg.setStatus(Message.STATUS_SEND);
databaseBackend.updateMessage(msg);
account.getXmppConnection().sendMessagePacket(outPacket);
diff --git a/src/eu/siacs/conversations/xmpp/XmppConnection.java b/src/eu/siacs/conversations/xmpp/XmppConnection.java
index 2447b49b..b62a6d29 100644
--- a/src/eu/siacs/conversations/xmpp/XmppConnection.java
+++ b/src/eu/siacs/conversations/xmpp/XmppConnection.java
@@ -795,6 +795,7 @@ public class XmppConnection implements Runnable {
}
public void sendMessagePacket(MessagePacket packet) {
+ Log.d("xmppService",packet.toString());
this.sendPacket(packet, null);
}