From b09a1432a347e9700ace8aa8fe729f53bfcfac80 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 18 Mar 2021 11:35:41 +0100 Subject: [PATCH] Stanza.getErrorCondation only ever needs the tag name --- .../services/XmppConnectionService.java | 13 ++-- .../conversations/xmpp/XmppConnection.java | 2 +- .../AbstractAcknowledgeableStanza.java | 62 +++++++++---------- 3 files changed, 35 insertions(+), 42 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 3256d2c15..146fc8bf1 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -1797,7 +1797,7 @@ public class XmppConnectionService extends Service { IqPacket request = mIqGenerator.deleteItem(Namespace.BOOKMARKS2, bookmark.getJid().asBareJid().toEscapedString()); sendIqPacket(account, request, (a, response) -> { if (response.getType() == IqPacket.TYPE.ERROR) { - Log.d(Config.LOGTAG, a.getJid().asBareJid() + ": unable to delete bookmark " + response.getError()); + Log.d(Config.LOGTAG, a.getJid().asBareJid() + ": unable to delete bookmark " + response.getErrorCondition()); } }); } else if (connection.getFeatures().bookmarksConversion()) { @@ -2867,13 +2867,12 @@ public class XmppConnectionService extends Service { } @Override - public void onFetchFailed(final Conversation conversation, Element error) { + public void onFetchFailed(final Conversation conversation, final String errorCondition) { if (conversation.getStatus() == Conversation.STATUS_ARCHIVED) { Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": conversation (" + conversation.getJid() + ") got archived before IQ result"); - return; } - if (error != null && "remote-server-not-found".equals(error.getName())) { + if ("remote-server-not-found".equals(errorCondition)) { synchronized (account.inProgressConferenceJoins) { account.inProgressConferenceJoins.remove(conversation); } @@ -3239,7 +3238,7 @@ public class XmppConnectionService extends Service { Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": received timeout waiting for conference configuration fetch"); } else { if (callback != null) { - callback.onFetchFailed(conversation, packet.getError()); + callback.onFetchFailed(conversation, packet.getErrorCondition()); } } } @@ -3534,7 +3533,7 @@ public class XmppConnectionService extends Service { if (publicationResponse.getType() == IqPacket.TYPE.RESULT) { callback.onAvatarPublicationSucceeded(); } else { - Log.d(Config.LOGTAG, "failed to publish vcard " + publicationResponse.getError()); + Log.d(Config.LOGTAG, "failed to publish vcard " + publicationResponse.getErrorCondition()); callback.onAvatarPublicationFailed(R.string.error_publish_avatar_server_reject); } }); @@ -4817,7 +4816,7 @@ public class XmppConnectionService extends Service { public interface OnConferenceConfigurationFetched { void onConferenceConfigurationFetched(Conversation conversation); - void onFetchFailed(Conversation conversation, Element error); + void onFetchFailed(Conversation conversation, String errorCondition); } public interface OnConferenceJoined { diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index baa8dcae8..b188824ae 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -930,7 +930,7 @@ public class XmppConnection implements Runnable { if (response.getType() == IqPacket.TYPE.RESULT) { sendRegistryRequest(); } else { - final Element error = response.getError(); + final String error = response.getErrorCondition(); Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": failed to pre auth. " + error); throw new StateChangingError(Account.State.REGISTRATION_INVALID_TOKEN); } diff --git a/src/main/java/eu/siacs/conversations/xmpp/stanzas/AbstractAcknowledgeableStanza.java b/src/main/java/eu/siacs/conversations/xmpp/stanzas/AbstractAcknowledgeableStanza.java index cd087f3ab..2291a9896 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/stanzas/AbstractAcknowledgeableStanza.java +++ b/src/main/java/eu/siacs/conversations/xmpp/stanzas/AbstractAcknowledgeableStanza.java @@ -5,44 +5,38 @@ import eu.siacs.conversations.xmpp.InvalidJid; abstract public class AbstractAcknowledgeableStanza extends AbstractStanza { - protected AbstractAcknowledgeableStanza(String name) { - super(name); - } + protected AbstractAcknowledgeableStanza(String name) { + super(name); + } - public String getId() { - return this.getAttribute("id"); - } + public String getId() { + return this.getAttribute("id"); + } - public void setId(final String id) { - setAttribute("id", id); - } + public void setId(final String id) { + setAttribute("id", id); + } - public Element getError() { - Element error = findChild("error"); - if (error != null) { - for(Element element : error.getChildren()) { - if (!element.getName().equals("text")) { - return element; - } - } - } - return null; - } + private Element getErrorConditionElement() { + final Element error = findChild("error"); + if (error == null) { + return null; + } + for (final Element element : error.getChildren()) { + if (!element.getName().equals("text")) { + return element; + } + } + return null; + } - public String getErrorCondition() { - Element error = findChild("error"); - if (error != null) { - for(Element element : error.getChildren()) { - if (!element.getName().equals("text")) { - return element.getName(); - } - } - } - return null; - } + public String getErrorCondition() { + final Element condition = getErrorConditionElement(); + return condition == null ? null : condition.getName(); + } - public boolean valid() { - return InvalidJid.isValid(getFrom()) && InvalidJid.isValid(getTo()); - } + public boolean valid() { + return InvalidJid.isValid(getFrom()) && InvalidJid.isValid(getTo()); + } }