diff --git a/src/main/java/eu/siacs/conversations/entities/MucOptions.java b/src/main/java/eu/siacs/conversations/entities/MucOptions.java index f2231178e..a92cb6768 100644 --- a/src/main/java/eu/siacs/conversations/entities/MucOptions.java +++ b/src/main/java/eu/siacs/conversations/entities/MucOptions.java @@ -101,8 +101,9 @@ public class MucOptions { return tookProposedNickFromBookmark; } - void notifyOfBookmarkNick(String nick) { - if (nick != null && nick.trim().equals(getSelf().getFullJid().getResource())) { + void notifyOfBookmarkNick(final String nick) { + final String normalized = normalize(account.getJid(),nick); + if (normalized != null && normalized.equals(getSelf().getFullJid().getResource())) { this.tookProposedNickFromBookmark = true; } } @@ -389,15 +390,15 @@ public class MucOptions { private String getProposedNick() { final Bookmark bookmark = this.conversation.getBookmark(); - final String bookmarkedNick = bookmark == null ? null : bookmark.getNick(); - if (bookmarkedNick != null && !bookmarkedNick.trim().isEmpty()) { + final String bookmarkedNick = normalize(account.getJid(), bookmark == null ? null : bookmark.getNick()); + if (bookmarkedNick != null) { this.tookProposedNickFromBookmark = true; - return bookmarkedNick.trim(); + return bookmarkedNick; } else if (!conversation.getJid().isBareJid()) { return conversation.getJid().getResource(); } else { - final String displayName = account.getDisplayName(); - if (TextUtils.isEmpty(displayName)) { + final String displayName = normalize(account.getJid(), account.getDisplayName()); + if (displayName == null) { return JidHelper.localPartOrFallback(account.getJid()); } else { return displayName; @@ -405,6 +406,18 @@ public class MucOptions { } } + private static String normalize(Jid account, String nick) { + if (account == null || TextUtils.isEmpty(nick)) { + return null; + } + try { + return account.withResource(nick).getResource(); + } catch (IllegalArgumentException e) { + return null; + } + + } + public String getActualNick() { if (this.self.getName() != null) { return this.self.getName(); @@ -532,7 +545,7 @@ public class MucOptions { public Jid createJoinJid(String nick) { try { - return Jid.of(this.conversation.getJid().asBareJid().toString() + "/" + nick); + return conversation.getJid().withResource(nick); } catch (final IllegalArgumentException e) { return null; } @@ -590,6 +603,7 @@ public class MucOptions { private int resId; private int rank; + Affiliation(int rank, int resId) { this.resId = resId; this.rank = rank; @@ -632,6 +646,7 @@ public class MucOptions { private int resId; private int rank; + Role(int resId, int rank) { this.resId = resId; this.rank = rank;