From f11adf4c0204653e35d098e148034923f4308f6f Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 19 Aug 2019 13:55:52 +0200 Subject: [PATCH] do not put default nick into bookmark if none has been set before --- .../conversations/entities/MucOptions.java | 16 ++++++++++------ .../services/XmppConnectionService.java | 19 +++++++++++++------ .../ui/StartConversationActivity.java | 5 +++-- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/MucOptions.java b/src/main/java/eu/siacs/conversations/entities/MucOptions.java index 62777f194..a70c67198 100644 --- a/src/main/java/eu/siacs/conversations/entities/MucOptions.java +++ b/src/main/java/eu/siacs/conversations/entities/MucOptions.java @@ -426,12 +426,16 @@ public class MucOptions { } else if (!conversation.getJid().isBareJid()) { return conversation.getJid().getResource(); } else { - final String displayName = normalize(account.getJid(), account.getDisplayName()); - if (displayName == null) { - return JidHelper.localPartOrFallback(account.getJid()); - } else { - return displayName; - } + return defaultNick(account); + } + } + + public static String defaultNick(final Account account) { + final String displayName = normalize(account.getJid(), account.getDisplayName()); + if (displayName == null) { + return JidHelper.localPartOrFallback(account.getJid()); + } else { + return displayName; } } diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index ded2ab3c7..e18ae32fb 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -2801,7 +2801,13 @@ public class XmppConnectionService extends Service { final Bookmark bookmark = conversation.getBookmark(); final String bookmarkedNick = bookmark == null ? null : bookmark.getNick(); if (bookmark != null && (tookProposedNickFromBookmark || TextUtils.isEmpty(bookmarkedNick)) && !full.getResource().equals(bookmarkedNick)) { - Log.d(Config.LOGTAG, conversation.getAccount().getJid().asBareJid() + ": persist nick '" + full.getResource() + "' into bookmark for " + conversation.getJid().asBareJid()); + final Account account = conversation.getAccount(); + final String defaultNick = MucOptions.defaultNick(account); + if (TextUtils.isEmpty(bookmarkedNick) && full.getResource().equals(defaultNick)) { + Log.d(Config.LOGTAG,account.getJid().asBareJid()+": do not overwrite empty bookmark nick with default nick for "+conversation.getJid().asBareJid()); + return; + } + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": persist nick '" + full.getResource() + "' into bookmark for " + conversation.getJid().asBareJid()); bookmark.setNick(full.getResource()); pushBookmarks(bookmark.getAccount()); } @@ -4420,11 +4426,12 @@ public class XmppConnectionService extends Service { } public void saveConversationAsBookmark(Conversation conversation, String name) { - Account account = conversation.getAccount(); - Bookmark bookmark = new Bookmark(account, conversation.getJid().asBareJid()); - if (!conversation.getJid().isBareJid()) { - bookmark.setNick(conversation.getJid().getResource()); - } + final Account account = conversation.getAccount(); + final Bookmark bookmark = new Bookmark(account, conversation.getJid().asBareJid()); + final String nick = conversation.getJid().getResource(); + if (nick != null && !nick.isEmpty() && !nick.equals(MucOptions.defaultNick(account))) { + bookmark.setNick(nick); + } if (!TextUtils.isEmpty(name)) { bookmark.setBookmarkName(name); } diff --git a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java index a48dd230b..4de40206c 100644 --- a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java @@ -62,6 +62,7 @@ import eu.siacs.conversations.entities.Bookmark; import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.ListItem; +import eu.siacs.conversations.entities.MucOptions; import eu.siacs.conversations.entities.Presence; import eu.siacs.conversations.services.QuickConversationsService; import eu.siacs.conversations.services.XmppConnectionService; @@ -1021,8 +1022,8 @@ public class StartConversationActivity extends XmppActivity implements XmppConne } else { final Bookmark bookmark = new Bookmark(account, conferenceJid.asBareJid()); bookmark.setAutojoin(getBooleanPreference("autojoin", R.bool.autojoin)); - String nick = conferenceJid.getResource(); - if (nick != null && !nick.isEmpty()) { + final String nick = conferenceJid.getResource(); + if (nick != null && !nick.isEmpty() && !nick.equals(MucOptions.defaultNick(account))) { bookmark.setNick(nick); } account.getBookmarks().add(bookmark);