From e8a1f069c287aff2f73d40cb2448209e00264c75 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 24 Jun 2018 16:33:15 +0200 Subject: [PATCH] reset subject and name on empty --- .../java/eu/siacs/conversations/entities/Bookmark.java | 7 ++++--- .../conversations/services/XmppConnectionService.java | 4 ++-- .../siacs/conversations/ui/ConferenceDetailsActivity.java | 3 ++- .../java/eu/siacs/conversations/utils/StringUtils.java | 4 ++++ src/main/java/eu/siacs/conversations/xml/Element.java | 5 +++++ 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Bookmark.java b/src/main/java/eu/siacs/conversations/entities/Bookmark.java index 1157d823a..748cab716 100644 --- a/src/main/java/eu/siacs/conversations/entities/Bookmark.java +++ b/src/main/java/eu/siacs/conversations/entities/Bookmark.java @@ -9,6 +9,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Locale; +import eu.siacs.conversations.utils.StringUtils; import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xmpp.InvalidJid; @@ -163,11 +164,11 @@ public class Bookmark extends Element implements ListItem { public boolean setBookmarkName(String name) { String before = getBookmarkName(); - if (name != null && !name.equals(before)) { + if (name != null) { this.setAttribute("name", name); - return true; } else { - return false; + this.removeAttribute("name"); } + return StringUtils.changed(before, name); } } diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 9584c2964..b30d31fb4 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -2462,7 +2462,7 @@ public class XmppConnectionService extends Service { } if (bookmark != null && (sameBefore || bookmark.getBookmarkName() == null)) { - if (bookmark.setBookmarkName(mucOptions.getName())) { + if (bookmark.setBookmarkName(StringUtils.nullOnEmpty(mucOptions.getName()))) { pushBookmarks(account); } } @@ -2555,7 +2555,7 @@ public class XmppConnectionService extends Service { } public void pushSubjectToConference(final Conversation conference, final String subject) { - MessagePacket packet = this.getMessageGenerator().conferenceSubject(conference, subject); + MessagePacket packet = this.getMessageGenerator().conferenceSubject(conference, StringUtils.nullOnEmpty(subject)); this.sendMessagePacket(conference.getAccount(), packet); } diff --git a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java index 8ff0b1bc5..aa66e9184 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java @@ -52,6 +52,7 @@ import eu.siacs.conversations.ui.util.MenuDoubleTabUtil; import eu.siacs.conversations.ui.util.MyLinkify; import eu.siacs.conversations.ui.util.SoftKeyboardUtils; import eu.siacs.conversations.utils.EmojiWrapper; +import eu.siacs.conversations.utils.StringUtils; import eu.siacs.conversations.utils.StylingHelper; import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.utils.XmppUri; @@ -364,7 +365,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers if (mucOptions.getSelf().getAffiliation().ranks(MucOptions.Affiliation.OWNER) && changed(mucOptions.getName(), name)) { Bundle options = new Bundle(); options.putString("muc#roomconfig_persistentroom", "1"); - options.putString("muc#roomconfig_roomname", name); + options.putString("muc#roomconfig_roomname", StringUtils.nullOnEmpty(name)); xmppConnectionService.pushConferenceConfiguration(mConversation, options, this); } } diff --git a/src/main/java/eu/siacs/conversations/utils/StringUtils.java b/src/main/java/eu/siacs/conversations/utils/StringUtils.java index 542468d18..1135560bb 100644 --- a/src/main/java/eu/siacs/conversations/utils/StringUtils.java +++ b/src/main/java/eu/siacs/conversations/utils/StringUtils.java @@ -43,4 +43,8 @@ public class StringUtils { return !equals(one, two); } + public static String nullOnEmpty(String input) { + return input == null || input.trim().isEmpty() ? null : input; + } + } diff --git a/src/main/java/eu/siacs/conversations/xml/Element.java b/src/main/java/eu/siacs/conversations/xml/Element.java index b31cef68e..0bbdbcebb 100644 --- a/src/main/java/eu/siacs/conversations/xml/Element.java +++ b/src/main/java/eu/siacs/conversations/xml/Element.java @@ -136,6 +136,11 @@ public class Element { return this; } + public Element removeAttribute(String name) { + this.attributes.remove(name); + return this; + } + public Element setAttributes(Hashtable attributes) { this.attributes = attributes; return this;