diff options
Diffstat (limited to 'src/eu/siacs/conversations/parser')
4 files changed, 50 insertions, 43 deletions
diff --git a/src/eu/siacs/conversations/parser/AbstractParser.java b/src/eu/siacs/conversations/parser/AbstractParser.java index 96d11508..25fcd921 100644 --- a/src/eu/siacs/conversations/parser/AbstractParser.java +++ b/src/eu/siacs/conversations/parser/AbstractParser.java @@ -13,17 +13,17 @@ import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.xml.Element; public abstract class AbstractParser { - + protected XmppConnectionService mXmppConnectionService; protected AbstractParser(XmppConnectionService service) { this.mXmppConnectionService = service; } - + protected long getTimestamp(Element packet) { long now = System.currentTimeMillis(); ArrayList<String> stamps = new ArrayList<String>(); - for(Element child : packet.getChildren()) { + for (Element child : packet.getChildren()) { if (child.getName().equals("delay")) { stamps.add(child.getAttribute("stamp").replace("Z", "+0000")); } @@ -33,17 +33,18 @@ public abstract class AbstractParser { try { String stamp = stamps.get(stamps.size() - 1); if (stamp.contains(".")) { - Date date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ",Locale.US) - .parse(stamp); - if (now<date.getTime()) { + Date date = new SimpleDateFormat( + "yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US) + .parse(stamp); + if (now < date.getTime()) { return now; } else { return date.getTime(); } } else { - Date date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ",Locale.US) - .parse(stamp); - if (now<date.getTime()) { + Date date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", + Locale.US).parse(stamp); + if (now < date.getTime()) { return now; } else { return date.getTime(); @@ -56,8 +57,9 @@ public abstract class AbstractParser { return now; } } - - protected void updateLastseen(Element packet, Account account, boolean presenceOverwrite) { + + protected void updateLastseen(Element packet, Account account, + boolean presenceOverwrite) { String[] fromParts = packet.getAttribute("from").split("/"); String from = fromParts[0]; String presence = null; @@ -70,19 +72,19 @@ public abstract class AbstractParser { long timestamp = getTimestamp(packet); if (timestamp >= contact.lastseen.time) { contact.lastseen.time = timestamp; - if ((presence!=null)&&(presenceOverwrite)) { + if ((presence != null) && (presenceOverwrite)) { contact.lastseen.presence = presence; } } } - + protected String avatarData(Element items) { Element item = items.findChild("item"); - if (item==null) { + if (item == null) { return null; } - Element data = item.findChild("data","urn:xmpp:avatar:data"); - if (data==null) { + Element data = item.findChild("data", "urn:xmpp:avatar:data"); + if (data == null) { return null; } return data.getContent(); diff --git a/src/eu/siacs/conversations/parser/IqParser.java b/src/eu/siacs/conversations/parser/IqParser.java index a22ff6a5..592b77a4 100644 --- a/src/eu/siacs/conversations/parser/IqParser.java +++ b/src/eu/siacs/conversations/parser/IqParser.java @@ -12,7 +12,7 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived { public IqParser(XmppConnectionService service) { super(service); } - + public void rosterItems(Account account, Element query) { String version = query.getAttribute("ver"); if (version != null) { @@ -27,7 +27,7 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived { if (!contact.getOption(Contact.Options.DIRTY_PUSH)) { contact.setServerName(name); } - if (subscription!=null) { + if (subscription != null) { if (subscription.equals("remove")) { contact.resetOption(Contact.Options.IN_ROSTER); contact.resetOption(Contact.Options.DIRTY_DELETE); @@ -42,14 +42,15 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived { } mXmppConnectionService.updateRosterUi(); } - + public String avatarData(IqPacket packet) { - Element pubsub = packet.findChild("pubsub", "http://jabber.org/protocol/pubsub"); - if (pubsub==null) { + Element pubsub = packet.findChild("pubsub", + "http://jabber.org/protocol/pubsub"); + if (pubsub == null) { return null; } Element items = pubsub.findChild("items"); - if (items==null) { + if (items == null) { return null; } return super.avatarData(items); @@ -63,20 +64,19 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived { Element query = packet.findChild("query"); this.rosterItems(account, query); } - } else if (packet - .hasChild("open", "http://jabber.org/protocol/ibb") - || packet - .hasChild("data", "http://jabber.org/protocol/ibb")) { - mXmppConnectionService.getJingleConnectionManager().deliverIbbPacket(account, packet); + } else if (packet.hasChild("open", "http://jabber.org/protocol/ibb") + || packet.hasChild("data", "http://jabber.org/protocol/ibb")) { + mXmppConnectionService.getJingleConnectionManager() + .deliverIbbPacket(account, packet); } else if (packet.hasChild("query", "http://jabber.org/protocol/disco#info")) { - IqPacket response = mXmppConnectionService.getIqGenerator().discoResponse(packet); + IqPacket response = mXmppConnectionService.getIqGenerator() + .discoResponse(packet); account.getXmppConnection().sendIqPacket(response, null); } else { if ((packet.getType() == IqPacket.TYPE_GET) || (packet.getType() == IqPacket.TYPE_SET)) { - IqPacket response = packet - .generateRespone(IqPacket.TYPE_ERROR); + IqPacket response = packet.generateRespone(IqPacket.TYPE_ERROR); Element error = response.addChild("error"); error.setAttribute("type", "cancel"); error.addChild("feature-not-implemented", diff --git a/src/eu/siacs/conversations/parser/MessageParser.java b/src/eu/siacs/conversations/parser/MessageParser.java index 0d46074d..3dca636e 100644 --- a/src/eu/siacs/conversations/parser/MessageParser.java +++ b/src/eu/siacs/conversations/parser/MessageParser.java @@ -4,6 +4,7 @@ import android.os.SystemClock; 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; @@ -18,7 +19,7 @@ import eu.siacs.conversations.xmpp.stanzas.MessagePacket; public class MessageParser extends AbstractParser implements OnMessagePacketReceived { - private long lastCarbonMessageReceived = -XmppConnectionService.CARBON_GRACE_PERIOD; + private long lastCarbonMessageReceived = -(Config.CARBON_GRACE_PERIOD * 1000); public MessageParser(XmppConnectionService service) { super(service); @@ -173,7 +174,8 @@ public class MessageParser extends AbstractParser implements finishedMessage.setTrueCounterpart(conversation.getMucOptions() .getTrueCounterpart(counterPart)); } - if (packet.hasChild("delay") && conversation.hasDuplicateMessage(finishedMessage)) { + if (packet.hasChild("delay") + && conversation.hasDuplicateMessage(finishedMessage)) { return null; } finishedMessage.setTime(getTimestamp(packet)); @@ -198,7 +200,8 @@ public class MessageParser extends AbstractParser implements } Element message = forwarded.findChild("message"); if ((message == null) || (!message.hasChild("body"))) { - if (status == Message.STATUS_RECEIVED && message.getAttribute("from")!=null) { + if (status == Message.STATUS_RECEIVED + && message.getAttribute("from") != null) { parseNormal(message, account); } return null; @@ -220,7 +223,7 @@ public class MessageParser extends AbstractParser implements Conversation conversation = mXmppConnectionService .findOrCreateConversation(account, parts[0], false); conversation.setLatestMarkableMessageId(getMarkableMessageId(packet)); - + String pgpBody = getPgpBody(message); Message finishedMessage; if (pgpBody != null) { @@ -243,7 +246,7 @@ public class MessageParser extends AbstractParser implements return null; } } - + return finishedMessage; } @@ -307,16 +310,18 @@ public class MessageParser extends AbstractParser implements if (node != null) { if (node.equals("urn:xmpp:avatar:metadata")) { Avatar avatar = Avatar.parseMetadata(items); - if (avatar!=null) { + if (avatar != null) { avatar.owner = from; if (mXmppConnectionService.getFileBackend().isAvatarCached( avatar)) { if (account.getJid().equals(from)) { if (account.setAvatar(avatar.getFilename())) { - mXmppConnectionService.databaseBackend.updateAccount(account); + mXmppConnectionService.databaseBackend + .updateAccount(account); } } else { - Contact contact = account.getRoster().getContact(from); + Contact contact = account.getRoster().getContact( + from); contact.setAvatar(avatar.getFilename()); } } else { @@ -324,11 +329,11 @@ public class MessageParser extends AbstractParser implements } } } else { - Log.d("xmppService", account.getJid() + ": " + node + " from " + Log.d(Config.LOGTAG, account.getJid() + ": " + node + " from " + from); } } else { - Log.d("xmppService", event.toString()); + Log.d(Config.LOGTAG, event.toString()); } } @@ -355,7 +360,7 @@ public class MessageParser extends AbstractParser implements boolean notify = true; if (mXmppConnectionService.getPreferences().getBoolean( "notification_grace_period_after_carbon_received", true)) { - notify = (SystemClock.elapsedRealtime() - lastCarbonMessageReceived) > XmppConnectionService.CARBON_GRACE_PERIOD; + notify = (SystemClock.elapsedRealtime() - lastCarbonMessageReceived) > (Config.CARBON_GRACE_PERIOD * 1000); } if ((packet.getType() == MessagePacket.TYPE_CHAT)) { diff --git a/src/eu/siacs/conversations/parser/PresenceParser.java b/src/eu/siacs/conversations/parser/PresenceParser.java index ea19df6f..32667007 100644 --- a/src/eu/siacs/conversations/parser/PresenceParser.java +++ b/src/eu/siacs/conversations/parser/PresenceParser.java @@ -26,7 +26,7 @@ public class PresenceParser extends AbstractParser implements if (muc != null) { boolean before = muc.getMucOptions().online(); muc.getMucOptions().processPacket(packet, mPgpEngine); - if (before!=muc.getMucOptions().online()) { + if (before != muc.getMucOptions().online()) { mXmppConnectionService.updateConversationUi(); } } @@ -36,7 +36,7 @@ public class PresenceParser extends AbstractParser implements if (muc != null) { boolean before = muc.getMucOptions().online(); muc.getMucOptions().processPacket(packet, mPgpEngine); - if (before!=muc.getMucOptions().online()) { + if (before != muc.getMucOptions().online()) { mXmppConnectionService.updateConversationUi(); } } |