normalize nicks before getting them from bookmarks or pep

This commit is contained in:
Daniel Gultsch 2019-01-19 11:42:57 +01:00
parent 14c8d4ce0d
commit dcdf340a41
1 changed files with 23 additions and 8 deletions

View File

@ -101,8 +101,9 @@ public class MucOptions {
return tookProposedNickFromBookmark; return tookProposedNickFromBookmark;
} }
void notifyOfBookmarkNick(String nick) { void notifyOfBookmarkNick(final String nick) {
if (nick != null && nick.trim().equals(getSelf().getFullJid().getResource())) { final String normalized = normalize(account.getJid(),nick);
if (normalized != null && normalized.equals(getSelf().getFullJid().getResource())) {
this.tookProposedNickFromBookmark = true; this.tookProposedNickFromBookmark = true;
} }
} }
@ -389,15 +390,15 @@ public class MucOptions {
private String getProposedNick() { private String getProposedNick() {
final Bookmark bookmark = this.conversation.getBookmark(); final Bookmark bookmark = this.conversation.getBookmark();
final String bookmarkedNick = bookmark == null ? null : bookmark.getNick(); final String bookmarkedNick = normalize(account.getJid(), bookmark == null ? null : bookmark.getNick());
if (bookmarkedNick != null && !bookmarkedNick.trim().isEmpty()) { if (bookmarkedNick != null) {
this.tookProposedNickFromBookmark = true; this.tookProposedNickFromBookmark = true;
return bookmarkedNick.trim(); return bookmarkedNick;
} else if (!conversation.getJid().isBareJid()) { } else if (!conversation.getJid().isBareJid()) {
return conversation.getJid().getResource(); return conversation.getJid().getResource();
} else { } else {
final String displayName = account.getDisplayName(); final String displayName = normalize(account.getJid(), account.getDisplayName());
if (TextUtils.isEmpty(displayName)) { if (displayName == null) {
return JidHelper.localPartOrFallback(account.getJid()); return JidHelper.localPartOrFallback(account.getJid());
} else { } else {
return displayName; 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() { public String getActualNick() {
if (this.self.getName() != null) { if (this.self.getName() != null) {
return this.self.getName(); return this.self.getName();
@ -532,7 +545,7 @@ public class MucOptions {
public Jid createJoinJid(String nick) { public Jid createJoinJid(String nick) {
try { try {
return Jid.of(this.conversation.getJid().asBareJid().toString() + "/" + nick); return conversation.getJid().withResource(nick);
} catch (final IllegalArgumentException e) { } catch (final IllegalArgumentException e) {
return null; return null;
} }
@ -590,6 +603,7 @@ public class MucOptions {
private int resId; private int resId;
private int rank; private int rank;
Affiliation(int rank, int resId) { Affiliation(int rank, int resId) {
this.resId = resId; this.resId = resId;
this.rank = rank; this.rank = rank;
@ -632,6 +646,7 @@ public class MucOptions {
private int resId; private int resId;
private int rank; private int rank;
Role(int resId, int rank) { Role(int resId, int rank) {
this.resId = resId; this.resId = resId;
this.rank = rank; this.rank = rank;