aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/entities/MucOptions.java
diff options
context:
space:
mode:
authorSam Whited <sam@samwhited.com>2014-11-05 15:55:47 -0500
committerSam Whited <sam@samwhited.com>2014-11-09 07:00:40 -0500
commit9053f4aca0c232db77dbd0a1e5b9b09bf41bec22 (patch)
treed44820f93e139f696228c6abcbac02b75a9f7c44 /src/main/java/eu/siacs/conversations/entities/MucOptions.java
parenta9908613162f753ad71ac25890fb7cc067925764 (diff)
Move a chunk of classes over to using JID objects
Diffstat (limited to 'src/main/java/eu/siacs/conversations/entities/MucOptions.java')
-rw-r--r--src/main/java/eu/siacs/conversations/entities/MucOptions.java46
1 files changed, 28 insertions, 18 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/MucOptions.java b/src/main/java/eu/siacs/conversations/entities/MucOptions.java
index d7407cd5e..f83387fc0 100644
--- a/src/main/java/eu/siacs/conversations/entities/MucOptions.java
+++ b/src/main/java/eu/siacs/conversations/entities/MucOptions.java
@@ -6,6 +6,8 @@ import java.util.concurrent.CopyOnWriteArrayList;
import eu.siacs.conversations.crypto.PgpEngine;
import eu.siacs.conversations.xml.Element;
+import eu.siacs.conversations.xmpp.jid.InvalidJidException;
+import eu.siacs.conversations.xmpp.jid.Jid;
import eu.siacs.conversations.xmpp.stanzas.PresencePacket;
import android.annotation.SuppressLint;
@@ -66,15 +68,20 @@ public class MucOptions {
public void setRole(String role) {
role = role.toLowerCase();
- if (role.equals("moderator")) {
- this.role = ROLE_MODERATOR;
- } else if (role.equals("participant")) {
- this.role = ROLE_PARTICIPANT;
- } else if (role.equals("visitor")) {
- this.role = ROLE_VISITOR;
- } else {
- this.role = ROLE_NONE;
- }
+ 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;
+ }
}
public int getAffiliation() {
@@ -109,7 +116,7 @@ public class MucOptions {
}
private Account account;
- private List<User> users = new CopyOnWriteArrayList<User>();
+ private List<User> users = new CopyOnWriteArrayList<>();
private Conversation conversation;
private boolean isOnline = false;
private int error = ERROR_ROOM_NOT_FOUND;
@@ -233,13 +240,12 @@ public class MucOptions {
}
public String getProposedNick() {
- String[] mucParts = conversation.getContactJid().split("/", 2);
if (conversation.getBookmark() != null
&& conversation.getBookmark().getNick() != null) {
return conversation.getBookmark().getNick();
} else {
- if (mucParts.length == 2) {
- return mucParts[1];
+ if (!conversation.getContactJid().getResourcepart().isEmpty()) {
+ return conversation.getContactJid().getResourcepart();
} else {
return account.getUsername();
}
@@ -297,7 +303,7 @@ public class MucOptions {
}
public long[] getPgpKeyIds() {
- List<Long> ids = new ArrayList<Long>();
+ List<Long> ids = new ArrayList<>();
for (User user : getUsers()) {
if (user.getPgpKeyId() != 0) {
ids.add(user.getPgpKeyId());
@@ -328,10 +334,14 @@ public class MucOptions {
return true;
}
- public String getJoinJid() {
- return this.conversation.getContactJid().split("/", 2)[0] + "/"
- + this.joinnick;
- }
+ public Jid getJoinJid() {
+ try {
+ return Jid.fromString(this.conversation.getContactJid().toBareJid().toString() + "/"
++ this.joinnick);
+ } catch (final InvalidJidException e) {
+ return null;
+ }
+ }
public String getTrueCounterpart(String counterpart) {
for (User user : this.getUsers()) {