diff options
author | Christian Schneppe <christian@pix-art.de> | 2019-02-21 19:45:12 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2019-02-21 19:45:12 +0100 |
commit | a5019812fbdaf57096b8483778b610fd3b0d1887 (patch) | |
tree | a435332fd2188c7a37163e5f3516d9e012480f82 /src/main/java | |
parent | 485609f30cf8771b5594c951029847ee6c0b634e (diff) |
show file too large instead of generic delivery failed
Diffstat (limited to '')
3 files changed, 54 insertions, 9 deletions
diff --git a/src/main/java/de/pixart/messenger/parser/AbstractParser.java b/src/main/java/de/pixart/messenger/parser/AbstractParser.java index e0a26c18d..0b94102a5 100644 --- a/src/main/java/de/pixart/messenger/parser/AbstractParser.java +++ b/src/main/java/de/pixart/messenger/parser/AbstractParser.java @@ -2,6 +2,8 @@ package de.pixart.messenger.parser; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.List; import java.util.Locale; import de.pixart.messenger.entities.Account; @@ -126,14 +128,36 @@ public abstract class AbstractParser { public static String extractErrorMessage(Element packet) { final Element error = packet.findChild("error"); if (error != null && error.getChildren().size() > 0) { + final List<String> errorNames = orderedElementNames(error.getChildren()); final String text = error.findChildContent("text"); if (text != null && !text.trim().isEmpty()) { - return text; - } else { - return error.getChildren().get(0).getName().replace("-", " "); + return prefixError(errorNames) + text; + } else if (errorNames.size() > 0) { + return prefixError(errorNames) + errorNames.get(0).replace("-", " "); + } + } + return null; + } + + private static String prefixError(List<String> errorNames) { + if (errorNames.size() > 0) { + return errorNames.get(0) + '\u001f'; + } + return ""; + } + + private static List<String> orderedElementNames(List<Element> children) { + List<String> names = new ArrayList<>(); + for (Element child : children) { + final String name = child.getName(); + if (name != null && !name.equals("text")) { + if ("urn:ietf:params:xml:ns:xmpp-stanzas".equals(child.getNamespace())) { + names.add(name); + } else { + names.add(0, name); + } } - } else { - return null; } + return names; } } diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index 4c97fb129..5f61fbf47 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -1837,9 +1837,17 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke private void showErrorMessage(final Message message) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(R.string.error_message); - builder.setMessage(message.getErrorMessage()); + final String errorMessage = message.getErrorMessage(); + final String[] errorMessageParts = errorMessage == null ? new String[0] : errorMessage.split("\\u001f"); + final String displayError; + if (errorMessageParts.length == 2) { + displayError = errorMessageParts[1]; + } else { + displayError = errorMessage; + } + builder.setMessage(displayError); builder.setNegativeButton(R.string.copy_to_clipboard, (dialog, which) -> { - activity.copyTextToClipboard(message.getErrorMessage(), R.string.error_message); + activity.copyTextToClipboard(displayError, R.string.error_message); Toast.makeText(activity, R.string.error_message_copied_to_clipboard, Toast.LENGTH_SHORT).show(); }); builder.setPositiveButton(R.string.ok, null); diff --git a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java index 8b93793c3..10eb977a7 100644 --- a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java +++ b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java @@ -260,10 +260,23 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie if (isResendable && file.exists()) { info = getContext().getString(R.string.send_failed_resend); } else { - if (Message.ERROR_MESSAGE_CANCELLED.equals(message.getErrorMessage())) { + final String errorMessage = message.getErrorMessage(); + if (Message.ERROR_MESSAGE_CANCELLED.equals(errorMessage)) { info = getContext().getString(R.string.cancelled); } else { - info = getContext().getString(R.string.send_failed); + final String[] errorParts = errorMessage.split("\\u001f", 2); + if (errorParts.length == 2) { + switch (errorParts[0]) { + case "file-too-large": + info = getContext().getString(R.string.file_too_large); + break; + default: + info = getContext().getString(R.string.send_failed); + break; + } + } else { + info = getContext().getString(R.string.send_failed); + } } } error = true; |