aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/parser
diff options
context:
space:
mode:
Diffstat (limited to 'src/eu/siacs/conversations/parser')
-rw-r--r--src/eu/siacs/conversations/parser/MessageParser.java23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/eu/siacs/conversations/parser/MessageParser.java b/src/eu/siacs/conversations/parser/MessageParser.java
index 8e0997289..ab75d6767 100644
--- a/src/eu/siacs/conversations/parser/MessageParser.java
+++ b/src/eu/siacs/conversations/parser/MessageParser.java
@@ -6,6 +6,7 @@ import net.java.otr4j.session.Session;
import net.java.otr4j.session.SessionStatus;
import android.util.Log;
import eu.siacs.conversations.entities.Account;
+import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.services.XmppConnectionService;
@@ -26,6 +27,7 @@ public class MessageParser {
Conversation conversation = mXmppConnectionService
.findOrCreateConversation(account, fromParts[0], false);
conversation.setLatestMarkableMessageId(getMarkableMessageId(packet));
+ updateLastseen(packet, account);
String pgpBody = getPgpBody(packet);
if (pgpBody != null) {
return new Message(conversation, packet.getFrom(), pgpBody,
@@ -43,6 +45,7 @@ public class MessageParser {
String[] fromParts = packet.getFrom().split("/");
Conversation conversation = mXmppConnectionService
.findOrCreateConversation(account, fromParts[0], false);
+ updateLastseen(packet, account);
String body = packet.getBody();
if (!conversation.hasValidOtrSession()) {
if (properlyAddressed) {
@@ -171,6 +174,7 @@ public class MessageParser {
return null; // either malformed or boring
if (status == Message.STATUS_RECIEVED) {
fullJid = message.getAttribute("from");
+ updateLastseen(message, account);
} else {
fullJid = message.getAttribute("to");
}
@@ -211,4 +215,23 @@ public class MessageParser {
return null;
}
}
+
+ private void updateLastseen(Element message, Account account) {
+ String[] fromParts = message.getAttribute("from").split("/");
+ String from = fromParts[0];
+ String presence = null;
+ if (fromParts.length >= 2) {
+ presence = fromParts[1];
+ }
+ Contact contact = account.getRoster().getContact(from);
+ if (presence!=null) {
+ contact.lastseen.presence = presence;
+ contact.lastseen.time = System.currentTimeMillis();
+ } else if ((contact.getPresences().size() == 1)&&(contact.getPresences().containsKey(contact.lastseen.presence))) {
+ contact.lastseen.time = System.currentTimeMillis();
+ } else {
+ contact.lastseen.presence = null;
+ contact.lastseen.time = System.currentTimeMillis();
+ }
+ }
}