From 7ee5e959597cfded524c7179b663138aca781ad8 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Sat, 21 Feb 2015 11:06:52 +0100 Subject: added typing notifications through XEP-0085. fixed #210 --- .../siacs/conversations/parser/MessageParser.java | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/main/java/eu/siacs/conversations/parser/MessageParser.java') diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index 49efb004..3f3cf8cb 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); -- cgit v1.2.3 From ff86fa604903cd77fe26860be0cc256b5d1e04eb Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 1 Mar 2015 14:15:40 +0100 Subject: mark all sent messages up to a marker as displayed --- .../java/eu/siacs/conversations/parser/MessageParser.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/main/java/eu/siacs/conversations/parser/MessageParser.java') diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index 3f3cf8cb..ced81520 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -402,14 +402,19 @@ public class MessageParser extends AbstractParser implements Element event = packet.findChild("event", "http://jabber.org/protocol/pubsub#event"); parseEvent(event, from, account); - } else if (from != null - && packet.hasChild("displayed", "urn:xmpp:chat-markers:0")) { + } else if (from != null && packet.hasChild("displayed", "urn:xmpp:chat-markers:0")) { String id = packet .findChild("displayed", "urn:xmpp:chat-markers:0") .getAttribute("id"); updateLastseen(packet, account, true); - mXmppConnectionService.markMessage(account, from.toBareJid(), - id, Message.STATUS_SEND_DISPLAYED); + final Message displayedMessage = mXmppConnectionService.markMessage(account, from.toBareJid(), id, Message.STATUS_SEND_DISPLAYED); + Message message = displayedMessage.prev(); + while(message != null + && message.getStatus() == Message.STATUS_SEND_RECEIVED + && message.getTimeSent() < displayedMessage.getTimeSent()) { + mXmppConnectionService.markMessage(message,Message.STATUS_SEND_DISPLAYED); + message = message.prev(); + } } else if (from != null && packet.hasChild("received", "urn:xmpp:chat-markers:0")) { String id = packet.findChild("received", "urn:xmpp:chat-markers:0") -- cgit v1.2.3 From 44028a547f23306cb8e88b0cb5b950e3c543fd34 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Fri, 6 Mar 2015 21:14:55 +0100 Subject: fixed npe in message parser --- src/main/java/eu/siacs/conversations/parser/MessageParser.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/main/java/eu/siacs/conversations/parser/MessageParser.java') diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index ced81520..6652842d 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -143,7 +143,7 @@ public class MessageParser extends AbstractParser implements finishedMessage.setRemoteMsgId(packet.getId()); finishedMessage.markable = isMarkable(packet); finishedMessage.setCounterpart(from); - extractChatState(conversation,packet); + extractChatState(conversation, packet); return finishedMessage; } catch (Exception e) { conversation.resetOtrSession(); @@ -408,11 +408,11 @@ public class MessageParser extends AbstractParser implements .getAttribute("id"); updateLastseen(packet, account, true); final Message displayedMessage = mXmppConnectionService.markMessage(account, from.toBareJid(), id, Message.STATUS_SEND_DISPLAYED); - Message message = displayedMessage.prev(); - while(message != null + Message message = displayedMessage == null ? null :displayedMessage.prev(); + while (message != null && message.getStatus() == Message.STATUS_SEND_RECEIVED && message.getTimeSent() < displayedMessage.getTimeSent()) { - mXmppConnectionService.markMessage(message,Message.STATUS_SEND_DISPLAYED); + mXmppConnectionService.markMessage(message, Message.STATUS_SEND_DISPLAYED); message = message.prev(); } } else if (from != null -- cgit v1.2.3 From 1c600fefcf9cba751bc8bc0f151cc03e28d9c4b9 Mon Sep 17 00:00:00 2001 From: BrianBlade Date: Mon, 16 Mar 2015 23:23:51 +0100 Subject: # add delivery receipts for private muc msgs # enable update last-seen for muc-msgs --- .../siacs/conversations/parser/MessageParser.java | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'src/main/java/eu/siacs/conversations/parser/MessageParser.java') diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index 6652842d..88d9daae 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -44,12 +44,11 @@ public class MessageParser extends AbstractParser implements } private Message parseChat(MessagePacket packet, Account account) { - final Jid jid = packet.getFrom(); + final Jid jid = packet.getFrom(); if (jid == null) { return null; } Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, jid.toBareJid(), false); - updateLastseen(packet, account, true); String pgpBody = getPgpBody(packet); Message finishedMessage; if (pgpBody != null) { @@ -64,13 +63,18 @@ public class MessageParser extends AbstractParser implements finishedMessage.markable = isMarkable(packet); if (conversation.getMode() == Conversation.MODE_MULTI && !jid.isBareJid()) { + final Jid trueCounterpart = conversation.getMucOptions() + .getTrueCounterpart(jid.getResourcepart()); + if (trueCounterpart != null) { + updateLastseen(packet, account, trueCounterpart, true); + } finishedMessage.setType(Message.TYPE_PRIVATE); - finishedMessage.setTrueCounterpart(conversation.getMucOptions() - .getTrueCounterpart(jid.getResourcepart())); + finishedMessage.setTrueCounterpart(trueCounterpart); if (conversation.hasDuplicateMessage(finishedMessage)) { return null; } - + } else { + updateLastseen(packet, account, true); } finishedMessage.setCounterpart(jid); finishedMessage.setTime(getTimestamp(packet)); @@ -89,7 +93,7 @@ public class MessageParser extends AbstractParser implements .findOrCreateConversation(account, from.toBareJid(), false); String presence; if (from.isBareJid()) { - presence = ""; + presence = ""; } else { presence = from.getResourcepart(); } @@ -153,7 +157,7 @@ public class MessageParser extends AbstractParser implements private Message parseGroupchat(MessagePacket packet, Account account) { int status; - final Jid from = packet.getFrom(); + final Jid from = packet.getFrom(); if (from == null) { return null; } @@ -163,6 +167,10 @@ public class MessageParser extends AbstractParser implements } Conversation conversation = mXmppConnectionService .findOrCreateConversation(account, from.toBareJid(), true); + final Jid trueCounterpart = conversation.getMucOptions().getTrueCounterpart(from.getResourcepart()); + if (trueCounterpart != null) { + updateLastseen(packet, account, trueCounterpart.toBareJid(), true); + } if (packet.hasChild("subject")) { conversation.setHasMessagesLeftOnServer(true); conversation.getMucOptions().setSubject(packet.findChild("subject").getContent()); -- cgit v1.2.3 From 442ae12ee5f979043e9ad248cdca0f2890b39654 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Thu, 19 Mar 2015 19:40:24 +0100 Subject: don't update presence for muc messages --- src/main/java/eu/siacs/conversations/parser/MessageParser.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'src/main/java/eu/siacs/conversations/parser/MessageParser.java') diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index 88d9daae..aa6aa4dc 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -1,11 +1,8 @@ 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; @@ -66,7 +63,7 @@ public class MessageParser extends AbstractParser implements final Jid trueCounterpart = conversation.getMucOptions() .getTrueCounterpart(jid.getResourcepart()); if (trueCounterpart != null) { - updateLastseen(packet, account, trueCounterpart, true); + updateLastseen(packet, account, trueCounterpart, false); } finishedMessage.setType(Message.TYPE_PRIVATE); finishedMessage.setTrueCounterpart(trueCounterpart); @@ -169,7 +166,7 @@ public class MessageParser extends AbstractParser implements .findOrCreateConversation(account, from.toBareJid(), true); final Jid trueCounterpart = conversation.getMucOptions().getTrueCounterpart(from.getResourcepart()); if (trueCounterpart != null) { - updateLastseen(packet, account, trueCounterpart.toBareJid(), true); + updateLastseen(packet, account, trueCounterpart, false); } if (packet.hasChild("subject")) { conversation.setHasMessagesLeftOnServer(true); -- cgit v1.2.3 From 99b2ef7e9d571dcfa386df4d0190ce626e657232 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Sat, 21 Mar 2015 16:07:17 +0100 Subject: respond to unreadable OTR messages with error message. fixed #1021 --- src/main/java/eu/siacs/conversations/parser/MessageParser.java | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/main/java/eu/siacs/conversations/parser/MessageParser.java') diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index aa6aa4dc..72ece046 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -118,6 +118,7 @@ public class MessageParser extends AbstractParser implements } } try { + conversation.setLastReceivedOtrMessageId(packet.getId()); Session otrSession = conversation.getOtrSession(); SessionStatus before = otrSession.getSessionStatus(); body = otrSession.transformReceiving(body); @@ -145,6 +146,7 @@ public class MessageParser extends AbstractParser implements finishedMessage.markable = isMarkable(packet); finishedMessage.setCounterpart(from); extractChatState(conversation, packet); + conversation.setLastReceivedOtrMessageId(null); return finishedMessage; } catch (Exception e) { conversation.resetOtrSession(); -- cgit v1.2.3 From c47d1e83c1a5ee11f6924dd4e8ac95f123802824 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Sat, 21 Mar 2015 16:43:03 +0100 Subject: properly set chat states when receiving otr status messages --- src/main/java/eu/siacs/conversations/parser/MessageParser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/java/eu/siacs/conversations/parser/MessageParser.java') diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index 72ece046..8ae9b642 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -94,6 +94,7 @@ public class MessageParser extends AbstractParser implements } else { presence = from.getResourcepart(); } + extractChatState(conversation, packet); updateLastseen(packet, account, true); String body = packet.getBody(); if (body.matches("^\\?OTRv\\d{1,2}\\?.*")) { @@ -145,7 +146,6 @@ public class MessageParser extends AbstractParser implements finishedMessage.setRemoteMsgId(packet.getId()); finishedMessage.markable = isMarkable(packet); finishedMessage.setCounterpart(from); - extractChatState(conversation, packet); conversation.setLastReceivedOtrMessageId(null); return finishedMessage; } catch (Exception e) { -- cgit v1.2.3