diff options
author | steckbrief <steckbrief@chefmail.de> | 2017-08-06 14:28:00 +0200 |
---|---|---|
committer | steckbrief <steckbrief@chefmail.de> | 2017-08-06 14:28:00 +0200 |
commit | be1992ce897d3b0551e545646a3e0f45cc6dd8c2 (patch) | |
tree | c15c94ade61e5063095d8b429ae4acf85459493f /src/main/java/de/thedevstack/conversationsplus/parser | |
parent | f8e083a32cb7232c9601f5011b14738d43bb3b06 (diff) |
Implements XEP-0202 Entity Time, moves Software Version to xmpp package, moves namespace definitions for mam, carbons and avatar to xmpp package
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/parser')
-rw-r--r-- | src/main/java/de/thedevstack/conversationsplus/parser/IqParser.java | 12 | ||||
-rw-r--r-- | src/main/java/de/thedevstack/conversationsplus/parser/MessageParser.java | 50 |
2 files changed, 37 insertions, 25 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/parser/IqParser.java b/src/main/java/de/thedevstack/conversationsplus/parser/IqParser.java index 8af05df5..35b41d61 100644 --- a/src/main/java/de/thedevstack/conversationsplus/parser/IqParser.java +++ b/src/main/java/de/thedevstack/conversationsplus/parser/IqParser.java @@ -31,11 +31,16 @@ import de.thedevstack.conversationsplus.services.avatar.AvatarCache; import de.thedevstack.conversationsplus.services.avatar.AvatarService; import de.thedevstack.conversationsplus.services.XmppConnectionService; import de.thedevstack.conversationsplus.utils.Xmlns; +import de.thedevstack.conversationsplus.utils.XmppSendUtil; import de.thedevstack.conversationsplus.xml.Element; import de.thedevstack.conversationsplus.xmpp.OnIqPacketReceived; import de.thedevstack.conversationsplus.xmpp.OnUpdateBlocklist; +import de.thedevstack.conversationsplus.xmpp.iqversion.IqVersionPacket; +import de.thedevstack.conversationsplus.xmpp.iqversion.IqVersionPacketGenerator; import de.thedevstack.conversationsplus.xmpp.jid.Jid; import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket; +import de.thedevstack.conversationsplus.xmpp.time.TimePacket; +import de.thedevstack.conversationsplus.xmpp.time.TimePacketGenerator; public class IqParser extends AbstractParser implements OnIqPacketReceived { @@ -323,12 +328,13 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived { } else if (packet.hasChild("query", "http://jabber.org/protocol/disco#info")) { final IqPacket response = mXmppConnectionService.getIqGenerator().discoResponse(packet); mXmppConnectionService.sendIqPacket(account, response, null); - } else if (packet.hasChild("query","jabber:iq:version")) { - final IqPacket response = mXmppConnectionService.getIqGenerator().versionResponse(packet); - mXmppConnectionService.sendIqPacket(account,response,null); + } else if (packet.hasChild("query", IqVersionPacket.NAMESPACE)) { + XmppSendUtil.sendIqPacket(account, IqVersionPacketGenerator.generateResponse(packet), null); } else if (packet.hasChild("ping", "urn:xmpp:ping")) { final IqPacket response = packet.generateResponse(IqPacket.TYPE.RESULT); mXmppConnectionService.sendIqPacket(account, response, null); + } else if (packet.hasChild("time", TimePacket.NAMESPACE)) { + XmppSendUtil.sendIqPacket(account, TimePacketGenerator.generateResponse(packet), null); } else { if (packet.getType() == IqPacket.TYPE.GET || packet.getType() == IqPacket.TYPE.SET) { final IqPacket response = packet.generateResponse(IqPacket.TYPE.ERROR); diff --git a/src/main/java/de/thedevstack/conversationsplus/parser/MessageParser.java b/src/main/java/de/thedevstack/conversationsplus/parser/MessageParser.java index f282ae01..52d35f58 100644 --- a/src/main/java/de/thedevstack/conversationsplus/parser/MessageParser.java +++ b/src/main/java/de/thedevstack/conversationsplus/parser/MessageParser.java @@ -5,12 +5,18 @@ import android.util.Pair; import de.thedevstack.conversationsplus.entities.FileParams; import de.thedevstack.conversationsplus.enums.FileStatus; +import de.thedevstack.conversationsplus.persistance.DatabaseBackend; import de.thedevstack.conversationsplus.services.avatar.AvatarCache; import de.thedevstack.conversationsplus.services.filetransfer.http.download.AutomaticFileDownload; import de.thedevstack.conversationsplus.services.filetransfer.http.download.HttpRetrieveHead; import de.thedevstack.conversationsplus.utils.MessageUtil; +import de.thedevstack.conversationsplus.utils.UiUpdateHelper; +import de.thedevstack.conversationsplus.utils.XmppSendUtil; +import de.thedevstack.conversationsplus.xmpp.avatar.AvatarPacket; import de.thedevstack.conversationsplus.xmpp.avatar.AvatarPacketParser; +import de.thedevstack.conversationsplus.xmpp.carbons.Carbons; import de.thedevstack.conversationsplus.xmpp.httpuploadim.HttpUploadHint; +import de.thedevstack.conversationsplus.xmpp.mam.Mam; import de.tzur.conversations.Settings; import net.java.otr4j.session.Session; @@ -99,7 +105,7 @@ public class MessageParser extends AbstractParser implements return null; } else if (body == null && status == SessionStatus.FINISHED) { conversation.resetOtrSession(); - mXmppConnectionService.updateConversationUi(); + UiUpdateHelper.updateConversationUi(); return null; } else if (body == null || (body.isEmpty())) { return null; @@ -148,9 +154,9 @@ public class MessageParser extends AbstractParser implements Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, jid, true); if (!conversation.getMucOptions().online()) { conversation.getMucOptions().setPassword(password); - mXmppConnectionService.databaseBackend.updateConversation(conversation); + DatabaseBackend.getInstance().updateConversation(conversation); mXmppConnectionService.joinMuc(conversation); - mXmppConnectionService.updateConversationUi(); + UiUpdateHelper.updateConversationUi(); } return true; } @@ -189,24 +195,24 @@ public class MessageParser extends AbstractParser implements private void parseEvent(final Element event, final Jid from, final Account account) { Element items = event.findChild("items"); String node = items == null ? null : items.getAttribute("node"); - if ("urn:xmpp:avatar:metadata".equals(node)) { + if (AvatarPacket.NAMESPACE_AVATAR_METADATA.equals(node)) { Avatar avatar = AvatarPacketParser.parseMetadata(items); if (avatar != null) { avatar.owner = from.toBareJid(); if (AvatarUtil.isAvatarCached(avatar)) { if (account.getJid().toBareJid().equals(from)) { if (account.setAvatar(avatar.getFilename())) { - mXmppConnectionService.databaseBackend.updateAccount(account); + DatabaseBackend.getInstance().updateAccount(account); } AvatarCache.clear(account); - mXmppConnectionService.updateConversationUi(); - mXmppConnectionService.updateAccountUi(); + UiUpdateHelper.updateConversationUi(); + UiUpdateHelper.updateAccountUi(); } else { Contact contact = account.getRoster().getContact(from); contact.setAvatar(avatar); AvatarCache.clear(contact); - mXmppConnectionService.updateConversationUi(); - mXmppConnectionService.updateRosterUi(); + UiUpdateHelper.updateConversationUi(); + UiUpdateHelper.updateRosterUi(); } } else { AvatarService.getInstance().fetchAvatar(account, avatar); @@ -219,8 +225,8 @@ public class MessageParser extends AbstractParser implements Contact contact = account.getRoster().getContact(from); contact.setPresenceName(nick.getContent()); AvatarCache.clear(account); - mXmppConnectionService.updateConversationUi(); - mXmppConnectionService.updateAccountUi(); + UiUpdateHelper.updateConversationUi(); + UiUpdateHelper.updateAccountUi(); } } else if (ConversationsPlusPreferences.omemoEnabled() && AxolotlService.PEP_DEVICE_LIST.equals(node)) { Log.d(Config.LOGTAG, AxolotlServiceImpl.getLogprefix(account)+"Received PEP device list update from "+ from + ", processing..."); @@ -228,7 +234,7 @@ public class MessageParser extends AbstractParser implements Set<Integer> deviceIds = mXmppConnectionService.getIqParser().deviceIds(item); AxolotlService axolotlService = account.getAxolotlService(); axolotlService.registerDevices(from, deviceIds); - mXmppConnectionService.updateAccountUi(); + UiUpdateHelper.updateAccountUi(); } } @@ -266,15 +272,15 @@ public class MessageParser extends AbstractParser implements final boolean isForwarded; boolean isCarbon = false; String serverMsgId = null; - final Element fin = original.findChild("fin", "urn:xmpp:mam:0"); + final Element fin = original.findChild("fin", Mam.NAMESPACE); if (fin != null) { mXmppConnectionService.getMessageArchiveService().processFin(fin,original.getFrom()); return; } - final Element result = original.findChild("result","urn:xmpp:mam:0"); + final Element result = original.findChild("result", Mam.NAMESPACE); final MessageArchiveService.Query query = result == null ? null : mXmppConnectionService.getMessageArchiveService().findQuery(result.getAttribute("queryid")); if (query != null && query.validFrom(original.getFrom())) { - Pair<MessagePacket, Long> f = original.getForwardedMessagePacket("result", "urn:xmpp:mam:0"); + Pair<MessagePacket, Long> f = original.getForwardedMessagePacket("result", Mam.NAMESPACE); if (f == null) { return; } @@ -288,8 +294,8 @@ public class MessageParser extends AbstractParser implements return; } else if (original.fromServer(account)) { Pair<MessagePacket, Long> f; - f = original.getForwardedMessagePacket("received", "urn:xmpp:carbons:2"); - f = f == null ? original.getForwardedMessagePacket("sent", "urn:xmpp:carbons:2") : f; + f = original.getForwardedMessagePacket("received", Carbons.NAMESPACE); + f = f == null ? original.getForwardedMessagePacket("sent", Carbons.NAMESPACE) : f; packet = f != null ? f.first : original; if (handleErrorMessage(account, packet)) { return; @@ -339,7 +345,7 @@ public class MessageParser extends AbstractParser implements } if (extractChatState(mXmppConnectionService.find(account, counterpart.toBareJid()), packet)) { - mXmppConnectionService.updateConversationUi(); + UiUpdateHelper.updateConversationUi(); } if ((body != null || pgpEncrypted != null || axolotlEncrypted != null) && !isMucStatusMessage) { @@ -455,7 +461,7 @@ public class MessageParser extends AbstractParser implements } if (query == null) { - mXmppConnectionService.updateConversationUi(); + UiUpdateHelper.updateConversationUi(); } if (Settings.CONFIRM_MESSAGE_READ && remoteMsgId != null && !isForwarded && !isTypeGroupChat) { @@ -477,7 +483,7 @@ public class MessageParser extends AbstractParser implements } } if (message.getEncryption() == Message.ENCRYPTION_NONE || !ConversationsPlusPreferences.dontSaveEncrypted()) { - mXmppConnectionService.databaseBackend.createMessage(message); + DatabaseBackend.getInstance().createMessage(message); } if (message.trusted() && message.treatAsDownloadable() != Message.Decision.NEVER @@ -511,7 +517,7 @@ public class MessageParser extends AbstractParser implements mXmppConnectionService.pushBookmarks(account); } } - mXmppConnectionService.updateConversationUi(); + UiUpdateHelper.updateConversationUi(); return; } } @@ -580,7 +586,7 @@ public class MessageParser extends AbstractParser implements packet, receiptsNamespaces, packet.getType()); - mXmppConnectionService.sendMessagePacket(account, receipt); + XmppSendUtil.sendMessagePacket(account, receipt); } } } |