From 198a7db954a63d710bad60370c652c66cc255067 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 15 May 2020 18:44:55 +0200 Subject: [PATCH] use escaped jid in more places --- .../siacs/conversations/entities/Bookmark.java | 2 +- .../conversations/generator/IqGenerator.java | 10 +++++----- .../generator/MessageGenerator.java | 2 +- .../ui/ConferenceDetailsActivity.java | 6 +++--- .../conversations/ui/TrustKeysActivity.java | 2 +- .../services/PushManagementService.java | 16 +--------------- 6 files changed, 12 insertions(+), 26 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Bookmark.java b/src/main/java/eu/siacs/conversations/entities/Bookmark.java index 710c3438a..e55622a06 100644 --- a/src/main/java/eu/siacs/conversations/entities/Bookmark.java +++ b/src/main/java/eu/siacs/conversations/entities/Bookmark.java @@ -28,7 +28,7 @@ public class Bookmark extends Element implements ListItem { public Bookmark(final Account account, final Jid jid) { super("conference"); this.jid = jid; - this.setAttribute("jid", jid.toString()); + this.setAttribute("jid", jid); this.account = account; } diff --git a/src/main/java/eu/siacs/conversations/generator/IqGenerator.java b/src/main/java/eu/siacs/conversations/generator/IqGenerator.java index df5e9f68a..dc3740128 100644 --- a/src/main/java/eu/siacs/conversations/generator/IqGenerator.java +++ b/src/main/java/eu/siacs/conversations/generator/IqGenerator.java @@ -334,7 +334,7 @@ public class IqGenerator extends AbstractGenerator { public IqPacket generateSetBlockRequest(final Jid jid, boolean reportSpam) { final IqPacket iq = new IqPacket(IqPacket.TYPE.SET); final Element block = iq.addChild("block", Namespace.BLOCKING); - final Element item = block.addChild("item").setAttribute("jid", jid.toEscapedString()); + final Element item = block.addChild("item").setAttribute("jid", jid); if (reportSpam) { item.addChild("report", "urn:xmpp:reporting:0").addChild("spam"); } @@ -345,7 +345,7 @@ public class IqGenerator extends AbstractGenerator { public IqPacket generateSetUnblockRequest(final Jid jid) { final IqPacket iq = new IqPacket(IqPacket.TYPE.SET); final Element block = iq.addChild("unblock", Namespace.BLOCKING); - block.addChild("item").setAttribute("jid", jid.toEscapedString()); + block.addChild("item").setAttribute("jid", jid); return iq; } @@ -372,7 +372,7 @@ public class IqGenerator extends AbstractGenerator { Element query = packet.query("http://jabber.org/protocol/muc#admin"); for (Jid jid : jids) { Element item = query.addChild("item"); - item.setAttribute("jid", jid.toEscapedString()); + item.setAttribute("jid", jid); item.setAttribute("affiliation", affiliation); } return packet; @@ -489,7 +489,7 @@ public class IqGenerator extends AbstractGenerator { public IqPacket enablePush(final Jid jid, final String node, final String secret) { IqPacket packet = new IqPacket(IqPacket.TYPE.SET); Element enable = packet.addChild("enable", Namespace.PUSH); - enable.setAttribute("jid", jid.toString()); + enable.setAttribute("jid", jid); enable.setAttribute("node", node); if (secret != null) { Data data = new Data(); @@ -504,7 +504,7 @@ public class IqGenerator extends AbstractGenerator { public IqPacket disablePush(final Jid jid, final String node) { IqPacket packet = new IqPacket(IqPacket.TYPE.SET); Element disable = packet.addChild("disable", Namespace.PUSH); - disable.setAttribute("jid", jid.toEscapedString()); + disable.setAttribute("jid", jid); disable.setAttribute("node", node); return packet; } diff --git a/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java b/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java index 9ec8682eb..1a4454cc5 100644 --- a/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java +++ b/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java @@ -198,7 +198,7 @@ public class MessageGenerator extends AbstractGenerator { packet.setTo(contact); packet.setFrom(conversation.getAccount().getJid()); Element x = packet.addChild("x", "jabber:x:conference"); - x.setAttribute("jid", conversation.getJid().asBareJid().toString()); + x.setAttribute("jid", conversation.getJid().asBareJid()); String password = conversation.getMucOptions().getPassword(); if (password != null) { x.setAttribute("password", password); diff --git a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java index 2f9ac958b..946a066fb 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java @@ -445,9 +445,9 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers final User self = mucOptions.getSelf(); String account; if (Config.DOMAIN_LOCK != null) { - account = mConversation.getAccount().getJid().getLocal(); + account = mConversation.getAccount().getJid().getEscapedLocal(); } else { - account = mConversation.getAccount().getJid().asBareJid().toString(); + account = mConversation.getAccount().getJid().asBareJid().toEscapedString(); } setTitle(mucOptions.isPrivateAndNonAnonymous() ? R.string.action_muc_details : R.string.channel_details); this.binding.editMucNameButton.setVisibility((self.getAffiliation().ranks(MucOptions.Affiliation.OWNER) || mucOptions.canChangeSubject()) ? View.VISIBLE : View.GONE); @@ -584,7 +584,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers @Override public void onAffiliationChangeFailed(Jid jid, int resId) { - displayToast(getString(resId, jid.asBareJid().toString())); + displayToast(getString(resId, jid.asBareJid().toEscapedString())); } @Override diff --git a/src/main/java/eu/siacs/conversations/ui/TrustKeysActivity.java b/src/main/java/eu/siacs/conversations/ui/TrustKeysActivity.java index f12e03131..0ac96fea4 100644 --- a/src/main/java/eu/siacs/conversations/ui/TrustKeysActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/TrustKeysActivity.java @@ -213,7 +213,7 @@ public class TrustKeysActivity extends OmemoActivity implements OnKeyStatusUpdat showCameraToast(); } - binding.ownKeysTitle.setText(mAccount.getJid().asBareJid().toString()); + binding.ownKeysTitle.setText(mAccount.getJid().asBareJid().toEscapedString()); binding.ownKeysCard.setVisibility(hasOwnKeys ? View.VISIBLE : View.GONE); binding.foreignKeys.setVisibility(hasForeignKeys ? View.VISIBLE : View.GONE); if (hasPendingKeyFetches()) { diff --git a/src/playstore/java/eu/siacs/conversations/services/PushManagementService.java b/src/playstore/java/eu/siacs/conversations/services/PushManagementService.java index 8469225b0..57b9b1c61 100644 --- a/src/playstore/java/eu/siacs/conversations/services/PushManagementService.java +++ b/src/playstore/java/eu/siacs/conversations/services/PushManagementService.java @@ -10,15 +10,13 @@ import com.google.firebase.iid.InstanceIdResult; import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Account; -import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.utils.PhoneHelper; import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xml.Namespace; -import eu.siacs.conversations.xmpp.OnIqPacketReceived; +import eu.siacs.conversations.xmpp.Jid; import eu.siacs.conversations.xmpp.XmppConnection; import eu.siacs.conversations.xmpp.forms.Data; import eu.siacs.conversations.xmpp.stanzas.IqPacket; -import rocks.xmpp.addr.Jid; public class PushManagementService { @@ -63,18 +61,6 @@ public class PushManagementService { }); } - public void unregisterChannel(final Account account, final String channel) { - final String androidId = PhoneHelper.getAndroidId(mXmppConnectionService); - final Jid appServer = getAppServer(); - final IqPacket packet = mXmppConnectionService.getIqGenerator().unregisterChannelOnAppServer(appServer, androidId, channel); - mXmppConnectionService.sendIqPacket(account, packet, (a, response) -> { - if (response.getType() == IqPacket.TYPE.RESULT) { - Log.d(Config.LOGTAG,a.getJid().asBareJid()+": successfully unregistered channel"); - } else if (response.getType() == IqPacket.TYPE.ERROR) { - Log.d(Config.LOGTAG, a.getJid().asBareJid()+": unable to unregister channel with hash "+channel); - } - }); - } private void enablePushOnServer(final Account account, final Jid appServer, final String node, final String secret) { final IqPacket enable = mXmppConnectionService.getIqGenerator().enablePush(appServer, node, secret); mXmppConnectionService.sendIqPacket(account, enable, (a, p) -> {