show file too large instead of generic delivery failed

This commit is contained in:
Daniel Gultsch 2019-02-20 21:44:06 +01:00
parent 3fabb52293
commit d95b904b5b
4 changed files with 56 additions and 9 deletions

View file

@ -1,8 +1,11 @@
package eu.siacs.conversations.parser;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import eu.siacs.conversations.entities.Account;
@ -127,14 +130,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("-"," ");
}
} else {
return null;
}
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);
}
}
}
return names;
}
}

View file

@ -1624,9 +1624,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.confirm, null);

View file

@ -219,10 +219,23 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
}
break;
case Message.STATUS_SEND_FAILED:
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;
break;

View file

@ -855,4 +855,5 @@
<string name="no_users_hint_group_chat">This private group chat has no participants.</string>
<string name="manage_permission">Manage privileges</string>
<string name="search_participants">Search participants</string>
<string name="file_too_large">File too large</string>
</resources>