reset subject and name on empty

This commit is contained in:
Christian Schneppe 2018-07-09 21:04:10 +02:00
parent b339e03c87
commit 0563821078
5 changed files with 25 additions and 14 deletions

View file

@ -9,6 +9,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import de.pixart.messenger.utils.StringUtils;
import de.pixart.messenger.utils.UIHelper;
import de.pixart.messenger.xml.Element;
import de.pixart.messenger.xmpp.InvalidJid;
@ -40,6 +41,14 @@ public class Bookmark extends Element implements ListItem {
return bookmark;
}
public static boolean printableValue(@Nullable String value, boolean permitNone) {
return value != null && !value.trim().isEmpty() && (permitNone || !"None".equals(value));
}
public static boolean printableValue(@Nullable String value) {
return printableValue(value, true);
}
public void setAutojoin(boolean autojoin) {
if (autojoin) {
this.setAttribute("autojoin", "true");
@ -68,14 +77,6 @@ public class Bookmark extends Element implements ListItem {
}
}
public static boolean printableValue(@Nullable String value, boolean permitNone) {
return value != null && !value.trim().isEmpty() && (permitNone || !"None".equals(value));
}
public static boolean printableValue(@Nullable String value) {
return printableValue(value, true);
}
@Override
public int getOffline() {
return 0;
@ -168,11 +169,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);
}
}

View file

@ -2710,7 +2710,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);
}
}
@ -2800,7 +2800,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);
}

View file

@ -53,6 +53,7 @@ import de.pixart.messenger.ui.util.MyLinkify;
import de.pixart.messenger.ui.util.SoftKeyboardUtils;
import de.pixart.messenger.utils.EmojiWrapper;
import de.pixart.messenger.utils.MenuDoubleTabUtil;
import de.pixart.messenger.utils.StringUtils;
import de.pixart.messenger.utils.StylingHelper;
import de.pixart.messenger.utils.TimeframeUtils;
import de.pixart.messenger.utils.UIHelper;
@ -406,7 +407,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);
}
}

View file

@ -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;
}
}

View file

@ -134,6 +134,11 @@ public class Element {
return this;
}
public Element removeAttribute(String name) {
this.attributes.remove(name);
return this;
}
public Element setAttributes(Hashtable<String, String> attributes) {
this.attributes = attributes;
return this;