diff options
Diffstat (limited to 'src/eu/siacs/conversations/parser')
-rw-r--r-- | src/eu/siacs/conversations/parser/AbstractParser.java | 26 | ||||
-rw-r--r-- | src/eu/siacs/conversations/parser/MessageParser.java | 8 |
2 files changed, 27 insertions, 7 deletions
diff --git a/src/eu/siacs/conversations/parser/AbstractParser.java b/src/eu/siacs/conversations/parser/AbstractParser.java index 2bd839f1f..c06a5cbd9 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 a435d055d..e99892a0a 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) { |