aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/parser/MessageParser.java
diff options
context:
space:
mode:
authorlookshe <github@lookshe.org>2015-04-11 14:15:07 +0200
committerlookshe <github@lookshe.org>2015-04-11 14:15:07 +0200
commitdf63c14617bc8d665bfeac62cde0b29e6aa98873 (patch)
treeb825c0c87bcd9833ecfad85ecc5c0901ea4d77eb /src/main/java/eu/siacs/conversations/parser/MessageParser.java
parent87e56b534ad41199380c97e16ad25acbd077878c (diff)
parente17b75511e7c9d8206939b742972021c5c9d6b86 (diff)
Merge branch 'trz/master' of ssh://git.fucktheforce.de/conversations into trz/master
Diffstat (limited to 'src/main/java/eu/siacs/conversations/parser/MessageParser.java')
-rw-r--r--src/main/java/eu/siacs/conversations/parser/MessageParser.java59
1 files changed, 48 insertions, 11 deletions
diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java
index 49efb004..8ae9b642 100644
--- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java
+++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java
@@ -14,6 +14,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,13 +25,27 @@ 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();
+ 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) {
@@ -45,16 +60,22 @@ 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, false);
+ }
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));
+ extractChatState(conversation,packet);
return finishedMessage;
}
@@ -69,10 +90,11 @@ public class MessageParser extends AbstractParser implements
.findOrCreateConversation(account, from.toBareJid(), false);
String presence;
if (from.isBareJid()) {
- presence = "";
+ presence = "";
} else {
presence = from.getResourcepart();
}
+ extractChatState(conversation, packet);
updateLastseen(packet, account, true);
String body = packet.getBody();
if (body.matches("^\\?OTRv\\d{1,2}\\?.*")) {
@@ -97,6 +119,7 @@ public class MessageParser extends AbstractParser implements
}
}
try {
+ conversation.setLastReceivedOtrMessageId(packet.getId());
Session otrSession = conversation.getOtrSession();
SessionStatus before = otrSession.getSessionStatus();
body = otrSession.transformReceiving(body);
@@ -123,6 +146,7 @@ public class MessageParser extends AbstractParser implements
finishedMessage.setRemoteMsgId(packet.getId());
finishedMessage.markable = isMarkable(packet);
finishedMessage.setCounterpart(from);
+ conversation.setLastReceivedOtrMessageId(null);
return finishedMessage;
} catch (Exception e) {
conversation.resetOtrSession();
@@ -132,7 +156,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;
}
@@ -142,6 +166,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, false);
+ }
if (packet.hasChild("subject")) {
conversation.setHasMessagesLeftOnServer(true);
conversation.getMucOptions().setSubject(packet.findChild("subject").getContent());
@@ -275,6 +303,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 +391,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);
@@ -377,14 +409,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 == null ? null :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")