From 24ca2a88fb1013a78d00fb6580853583bc6e7a7f Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Sat, 31 Aug 2019 15:41:38 +0200 Subject: do not put default nick into bookmark if none has been set before --- .../java/de/pixart/messenger/entities/MucOptions.java | 16 ++++++++++------ .../messenger/services/XmppConnectionService.java | 17 ++++++++++++----- .../pixart/messenger/ui/StartConversationActivity.java | 5 +++-- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/main/java/de/pixart/messenger/entities/MucOptions.java b/src/main/java/de/pixart/messenger/entities/MucOptions.java index d1e30062a..aedb01144 100644 --- a/src/main/java/de/pixart/messenger/entities/MucOptions.java +++ b/src/main/java/de/pixart/messenger/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/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index 5028fea28..c1d5655f5 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -3073,7 +3073,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()); } @@ -4779,10 +4785,11 @@ 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/de/pixart/messenger/ui/StartConversationActivity.java b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java index 68aa128b6..1918d73d0 100644 --- a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java +++ b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java @@ -61,6 +61,7 @@ import de.pixart.messenger.entities.Bookmark; import de.pixart.messenger.entities.Contact; import de.pixart.messenger.entities.Conversation; import de.pixart.messenger.entities.ListItem; +import de.pixart.messenger.entities.MucOptions; import de.pixart.messenger.entities.Presence; import de.pixart.messenger.services.QuickConversationsService; import de.pixart.messenger.services.XmppConnectionService; @@ -1002,8 +1003,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); -- cgit v1.2.3