aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/parser
diff options
context:
space:
mode:
authorSam Whited <sam@samwhited.com>2014-11-05 15:55:47 -0500
committerSam Whited <sam@samwhited.com>2014-11-09 07:00:40 -0500
commit9053f4aca0c232db77dbd0a1e5b9b09bf41bec22 (patch)
treed44820f93e139f696228c6abcbac02b75a9f7c44 /src/main/java/eu/siacs/conversations/parser
parenta9908613162f753ad71ac25890fb7cc067925764 (diff)
Move a chunk of classes over to using JID objects
Diffstat (limited to 'src/main/java/eu/siacs/conversations/parser')
-rw-r--r--src/main/java/eu/siacs/conversations/parser/AbstractParser.java26
-rw-r--r--src/main/java/eu/siacs/conversations/parser/IqParser.java21
2 files changed, 31 insertions, 16 deletions
diff --git a/src/main/java/eu/siacs/conversations/parser/AbstractParser.java b/src/main/java/eu/siacs/conversations/parser/AbstractParser.java
index 5541c1c6..9e413052 100644
--- a/src/main/java/eu/siacs/conversations/parser/AbstractParser.java
+++ b/src/main/java/eu/siacs/conversations/parser/AbstractParser.java
@@ -11,6 +11,8 @@ import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.xml.Element;
+import eu.siacs.conversations.xmpp.jid.InvalidJidException;
+import eu.siacs.conversations.xmpp.jid.Jid;
public abstract class AbstractParser {
@@ -22,7 +24,7 @@ public abstract class AbstractParser {
protected long getTimestamp(Element packet) {
long now = System.currentTimeMillis();
- ArrayList<String> stamps = new ArrayList<String>();
+ ArrayList<String> stamps = new ArrayList<>();
for (Element child : packet.getChildren()) {
if (child.getName().equals("delay")) {
stamps.add(child.getAttribute("stamp").replace("Z", "+0000"));
@@ -58,21 +60,21 @@ public abstract class AbstractParser {
}
}
- protected void updateLastseen(Element packet, Account account,
- boolean presenceOverwrite) {
- String[] fromParts = packet.getAttribute("from").split("/", 2);
- String from = fromParts[0];
- String presence = null;
- if (fromParts.length >= 2) {
- presence = fromParts[1];
- } else {
- presence = "";
- }
+ protected void updateLastseen(final Element packet, final Account account,
+ final boolean presenceOverwrite) {
+ Jid from;
+ try {
+ from = Jid.fromString(packet.getAttribute("from")).toBareJid();
+ } catch (final InvalidJidException e) {
+ // TODO: Handle this?
+ from = null;
+ }
+ String presence = from == null || from.getResourcepart().isEmpty() ? "" : from.getResourcepart();
Contact contact = account.getRoster().getContact(from);
long timestamp = getTimestamp(packet);
if (timestamp >= contact.lastseen.time) {
contact.lastseen.time = timestamp;
- if ((presence != null) && (presenceOverwrite)) {
+ if (!presence.isEmpty() && presenceOverwrite) {
contact.lastseen.presence = presence;
}
}
diff --git a/src/main/java/eu/siacs/conversations/parser/IqParser.java b/src/main/java/eu/siacs/conversations/parser/IqParser.java
index df6754f2..1c66da26 100644
--- a/src/main/java/eu/siacs/conversations/parser/IqParser.java
+++ b/src/main/java/eu/siacs/conversations/parser/IqParser.java
@@ -5,6 +5,8 @@ import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.OnIqPacketReceived;
+import eu.siacs.conversations.xmpp.jid.InvalidJidException;
+import eu.siacs.conversations.xmpp.jid.Jid;
import eu.siacs.conversations.xmpp.stanzas.IqPacket;
public class IqParser extends AbstractParser implements OnIqPacketReceived {
@@ -20,8 +22,14 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived {
}
for (Element item : query.getChildren()) {
if (item.getName().equals("item")) {
- String jid = item.getAttribute("jid");
- String name = item.getAttribute("name");
+ Jid jid;
+ try {
+ jid = Jid.fromString(item.getAttribute("jid"));
+ } catch (final InvalidJidException e) {
+ // TODO: Handle this?
+ jid = null;
+ }
+ String name = item.getAttribute("name");
String subscription = item.getAttribute("subscription");
Contact contact = account.getRoster().getContact(jid);
if (!contact.getOption(Contact.Options.DIRTY_PUSH)) {
@@ -59,8 +67,13 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived {
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
if (packet.hasChild("query", "jabber:iq:roster")) {
- String from = packet.getFrom();
- if ((from == null) || (from.equals(account.getJid()))) {
+ Jid from = null;
+ try {
+ from = Jid.fromString(packet.getFrom());
+ } catch (final InvalidJidException e) {
+ // TODO: Handle this?
+ }
+ if ((from == null) || (from.equals(account.getJid()))) {
Element query = packet.findChild("query");
this.rosterItems(account, query);
}