aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/parser
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2015-02-21 11:06:52 +0100
committeriNPUTmice <daniel@gultsch.de>2015-02-21 11:06:52 +0100
commit7ee5e959597cfded524c7179b663138aca781ad8 (patch)
tree29a97c63d690a4d419a5500b1bb5a1c10f1f078b /src/main/java/eu/siacs/conversations/parser
parent3f248e0d89af977e7f602102663be9729430f1ed (diff)
added typing notifications through XEP-0085. fixed #210
Diffstat (limited to 'src/main/java/eu/siacs/conversations/parser')
-rw-r--r--src/main/java/eu/siacs/conversations/parser/MessageParser.java25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java
index 49efb0044..3f3cf8cbb 100644
--- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java
+++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java
@@ -1,8 +1,11 @@
package eu.siacs.conversations.parser;
+import android.util.Log;
+
import net.java.otr4j.session.Session;
import net.java.otr4j.session.SessionStatus;
+import eu.siacs.conversations.Config;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation;
@@ -14,6 +17,7 @@ import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.utils.CryptoHelper;
import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.OnMessagePacketReceived;
+import eu.siacs.conversations.xmpp.chatstate.ChatState;
import eu.siacs.conversations.xmpp.jid.Jid;
import eu.siacs.conversations.xmpp.pep.Avatar;
import eu.siacs.conversations.xmpp.stanzas.MessagePacket;
@@ -24,6 +28,21 @@ public class MessageParser extends AbstractParser implements
super(service);
}
+ private boolean extractChatState(Conversation conversation, final Element element) {
+ ChatState state = ChatState.parse(element);
+ if (state != null && conversation != null) {
+ final Account account = conversation.getAccount();
+ Jid from = element.getAttributeAsJid("from");
+ if (from != null && from.toBareJid().equals(account.getJid().toBareJid())) {
+ conversation.setOutgoingChatState(state);
+ return false;
+ } else {
+ return conversation.setIncomingChatState(state);
+ }
+ }
+ return false;
+ }
+
private Message parseChat(MessagePacket packet, Account account) {
final Jid jid = packet.getFrom();
if (jid == null) {
@@ -55,6 +74,7 @@ public class MessageParser extends AbstractParser implements
}
finishedMessage.setCounterpart(jid);
finishedMessage.setTime(getTimestamp(packet));
+ extractChatState(conversation,packet);
return finishedMessage;
}
@@ -123,6 +143,7 @@ public class MessageParser extends AbstractParser implements
finishedMessage.setRemoteMsgId(packet.getId());
finishedMessage.markable = isMarkable(packet);
finishedMessage.setCounterpart(from);
+ extractChatState(conversation,packet);
return finishedMessage;
} catch (Exception e) {
conversation.resetOtrSession();
@@ -275,6 +296,7 @@ public class MessageParser extends AbstractParser implements
finishedMessage = new Message(conversation, body,
Message.ENCRYPTION_NONE, status);
}
+ extractChatState(conversation,message);
finishedMessage.setTime(getTimestamp(message));
finishedMessage.setRemoteMsgId(message.getAttribute("id"));
finishedMessage.markable = isMarkable(message);
@@ -362,6 +384,9 @@ public class MessageParser extends AbstractParser implements
private void parseNonMessage(Element packet, Account account) {
final Jid from = packet.getAttributeAsJid("from");
+ if (extractChatState(from == null ? null : mXmppConnectionService.find(account,from), packet)) {
+ mXmppConnectionService.updateConversationUi();
+ }
Element invite = extractInvite(packet);
if (invite != null) {
Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, from, true);