From 4c9e331e01971ad10df42b11b025fe2008c6918b Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 24 Jun 2018 16:17:20 +0200 Subject: [PATCH] save name instead of subject in bookmark --- .../conversations/parser/MessageParser.java | 6 --- .../services/XmppConnectionService.java | 19 +++++++- .../ui/ConferenceDetailsActivity.java | 11 +---- .../conversations/utils/StringUtils.java | 46 +++++++++++++++++++ 4 files changed, 66 insertions(+), 16 deletions(-) create mode 100644 src/main/java/eu/siacs/conversations/utils/StringUtils.java diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index 78844f740..ca38f404e 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -645,12 +645,6 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece if (conversation.getMucOptions().setSubject(subject)) { mXmppConnectionService.updateConversation(conversation); } - final Bookmark bookmark = conversation.getBookmark(); - if (bookmark != null && bookmark.getBookmarkName() == null) { - if (bookmark.setBookmarkName(subject)) { - mXmppConnectionService.pushBookmarks(account); - } - } mXmppConnectionService.updateConversationUi(); return; } diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 19258f34a..9584c2964 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -115,6 +115,7 @@ import eu.siacs.conversations.utils.ReplacingSerialSingleThreadExecutor; import eu.siacs.conversations.utils.ReplacingTaskManager; import eu.siacs.conversations.utils.Resolver; import eu.siacs.conversations.utils.SerialSingleThreadExecutor; +import eu.siacs.conversations.utils.StringUtils; import eu.siacs.conversations.utils.WakeLockHelper; import eu.siacs.conversations.xml.Namespace; import eu.siacs.conversations.utils.XmppUri; @@ -2450,13 +2451,29 @@ public class XmppConnectionService extends Service { @Override public void onIqPacketReceived(Account account, IqPacket packet) { if (packet.getType() == IqPacket.TYPE.RESULT) { - if (conversation.getMucOptions().updateConfiguration(new ServiceDiscoveryResult(packet))) { + + final MucOptions mucOptions = conversation.getMucOptions(); + final Bookmark bookmark = conversation.getBookmark(); + final boolean sameBefore = StringUtils.equals(bookmark == null ? null : bookmark.getBookmarkName(), mucOptions.getName()); + + if (mucOptions.updateConfiguration(new ServiceDiscoveryResult(packet))) { Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": muc configuration changed for " + conversation.getJid().asBareJid()); updateConversation(conversation); } + + if (bookmark != null && (sameBefore || bookmark.getBookmarkName() == null)) { + if (bookmark.setBookmarkName(mucOptions.getName())) { + pushBookmarks(account); + } + } + + if (callback != null) { callback.onConferenceConfigurationFetched(conversation); } + + + updateConversationUi(); } else if (packet.getType() == IqPacket.TYPE.ERROR) { if (callback != null) { diff --git a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java index 74a765b9a..8ff0b1bc5 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java @@ -58,6 +58,7 @@ import eu.siacs.conversations.utils.XmppUri; import rocks.xmpp.addr.Jid; import static eu.siacs.conversations.entities.Bookmark.printableValue; +import static eu.siacs.conversations.utils.StringUtils.changed; public class ConferenceDetailsActivity extends XmppActivity implements OnConversationUpdate, OnMucRosterUpdate, XmppConnectionService.OnAffiliationChanged, XmppConnectionService.OnRoleChanged, XmppConnectionService.OnConfigurationPushed, TextWatcher { public static final String ACTION_VIEW_MUC = "view_muc"; @@ -368,13 +369,6 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers } } - private static String blankOnNull(String input) { - return input == null ? "" : input; - } - - private static boolean changed(String one, String two) { - return !blankOnNull(one).equals(blankOnNull(two)); - } @Override protected String getShareableUri(boolean http) { @@ -558,8 +552,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers } protected void saveAsBookmark() { - xmppConnectionService.saveConversationAsBookmark(mConversation, - mConversation.getMucOptions().getSubject()); + xmppConnectionService.saveConversationAsBookmark(mConversation, mConversation.getMucOptions().getName()); } protected void deleteBookmark() { diff --git a/src/main/java/eu/siacs/conversations/utils/StringUtils.java b/src/main/java/eu/siacs/conversations/utils/StringUtils.java new file mode 100644 index 000000000..542468d18 --- /dev/null +++ b/src/main/java/eu/siacs/conversations/utils/StringUtils.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2018, Daniel Gultsch All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package eu.siacs.conversations.utils; + +public class StringUtils { + + private static String blankOnNull(String input) { + return input == null ? "" : input; + } + + public static boolean equals(String one, String two) { + return blankOnNull(one).equals(blankOnNull(two)); + } + + public static boolean changed(String one, String two) { + return !equals(one, two); + } + +}