put xep333 parsing into parser class

This commit is contained in:
Daniel Gultsch 2014-06-06 18:49:35 +02:00
parent 476ab656ef
commit 246776067a
4 changed files with 31 additions and 30 deletions

View file

@ -34,7 +34,7 @@ public abstract class AbstractParser {
} }
} }
protected void updateLastseen(Element packet, Account account) { protected void updateLastseen(Element packet, Account account, boolean presenceOverwrite) {
String[] fromParts = packet.getAttribute("from").split("/"); String[] fromParts = packet.getAttribute("from").split("/");
String from = fromParts[0]; String from = fromParts[0];
String presence = null; String presence = null;
@ -45,7 +45,7 @@ public abstract class AbstractParser {
long timestamp = getTimestamp(packet); long timestamp = getTimestamp(packet);
if (timestamp >= contact.lastseen.time) { if (timestamp >= contact.lastseen.time) {
contact.lastseen.time = timestamp; contact.lastseen.time = timestamp;
if (presence!=null) { if ((presence!=null)&&(presenceOverwrite)) {
contact.lastseen.presence = presence; contact.lastseen.presence = presence;
} }
} }

View file

@ -24,7 +24,7 @@ public class MessageParser extends AbstractParser {
Conversation conversation = mXmppConnectionService Conversation conversation = mXmppConnectionService
.findOrCreateConversation(account, fromParts[0], false); .findOrCreateConversation(account, fromParts[0], false);
conversation.setLatestMarkableMessageId(getMarkableMessageId(packet)); conversation.setLatestMarkableMessageId(getMarkableMessageId(packet));
updateLastseen(packet, account); updateLastseen(packet, account,true);
String pgpBody = getPgpBody(packet); String pgpBody = getPgpBody(packet);
if (pgpBody != null) { if (pgpBody != null) {
return new Message(conversation, packet.getFrom(), pgpBody, return new Message(conversation, packet.getFrom(), pgpBody,
@ -42,7 +42,7 @@ public class MessageParser extends AbstractParser {
String[] fromParts = packet.getFrom().split("/"); String[] fromParts = packet.getFrom().split("/");
Conversation conversation = mXmppConnectionService Conversation conversation = mXmppConnectionService
.findOrCreateConversation(account, fromParts[0], false); .findOrCreateConversation(account, fromParts[0], false);
updateLastseen(packet, account); updateLastseen(packet, account,true);
String body = packet.getBody(); String body = packet.getBody();
if (!conversation.hasValidOtrSession()) { if (!conversation.hasValidOtrSession()) {
if (properlyAddressed) { if (properlyAddressed) {
@ -174,7 +174,7 @@ public class MessageParser extends AbstractParser {
return null; // either malformed or boring return null; // either malformed or boring
if (status == Message.STATUS_RECIEVED) { if (status == Message.STATUS_RECIEVED) {
fullJid = message.getAttribute("from"); fullJid = message.getAttribute("from");
updateLastseen(message, account); updateLastseen(message, account,true);
} else { } else {
fullJid = message.getAttribute("to"); fullJid = message.getAttribute("to");
} }
@ -199,6 +199,28 @@ public class MessageParser extends AbstractParser {
mXmppConnectionService.markMessage(account, fromParts[0], mXmppConnectionService.markMessage(account, fromParts[0],
packet.getId(), Message.STATUS_SEND_FAILED); packet.getId(), Message.STATUS_SEND_FAILED);
} }
public void parseNormal(MessagePacket packet, Account account) {
if (packet.hasChild("displayed","urn:xmpp:chat-markers:0")) {
String id = packet.findChild("displayed","urn:xmpp:chat-markers:0").getAttribute("id");
String[] fromParts = packet.getFrom().split("/");
updateLastseen(packet, account,true);
mXmppConnectionService.markMessage(account,fromParts[0], id, Message.STATUS_SEND_DISPLAYED);
} else if (packet.hasChild("received","urn:xmpp:chat-markers:0")) {
String id = packet.findChild("received","urn:xmpp:chat-markers:0").getAttribute("id");
String[] fromParts = packet.getFrom().split("/");
updateLastseen(packet, account,false);
mXmppConnectionService.markMessage(account,fromParts[0], id, Message.STATUS_SEND_RECEIVED);
} else if (packet.hasChild("x")) {
Element x = packet.findChild("x");
if (x.hasChild("invite")) {
Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, packet.getFrom(),
true);
mXmppConnectionService.updateUi(conversation, false);
}
}
}
private String getPgpBody(Element message) { private String getPgpBody(Element message) {
Element child = message.findChild("x", "jabber:x:encrypted"); Element child = message.findChild("x", "jabber:x:encrypted");
@ -216,4 +238,6 @@ public class MessageParser extends AbstractParser {
return null; return null;
} }
} }
} }

View file

@ -71,9 +71,9 @@ public class PresenceParser extends AbstractParser {
x.getContent())); x.getContent()));
} }
} }
updateLastseen(packet, account,true);
mXmppConnectionService.onContactStatusChanged mXmppConnectionService.onContactStatusChanged
.onContactStatusChanged(contact); .onContactStatusChanged(contact);
updateLastseen(packet, account);
} }
} else if (type.equals("unavailable")) { } else if (type.equals("unavailable")) {
if (fromParts.length != 2) { if (fromParts.length != 2) {

View file

@ -178,30 +178,7 @@ public class XmppConnectionService extends Service {
mMessageParser.parseError(packet, account); mMessageParser.parseError(packet, account);
return; return;
} else if (packet.getType() == MessagePacket.TYPE_NORMAL) { } else if (packet.getType() == MessagePacket.TYPE_NORMAL) {
if (packet.hasChild("displayed","urn:xmpp:chat-markers:0")) { mMessageParser.parseNormal(packet, account);
String id = packet.findChild("displayed","urn:xmpp:chat-markers:0").getAttribute("id");
String[] fromParts = packet.getFrom().split("/");
markMessage(account,fromParts[0], id, Message.STATUS_SEND_DISPLAYED);
Log.d(LOGTAG,"message was displayed by contact");
} else if (packet.hasChild("received","urn:xmpp:chat-markers:0")) {
String id = packet.findChild("received","urn:xmpp:chat-markers:0").getAttribute("id");
String[] fromParts = packet.getFrom().split("/");
markMessage(account,fromParts[0], id, Message.STATUS_SEND_RECEIVED);
} else if (packet.hasChild("x")) {
Element x = packet.findChild("x");
if (x.hasChild("invite")) {
findOrCreateConversation(account, packet.getFrom(),
true);
if (convChangedListener != null) {
convChangedListener.onConversationListChanged();
}
Log.d(LOGTAG,
"invitation received to " + packet.getFrom());
}
} else {
//Log.d(LOGTAG, "unparsed message " + packet.toString());
}
} }
if ((message == null) || (message.getBody() == null)) { if ((message == null) || (message.getBody() == null)) {
return; return;