aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/entities/MucOptions.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/pixart/messenger/entities/MucOptions.java')
-rw-r--r--src/main/java/de/pixart/messenger/entities/MucOptions.java133
1 files changed, 59 insertions, 74 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/MucOptions.java b/src/main/java/de/pixart/messenger/entities/MucOptions.java
index 2ef23882f..774620707 100644
--- a/src/main/java/de/pixart/messenger/entities/MucOptions.java
+++ b/src/main/java/de/pixart/messenger/entities/MucOptions.java
@@ -2,18 +2,19 @@ package de.pixart.messenger.entities;
import android.annotation.SuppressLint;
import android.support.annotation.NonNull;
-import android.util.Log;
+import android.support.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
+import java.util.Locale;
import java.util.Set;
import de.pixart.messenger.Config;
import de.pixart.messenger.R;
+import de.pixart.messenger.services.MessageArchiveService;
import de.pixart.messenger.utils.JidHelper;
-import de.pixart.messenger.utils.Namespace;
import de.pixart.messenger.utils.UIHelper;
import de.pixart.messenger.xmpp.chatstate.ChatState;
import de.pixart.messenger.xmpp.forms.Data;
@@ -30,8 +31,11 @@ public class MucOptions {
return this.conversation.getAccount();
}
- public void setSelf(User user) {
+ public boolean setSelf(User user) {
this.self = user;
+ final boolean roleChanged = this.conversation.setAttribute("role", user.role.toString());
+ final boolean affiliationChanged = this.conversation.setAttribute("affiliation", user.affiliation.toString());
+ return roleChanged || affiliationChanged;
}
public void changeAffiliation(Jid jid, Affiliation affiliation) {
@@ -67,20 +71,22 @@ public class MucOptions {
}
}
+ public boolean mamSupport() {
+ return MessageArchiveService.Version.has(getFeatures());
+ }
+
public enum Affiliation {
- OWNER("owner", 4, R.string.owner),
- ADMIN("admin", 3, R.string.admin),
- MEMBER("member", 2, R.string.member),
- OUTCAST("outcast", 0, R.string.outcast),
- NONE("none", 1, R.string.no_affiliation);
-
- Affiliation(String string, int rank, int resId) {
- this.string = string;
+ OWNER(4, R.string.owner),
+ ADMIN(3, R.string.admin),
+ MEMBER(2, R.string.member),
+ OUTCAST(0, R.string.outcast),
+ NONE(1, R.string.no_affiliation);
+
+ Affiliation(int rank, int resId) {
this.resId = resId;
this.rank = rank;
}
- private String string;
private int resId;
private int rank;
@@ -90,7 +96,7 @@ public class MucOptions {
@Override
public String toString() {
- return this.string;
+ return name().toLowerCase(Locale.US);
}
public boolean outranks(Affiliation affiliation) {
@@ -100,21 +106,30 @@ public class MucOptions {
public boolean ranks(Affiliation affiliation) {
return rank >= affiliation.rank;
}
+
+ public static Affiliation of(@Nullable String value) {
+ if (value == null) {
+ return NONE;
+ }
+ try {
+ return Affiliation.valueOf(value.toUpperCase(Locale.US));
+ } catch (IllegalArgumentException e) {
+ return NONE;
+ }
+ }
}
public enum Role {
- MODERATOR("moderator", R.string.moderator, 3),
- VISITOR("visitor", R.string.visitor, 1),
- PARTICIPANT("participant", R.string.participant, 2),
- NONE("none", R.string.no_role, 0);
+ MODERATOR(R.string.moderator, 3),
+ VISITOR(R.string.visitor, 1),
+ PARTICIPANT(R.string.participant, 2),
+ NONE(R.string.no_role, 0);
- Role(String string, int resId, int rank) {
- this.string = string;
+ Role(int resId, int rank) {
this.resId = resId;
this.rank = rank;
}
- private String string;
private int resId;
private int rank;
@@ -124,12 +139,23 @@ public class MucOptions {
@Override
public String toString() {
- return this.string;
+ return name().toLowerCase(Locale.US);
}
public boolean ranks(Role role) {
return rank >= role.rank;
}
+
+ public static Role of(@Nullable String value) {
+ if (value == null) {
+ return NONE;
+ }
+ try {
+ return Role.valueOf(value.toUpperCase(Locale.US));
+ } catch (IllegalArgumentException e) {
+ return NONE;
+ }
+ }
}
public enum Error {
@@ -140,8 +166,10 @@ public class MucOptions {
PASSWORD_REQUIRED,
BANNED,
MEMBERS_ONLY,
+ RESOURCE_CONSTRAINT,
KICKED,
SHUTDOWN,
+ DESTROYED,
INVALID_NICK,
UNKNOWN
}
@@ -193,25 +221,7 @@ public class MucOptions {
}
public void setRole(String role) {
- if (role == null) {
- this.role = Role.NONE;
- return;
- }
- role = role.toLowerCase();
- switch (role) {
- case "moderator":
- this.role = Role.MODERATOR;
- break;
- case "participant":
- this.role = Role.PARTICIPANT;
- break;
- case "visitor":
- this.role = Role.VISITOR;
- break;
- default:
- this.role = Role.NONE;
- break;
- }
+ this.role = Role.of(role);
}
public Affiliation getAffiliation() {
@@ -219,27 +229,7 @@ public class MucOptions {
}
public void setAffiliation(String affiliation) {
- if (affiliation == null) {
- this.affiliation = Affiliation.NONE;
- return;
- }
- affiliation = affiliation.toLowerCase();
- switch (affiliation) {
- case "admin":
- this.affiliation = Affiliation.ADMIN;
- break;
- case "owner":
- this.affiliation = Affiliation.OWNER;
- break;
- case "member":
- this.affiliation = Affiliation.MEMBER;
- break;
- case "outcast":
- this.affiliation = Affiliation.OUTCAST;
- break;
- default:
- this.affiliation = Affiliation.NONE;
- }
+ this.affiliation = Affiliation.of(affiliation);
}
public void setPgpKeyId(long id) {
@@ -377,6 +367,8 @@ public class MucOptions {
this.account = conversation.getAccount();
this.conversation = conversation;
this.self = new User(this, createJoinJid(getProposedNick()));
+ this.self.affiliation = Affiliation.of(conversation.getAttribute("affiliation"));
+ this.self.role = Role.of(conversation.getAttribute("role"));
}
public boolean updateConfiguration(ServiceDiscoveryResult serviceDiscoveryResult) {
@@ -384,12 +376,12 @@ public class MucOptions {
String name;
Field roomConfigName = getRoomInfoForm().getFieldByName("muc#roomconfig_roomname");
if (roomConfigName != null) {
- Log.d(Config.LOGTAG, "value of room config name " + roomConfigName.getValue());
name = roomConfigName.getValue();
} else {
List<ServiceDiscoveryResult.Identity> identities = serviceDiscoveryResult.getIdentities();
String identityName = identities.size() > 0 ? identities.get(0).getName() : null;
- if (!conversation.getJid().getEscapedLocal().equals(identityName)) {
+ final Jid jid = conversation.getJid();
+ if (identityName != null && !identityName.equals(jid == null ? null : jid.getEscapedLocal())) {
name = identityName;
} else {
name = null;
@@ -446,21 +438,15 @@ public class MucOptions {
}
public boolean participating() {
- return !online()
- || self.getRole().ranks(Role.PARTICIPANT)
- || hasFeature("muc_unmoderated");
+ return self.getRole().ranks(Role.PARTICIPANT) || !moderated();
}
public boolean membersOnly() {
return conversation.getBooleanAttribute(Conversation.ATTRIBUTE_MEMBERS_ONLY, false);
}
- public boolean mamSupport() {
- return hasFeature(Namespace.MAM) || hasFeature(Namespace.MAM_LEGACY);
- }
-
- public boolean mamLegacy() {
- return hasFeature(Namespace.MAM_LEGACY) && !hasFeature(Namespace.MAM);
+ public List<String> getFeatures() {
+ return this.serviceDiscoveryResult != null ? this.serviceDiscoveryResult.features : Collections.emptyList();
}
public boolean nonanonymous() {
@@ -714,8 +700,7 @@ public class MucOptions {
}
public String getName() {
- String mucName = this.conversation.getAttribute("muc_name");
- return conversation.getJid().getEscapedLocal().equals(mucName) ? null : mucName;
+ return this.conversation.getAttribute("muc_name");
}
private List<User> getFallbackUsersFromCryptoTargets() {