aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/entities
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-06-29 22:22:29 +0200
committerChristian Schneppe <christian@pix-art.de>2018-06-29 22:22:29 +0200
commitd269fd47eecc7b4f34634118926a19bc084d07a4 (patch)
tree60e32019ff038b683dadb421aa6695461876fad6 /src/main/java/de/pixart/messenger/entities
parent298e5757cdfcdeacdd1d219ce314d52089fc2823 (diff)
use room name (if available and != localpart) as group name
Diffstat (limited to 'src/main/java/de/pixart/messenger/entities')
-rw-r--r--src/main/java/de/pixart/messenger/entities/Conversation.java22
-rw-r--r--src/main/java/de/pixart/messenger/entities/MucOptions.java58
2 files changed, 48 insertions, 32 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/Conversation.java b/src/main/java/de/pixart/messenger/entities/Conversation.java
index 81c3c1d95..4729eb976 100644
--- a/src/main/java/de/pixart/messenger/entities/Conversation.java
+++ b/src/main/java/de/pixart/messenger/entities/Conversation.java
@@ -60,7 +60,6 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
private static final String ATTRIBUTE_NEXT_MESSAGE_TIMESTAMP = "next_message_timestamp";
private static final String ATTRIBUTE_CRYPTO_TARGETS = "crypto_targets";
private static final String ATTRIBUTE_NEXT_ENCRYPTION = "next_encryption";
- public static final String ATTRIBUTE_ALLOW_PM = "allow_pm";
public static final String ATTRIBUTE_MEMBERS_ONLY = "members_only";
public static final String ATTRIBUTE_MODERATED = "moderated";
public static final String ATTRIBUTE_NON_ANONYMOUS = "non_anonymous";
@@ -509,10 +508,13 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
public @NonNull CharSequence getName() {
if (getMode() == MODE_MULTI) {
+ final String roomName = getMucOptions().getName();
final String subject = getMucOptions().getSubject();
final Bookmark bookmark = getBookmark();
final String bookmarkName = bookmark != null ? bookmark.getBookmarkName() : null;
- if (printableValue(subject)) {
+ if (printableValue(roomName)) {
+ return roomName;
+ } else if (printableValue(subject)) {
return subject;
} else if (printableValue(bookmarkName, false)) {
return bookmarkName;
@@ -910,10 +912,20 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
public boolean setAttribute(String key, String value) {
synchronized (this.attributes) {
try {
- this.attributes.put(key, value == null ? "" : value);
- return true;
+ if (value == null) {
+ if (this.attributes.has(key)) {
+ this.attributes.remove(key);
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ String prev = this.attributes.getString(key);
+ this.attributes.put(key, value);
+ return !value.equals(prev);
+ }
} catch (JSONException e) {
- return false;
+ throw new AssertionError(e);
}
}
}
diff --git a/src/main/java/de/pixart/messenger/entities/MucOptions.java b/src/main/java/de/pixart/messenger/entities/MucOptions.java
index eb5629b2e..ecf016c48 100644
--- a/src/main/java/de/pixart/messenger/entities/MucOptions.java
+++ b/src/main/java/de/pixart/messenger/entities/MucOptions.java
@@ -1,8 +1,10 @@
package de.pixart.messenger.entities;
import android.annotation.SuppressLint;
+import android.support.annotation.NonNull;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -322,7 +324,7 @@ public class MucOptions {
}
@Override
- public int compareTo(User another) {
+ public int compareTo(@NonNull User another) {
if (another.getAffiliation().outranks(getAffiliation())) {
return 1;
} else if (getAffiliation().outranks(another.getAffiliation())) {
@@ -358,8 +360,7 @@ public class MucOptions {
private Account account;
private final Set<User> users = new HashSet<>();
- private final List<String> features = new ArrayList<>();
- private Data form = new Data();
+ private ServiceDiscoveryResult serviceDiscoveryResult;
private final Conversation conversation;
private boolean isOnline = false;
private Error error = Error.NONE;
@@ -373,34 +374,39 @@ public class MucOptions {
this.self = new User(this, createJoinJid(getProposedNick()));
}
- public boolean updateConfiguration(List<String> features, String name, Data data) {
- updateFeatures(features);
- updateFormData(data == null ? new Data() : data);
- Field allowPmField = this.form.getFieldByName("muc#roomconfig_allowpm");
- boolean changed = false;
- changed |= conversation.setAttribute(Conversation.ATTRIBUTE_ALLOW_PM, allowPmField == null || "1".equals(allowPmField.getValue()));
+ public boolean updateConfiguration(ServiceDiscoveryResult serviceDiscoveryResult) {
+ this.serviceDiscoveryResult = serviceDiscoveryResult;
+ String name;
+ Field roomInfoName = getRoomInfoForm().getFieldByName("muc#roominfo_name");
+ if (roomInfoName != null) {
+ name = roomInfoName.getValue();
+ } else {
+ List<ServiceDiscoveryResult.Identity> identities = serviceDiscoveryResult.getIdentities();
+ String identityName = identities.size() > 0 ? identities.get(0).getName() : null;
+ if (!conversation.getJid().getEscapedLocal().equals(identityName)) {
+ name = identityName;
+ } else {
+ name = null;
+ }
+ }
+ boolean changed = conversation.setAttribute("muc_name", name);
changed |= conversation.setAttribute(Conversation.ATTRIBUTE_MEMBERS_ONLY, this.hasFeature("muc_membersonly"));
changed |= conversation.setAttribute(Conversation.ATTRIBUTE_MODERATED, this.hasFeature("muc_moderated"));
changed |= conversation.setAttribute(Conversation.ATTRIBUTE_NON_ANONYMOUS, this.hasFeature("muc_nonanonymous"));
- changed |= setName(name);
return changed;
}
- private void updateFeatures(List<String> features) {
- this.features.clear();
- this.features.addAll(features);
+ private Data getRoomInfoForm() {
+ final List<Data> forms = serviceDiscoveryResult == null ? Collections.emptyList() : serviceDiscoveryResult.forms;
+ return forms.size() == 0 ? new Data() : forms.get(0);
}
public String getAvatar() {
return account.getRoster().getContact(conversation.getJid()).getAvatar();
}
- private void updateFormData(Data form) {
- this.form = form;
- }
-
public boolean hasFeature(String feature) {
- return this.features.contains(feature);
+ return this.serviceDiscoveryResult != null && this.serviceDiscoveryResult.features.contains(feature);
}
public boolean hasVCards() {
@@ -408,17 +414,18 @@ public class MucOptions {
}
public boolean canInvite() {
- Field field = this.form.getFieldByName("muc#roomconfig_allowinvites");
+ Field field = getRoomInfoForm().getFieldByName("muc#roominfo_allowinvites");
return !membersOnly() || self.getRole().ranks(Role.MODERATOR) || (field != null && "1".equals(field.getValue()));
}
public boolean canChangeSubject() {
- Field field = this.form.getFieldByName("muc#roomconfig_changesubject");
+ Field field = getRoomInfoForm().getFieldByName("muc#roominfo_changesubject");
return self.getRole().ranks(Role.MODERATOR) || (field != null && "1".equals(field.getValue()));
}
public boolean allowPm() {
- return conversation.getBooleanAttribute(Conversation.ATTRIBUTE_ALLOW_PM, false);
+ Field field = getRoomInfoForm().getFieldByName("muc#roominfo_allowpm");
+ return field != null && "1".equals(field.getValue());
}
public boolean participating() {
@@ -693,15 +700,12 @@ public class MucOptions {
return this.conversation.getAttribute("subject");
}
- private boolean setName(String name) {
- return this.conversation.setAttribute("muc_name", name);
- }
-
public String getName() {
- return this.conversation.getAttribute("muc_name");
+ String mucName = this.conversation.getAttribute("muc_name");
+ return conversation.getJid().getEscapedLocal().equals(mucName) ? null : mucName;
}
- public List<User> getFallbackUsersFromCryptoTargets() {
+ private List<User> getFallbackUsersFromCryptoTargets() {
List<User> users = new ArrayList<>();
for (Jid jid : conversation.getAcceptedCryptoTargets()) {
User user = new User(this, null);