diff options
author | Christian Schneppe <christian@pix-art.de> | 2017-12-16 22:38:45 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2017-12-16 22:38:45 +0100 |
commit | fa351734ecf1f3219f8a83603368e36636926951 (patch) | |
tree | c44891c14fa7beadf245f558ad1112f0edb15579 /src/main | |
parent | 090faad3743ca7134a0ce398a9d2b62d84477e86 (diff) |
try to detect invalid nick (w/ emoji) in MUCs
Diffstat (limited to '')
4 files changed, 37 insertions, 12 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/MucOptions.java b/src/main/java/de/pixart/messenger/entities/MucOptions.java index 67c02b543..f1c3aa9e8 100644 --- a/src/main/java/de/pixart/messenger/entities/MucOptions.java +++ b/src/main/java/de/pixart/messenger/entities/MucOptions.java @@ -140,6 +140,7 @@ public class MucOptions { MEMBERS_ONLY, KICKED, SHUTDOWN, + INVALID_NICK, UNKNOWN } diff --git a/src/main/java/de/pixart/messenger/parser/PresenceParser.java b/src/main/java/de/pixart/messenger/parser/PresenceParser.java index 2bb7e6aac..f020c314a 100644 --- a/src/main/java/de/pixart/messenger/parser/PresenceParser.java +++ b/src/main/java/de/pixart/messenger/parser/PresenceParser.java @@ -70,10 +70,7 @@ public class PresenceParser extends AbstractParser implements || ((codes.isEmpty() || codes.contains(MucOptions.STATUS_CODE_ROOM_CREATED)) && jid.equals(item.getAttributeAsJid("jid")))) { mucOptions.setOnline(); mucOptions.setSelf(user); - if (mucOptions.onRenameListener != null) { - mucOptions.onRenameListener.onSuccess(); - mucOptions.onRenameListener = null; - } + invokeRenameListener(mucOptions, true); } boolean isNew = mucOptions.updateUser(user); final AxolotlService axolotlService = conversation.getAccount().getAxolotlService(); @@ -141,26 +138,50 @@ public class PresenceParser extends AbstractParser implements } } } else if (type.equals("error")) { - Element error = packet.findChild("error"); - if (error != null && error.hasChild("conflict")) { + final Element error = packet.findChild("error"); + if (error == null) { + return; + } + if (error.hasChild("conflict")) { if (mucOptions.online()) { - if (mucOptions.onRenameListener != null) { - mucOptions.onRenameListener = null; - } + invokeRenameListener(mucOptions, false); } else { mucOptions.setError(MucOptions.Error.NICK_IN_USE); } - } else if (error != null && error.hasChild("not-authorized")) { + } else if (error.hasChild("not-authorized")) { mucOptions.setError(MucOptions.Error.PASSWORD_REQUIRED); - } else if (error != null && error.hasChild("forbidden")) { + } else if (error.hasChild("forbidden")) { mucOptions.setError(MucOptions.Error.BANNED); - } else if (error != null && error.hasChild("registration-required")) { + } else if (error.hasChild("registration-required")) { mucOptions.setError(MucOptions.Error.MEMBERS_ONLY); + } else { + final String text = error.findChildContent("text"); + if (text != null && text.contains("attribute 'to'")) { + if (mucOptions.online()) { + invokeRenameListener(mucOptions, false); + } else { + mucOptions.setError(MucOptions.Error.INVALID_NICK); + } + } else { + mucOptions.setError(MucOptions.Error.UNKNOWN); + Log.d(Config.LOGTAG, "unknown error in conference: " + packet); + } } } } } + private static void invokeRenameListener(final MucOptions options, boolean success) { + if (options.onRenameListener != null) { + if (success) { + options.onRenameListener.onSuccess(); + } else { + options.onRenameListener.onFailure(); + } + options.onRenameListener = null; + } + } + private static List<String> getStatusCodes(Element x) { List<String> codes = new ArrayList<>(); if (x != null) { diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index 5413dcf6f..c37c5cee7 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -1144,6 +1144,8 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa activity.xmppConnectionService.joinMuc(conversation); //showSnackbar(R.string.conference_unknown_error, R.string.try_again, joinMuc); break; + case INVALID_NICK: + showSnackbar(R.string.invalid_muc_nick, R.string.edit, clickToMuc); case SHUTDOWN: showSnackbar(R.string.conference_shutdown, R.string.try_again, joinMuc); break; diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 05420f06e..84e4e0d51 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -746,4 +746,5 @@ <string name="pref_warn_unencrypted_chat_summary">If message encryption is available, you should use it. If you don\'t use message encryption, show a warning message inside the chat.</string> <string name="pref_use_bundled_emoji">Use integrated emojis</string> <string name="pref_use_bundled_emoji_summary">Use the integrated emoji library instead of using your devices ones. Changes will be available after reopening the app.</string> + <string name="invalid_muc_nick">Invalid nickname</string> </resources> |