aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2017-12-16 22:38:45 +0100
committerChristian Schneppe <christian@pix-art.de>2017-12-16 22:38:45 +0100
commitfa351734ecf1f3219f8a83603368e36636926951 (patch)
treec44891c14fa7beadf245f558ad1112f0edb15579 /src/main/java
parent090faad3743ca7134a0ce398a9d2b62d84477e86 (diff)
try to detect invalid nick (w/ emoji) in MUCs
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/de/pixart/messenger/entities/MucOptions.java1
-rw-r--r--src/main/java/de/pixart/messenger/parser/PresenceParser.java45
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationFragment.java2
3 files changed, 36 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;