anotherim/src/main/java/eu/siacs/conversations/entities/MucOptions.java

848 lines
21 KiB
Java
Raw Normal View History

2014-10-22 16:38:44 +00:00
package eu.siacs.conversations.entities;
2015-07-20 12:26:29 +00:00
import android.annotation.SuppressLint;
import android.support.annotation.NonNull;
import android.util.Log;
2015-07-20 12:26:29 +00:00
2014-10-22 16:38:44 +00:00
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
2014-10-22 16:38:44 +00:00
import java.util.List;
import java.util.Set;
2014-10-22 16:38:44 +00:00
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
import eu.siacs.conversations.utils.JidHelper;
import eu.siacs.conversations.utils.UIHelper;
2017-03-01 12:01:46 +00:00
import eu.siacs.conversations.xml.Namespace;
import eu.siacs.conversations.xmpp.chatstate.ChatState;
import eu.siacs.conversations.xmpp.forms.Data;
import eu.siacs.conversations.xmpp.forms.Field;
2015-12-03 17:18:34 +00:00
import eu.siacs.conversations.xmpp.pep.Avatar;
2018-03-05 17:30:40 +00:00
import rocks.xmpp.addr.Jid;
2014-10-22 16:38:44 +00:00
@SuppressLint("DefaultLocale")
public class MucOptions {
2016-05-27 08:35:00 +00:00
private boolean mAutoPushConfiguration = true;
2015-12-03 17:18:34 +00:00
public Account getAccount() {
return this.conversation.getAccount();
}
public void setSelf(User user) {
this.self = user;
}
public void changeAffiliation(Jid jid, Affiliation affiliation) {
User user = findUserByRealJid(jid);
synchronized (users) {
if (user != null && user.getRole() == Role.NONE) {
users.remove(user);
if (affiliation.ranks(Affiliation.MEMBER)) {
user.affiliation = affiliation;
users.add(user);
}
}
}
}
2016-05-27 08:35:00 +00:00
public void flagNoAutoPushConfiguration() {
mAutoPushConfiguration = false;
}
public boolean autoPushConfiguration() {
return mAutoPushConfiguration;
}
public boolean isSelf(Jid counterpart) {
return counterpart.equals(self.getFullJid());
}
public void resetChatState() {
synchronized (users) {
2018-03-30 06:47:37 +00:00
for (User user : users) {
user.chatState = Config.DEFAULT_CHATSTATE;
}
}
}
public enum Affiliation {
2015-01-07 14:03:29 +00:00
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) {
2015-01-07 14:03:29 +00:00
this.string = string;
this.resId = resId;
2015-01-07 14:03:29 +00:00
this.rank = rank;
}
2015-01-07 14:03:29 +00:00
private String string;
private int resId;
2015-01-07 14:03:29 +00:00
private int rank;
public int getResId() {
return resId;
}
2015-01-07 14:03:29 +00:00
@Override
public String toString() {
return this.string;
}
public boolean outranks(Affiliation affiliation) {
return rank > affiliation.rank;
}
public boolean ranks(Affiliation affiliation) {
return rank >= affiliation.rank;
}
}
public enum Role {
2018-03-30 06:47:37 +00:00
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);
Role(String string, int resId, int rank) {
2015-01-07 14:03:29 +00:00
this.string = string;
this.resId = resId;
this.rank = rank;
}
2015-01-07 14:03:29 +00:00
private String string;
private int resId;
private int rank;
public int getResId() {
return resId;
}
2015-01-07 14:03:29 +00:00
@Override
public String toString() {
return this.string;
}
public boolean ranks(Role role) {
return rank >= role.rank;
}
}
public enum Error {
NO_RESPONSE,
SERVER_NOT_FOUND,
NONE,
NICK_IN_USE,
PASSWORD_REQUIRED,
BANNED,
MEMBERS_ONLY,
KICKED,
SHUTDOWN,
INVALID_NICK,
UNKNOWN
}
2014-10-22 16:38:44 +00:00
public static final String STATUS_CODE_SELF_PRESENCE = "110";
public static final String STATUS_CODE_ROOM_CREATED = "201";
2014-10-22 16:38:44 +00:00
public static final String STATUS_CODE_BANNED = "301";
public static final String STATUS_CODE_CHANGED_NICK = "303";
2014-10-22 16:38:44 +00:00
public static final String STATUS_CODE_KICKED = "307";
public static final String STATUS_CODE_AFFILIATION_CHANGE = "321";
public static final String STATUS_CODE_LOST_MEMBERSHIP = "322";
public static final String STATUS_CODE_SHUTDOWN = "332";
2014-10-22 16:38:44 +00:00
private interface OnEventListener {
2015-12-03 17:18:34 +00:00
void onSuccess();
2015-12-03 17:18:34 +00:00
void onFailure();
}
public interface OnRenameListener extends OnEventListener {
}
2016-05-17 13:01:56 +00:00
public static class User implements Comparable<User> {
private Role role = Role.NONE;
private Affiliation affiliation = Affiliation.NONE;
private Jid realJid;
2015-12-03 17:18:34 +00:00
private Jid fullJid;
2014-10-22 16:38:44 +00:00
private long pgpKeyId = 0;
2015-12-03 17:18:34 +00:00
private Avatar avatar;
private MucOptions options;
private ChatState chatState = Config.DEFAULT_CHATSTATE;
2014-10-22 16:38:44 +00:00
2015-12-03 17:18:34 +00:00
public User(MucOptions options, Jid from) {
this.options = options;
this.fullJid = from;
2014-10-22 16:38:44 +00:00
}
2015-12-03 17:18:34 +00:00
public String getName() {
2018-03-05 17:30:40 +00:00
return fullJid == null ? null : fullJid.getResource();
2014-10-22 16:38:44 +00:00
}
public void setRealJid(Jid jid) {
2018-03-05 17:30:40 +00:00
this.realJid = jid != null ? jid.asBareJid() : null;
2014-10-22 16:38:44 +00:00
}
public Role getRole() {
2014-10-22 16:38:44 +00:00
return this.role;
}
public void setRole(String role) {
if (role == null) {
this.role = Role.NONE;
return;
}
2014-10-22 16:38:44 +00:00
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;
}
2014-10-22 16:38:44 +00:00
}
public Affiliation getAffiliation() {
2014-10-22 16:38:44 +00:00
return this.affiliation;
}
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;
2014-10-22 16:38:44 +00:00
}
}
public void setPgpKeyId(long id) {
this.pgpKeyId = id;
}
public long getPgpKeyId() {
if (this.pgpKeyId != 0) {
return this.pgpKeyId;
} else if (realJid != null) {
return getAccount().getRoster().getContact(realJid).getPgpKeyId();
} else {
return 0;
}
2014-10-22 16:38:44 +00:00
}
public Contact getContact() {
2016-05-17 13:01:56 +00:00
if (fullJid != null) {
return getAccount().getRoster().getContactFromRoster(realJid);
2018-03-30 06:47:37 +00:00
} else if (realJid != null) {
2016-05-17 13:01:56 +00:00
return getAccount().getRoster().getContact(realJid);
} else {
return null;
}
2015-12-03 17:18:34 +00:00
}
2015-12-04 20:36:48 +00:00
public boolean setAvatar(Avatar avatar) {
if (this.avatar != null && this.avatar.equals(avatar)) {
return false;
} else {
this.avatar = avatar;
return true;
}
2015-12-03 17:18:34 +00:00
}
public String getAvatar() {
return avatar == null ? null : avatar.getFilename();
}
public Account getAccount() {
return options.getAccount();
}
public Conversation getConversation() {
return options.getConversation();
}
2015-12-03 17:18:34 +00:00
public Jid getFullJid() {
return fullJid;
2014-10-22 16:38:44 +00:00
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
User user = (User) o;
if (role != user.role) return false;
if (affiliation != user.affiliation) return false;
if (realJid != null ? !realJid.equals(user.realJid) : user.realJid != null)
return false;
return fullJid != null ? fullJid.equals(user.fullJid) : user.fullJid == null;
}
public boolean isDomain() {
return realJid != null && realJid.getLocal() == null && role == Role.NONE;
}
@Override
public int hashCode() {
int result = role != null ? role.hashCode() : 0;
result = 31 * result + (affiliation != null ? affiliation.hashCode() : 0);
result = 31 * result + (realJid != null ? realJid.hashCode() : 0);
result = 31 * result + (fullJid != null ? fullJid.hashCode() : 0);
return result;
}
@Override
public String toString() {
2018-03-30 06:47:37 +00:00
return "[fulljid:" + String.valueOf(fullJid) + ",realjid:" + String.valueOf(realJid) + ",affiliation" + affiliation.toString() + "]";
}
public boolean realJidMatchesAccount() {
2018-03-05 17:30:40 +00:00
return realJid != null && realJid.equals(options.account.getJid().asBareJid());
}
2016-05-17 13:01:56 +00:00
@Override
public int compareTo(@NonNull User another) {
if (another.getAffiliation().outranks(getAffiliation())) {
return 1;
} else if (getAffiliation().outranks(another.getAffiliation())) {
return -1;
2016-05-17 13:01:56 +00:00
} else {
2016-07-04 17:30:19 +00:00
return getComparableName().compareToIgnoreCase(another.getComparableName());
}
}
private String getComparableName() {
Contact contact = getContact();
if (contact != null) {
return contact.getDisplayName();
} else {
String name = getName();
return name == null ? "" : name;
2016-05-17 13:01:56 +00:00
}
}
public Jid getRealJid() {
return realJid;
}
public boolean setChatState(ChatState chatState) {
if (this.chatState == chatState) {
return false;
}
this.chatState = chatState;
return true;
}
2014-10-22 16:38:44 +00:00
}
private Account account;
private final Set<User> users = new HashSet<>();
private ServiceDiscoveryResult serviceDiscoveryResult;
private final Conversation conversation;
2014-10-22 16:38:44 +00:00
private boolean isOnline = false;
private Error error = Error.NONE;
2015-12-03 17:18:34 +00:00
public OnRenameListener onRenameListener = null;
private User self;
2014-10-22 16:38:44 +00:00
private String password = null;
public MucOptions(Conversation conversation) {
this.account = conversation.getAccount();
this.conversation = conversation;
2018-03-30 06:47:37 +00:00
this.self = new User(this, createJoinJid(getProposedNick()));
}
public boolean updateConfiguration(ServiceDiscoveryResult serviceDiscoveryResult) {
this.serviceDiscoveryResult = serviceDiscoveryResult;
String name;
Field roomConfigName = getRoomInfoForm().getFieldByName("muc#roomconfig_roomname");
if (roomConfigName != null) {
name = roomConfigName.getValue();
} else {
List<ServiceDiscoveryResult.Identity> identities = serviceDiscoveryResult.getIdentities();
String identityName = identities.size() > 0 ? identities.get(0).getName() : null;
2018-06-27 15:17:44 +00:00
final Jid jid = conversation.getJid();
if (identityName != null && !identityName.equals(jid == null ? null : jid.getEscapedLocal())) {
name = identityName;
} else {
name = null;
}
}
boolean changed = conversation.setAttribute("muc_name", name);
2018-03-30 06:47:37 +00:00
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"));
return changed;
2014-10-22 16:38:44 +00:00
}
private Data getRoomInfoForm() {
final List<Data> forms = serviceDiscoveryResult == null ? Collections.emptyList() : serviceDiscoveryResult.forms;
return forms.size() == 0 ? new Data() : forms.get(0);
}
2018-04-14 15:54:04 +00:00
public String getAvatar() {
return account.getRoster().getContact(conversation.getJid()).getAvatar();
}
public boolean hasFeature(String feature) {
return this.serviceDiscoveryResult != null && this.serviceDiscoveryResult.features.contains(feature);
}
public boolean hasVCards() {
return hasFeature("vcard-temp");
}
public boolean canInvite() {
Field field = getRoomInfoForm().getFieldByName("muc#roomconfig_allowinvites");
return !membersOnly() || self.getRole().ranks(Role.MODERATOR) || (field != null && "1".equals(field.getValue()));
}
public boolean canChangeSubject() {
Field field = getRoomInfoForm().getFieldByName("muc#roominfo_changesubject");
return self.getRole().ranks(Role.MODERATOR) || (field != null && "1".equals(field.getValue()));
}
public boolean allowPm() {
final Field field = getRoomInfoForm().getFieldByName("muc#roomconfig_allowpm");
if (field == null) {
return true; //fall back if field does not exists
}
if ("anyone".equals(field.getValue())) {
return true;
} else if ("participants".equals(field.getValue())) {
return self.getRole().ranks(Role.PARTICIPANT);
} else if ("moderators".equals(field.getValue())) {
return self.getRole().ranks(Role.MODERATOR);
} else {
return false;
}
}
public boolean participating() {
return !online()
|| self.getRole().ranks(Role.PARTICIPANT)
|| hasFeature("muc_unmoderated");
}
public boolean membersOnly() {
2018-03-30 06:47:37 +00:00
return conversation.getBooleanAttribute(Conversation.ATTRIBUTE_MEMBERS_ONLY, false);
}
public boolean mamSupport() {
2017-03-01 12:01:46 +00:00
return hasFeature(Namespace.MAM) || hasFeature(Namespace.MAM_LEGACY);
2017-02-15 15:42:35 +00:00
}
public boolean mamLegacy() {
2017-03-01 12:01:46 +00:00
return hasFeature(Namespace.MAM_LEGACY) && !hasFeature(Namespace.MAM);
}
2015-01-08 20:29:26 +00:00
public boolean nonanonymous() {
2018-03-30 06:47:37 +00:00
return conversation.getBooleanAttribute(Conversation.ATTRIBUTE_NON_ANONYMOUS, false);
2015-01-08 20:29:26 +00:00
}
public boolean isPrivateAndNonAnonymous() {
return membersOnly() && nonanonymous();
}
public boolean moderated() {
2018-03-30 06:47:37 +00:00
return conversation.getBooleanAttribute(Conversation.ATTRIBUTE_MODERATED, false);
}
public User deleteUser(Jid jid) {
User user = findUserByFullJid(jid);
if (user != null) {
synchronized (users) {
users.remove(user);
boolean realJidInMuc = false;
for (User u : users) {
if (user.realJid != null && user.realJid.equals(u.realJid)) {
realJidInMuc = true;
break;
}
}
2018-03-05 17:30:40 +00:00
boolean self = user.realJid != null && user.realJid.equals(account.getJid().asBareJid());
if (membersOnly()
&& nonanonymous()
&& user.affiliation.ranks(Affiliation.MEMBER)
&& user.realJid != null
&& !realJidInMuc
&& !self) {
user.role = Role.NONE;
user.avatar = null;
user.fullJid = null;
users.add(user);
}
}
}
return user;
2014-10-22 16:38:44 +00:00
}
//returns true if real jid was new;
public boolean updateUser(User user) {
User old;
boolean realJidFound = false;
if (user.fullJid == null && user.realJid != null) {
old = findUserByRealJid(user.realJid);
realJidFound = old != null;
if (old != null) {
if (old.fullJid != null) {
return false; //don't add. user already exists
} else {
synchronized (users) {
users.remove(old);
}
}
}
} else if (user.realJid != null) {
old = findUserByRealJid(user.realJid);
realJidFound = old != null;
synchronized (users) {
if (old != null && old.fullJid == null) {
users.remove(old);
}
}
}
old = findUserByFullJid(user.getFullJid());
synchronized (this.users) {
if (old != null) {
users.remove(old);
}
boolean fullJidIsSelf = isOnline && user.getFullJid() != null && user.getFullJid().equals(self.getFullJid());
if ((!membersOnly() || user.getAffiliation().ranks(Affiliation.MEMBER))
&& user.getAffiliation().outranks(Affiliation.OUTCAST)
2018-03-30 06:47:37 +00:00
&& !fullJidIsSelf) {
this.users.add(user);
return !realJidFound && user.realJid != null;
}
}
return false;
}
public User findUserByFullJid(Jid jid) {
if (jid == null) {
return null;
}
synchronized (users) {
for (User user : users) {
if (jid.equals(user.getFullJid())) {
return user;
}
}
}
return null;
2014-10-22 16:38:44 +00:00
}
public User findUserByRealJid(Jid jid) {
if (jid == null) {
return null;
}
synchronized (users) {
for (User user : users) {
if (jid.equals(user.realJid)) {
return user;
}
}
}
return null;
}
public User findUser(ReadByMarker readByMarker) {
if (readByMarker.getRealJid() != null) {
2018-03-05 17:30:40 +00:00
User user = findUserByRealJid(readByMarker.getRealJid().asBareJid());
if (user == null) {
2018-03-30 06:47:37 +00:00
user = new User(this, readByMarker.getFullJid());
user.setRealJid(readByMarker.getRealJid());
}
return user;
} else if (readByMarker.getFullJid() != null) {
return findUserByFullJid(readByMarker.getFullJid());
} else {
return null;
}
}
public boolean isContactInRoom(Contact contact) {
2018-03-05 17:30:40 +00:00
return findUserByRealJid(contact.getJid().asBareJid()) != null;
}
public boolean isUserInRoom(Jid jid) {
return findUserByFullJid(jid) != null;
2015-12-03 17:18:34 +00:00
}
public void setError(Error error) {
this.isOnline = isOnline && error == Error.NONE;
this.error = error;
}
2017-12-18 12:19:11 +00:00
public boolean setOnline() {
boolean before = this.isOnline;
this.isOnline = true;
2017-12-18 12:19:11 +00:00
return !before;
}
2015-12-03 17:18:34 +00:00
public ArrayList<User> getUsers() {
return getUsers(true);
}
public ArrayList<User> getUsers(boolean includeOffline) {
synchronized (users) {
ArrayList<User> users = new ArrayList<>();
for (User user : this.users) {
if (!user.isDomain() && (includeOffline || user.getRole().ranks(Role.PARTICIPANT))) {
users.add(user);
}
}
return users;
}
2014-10-22 16:38:44 +00:00
}
2017-03-08 09:32:42 +00:00
public ArrayList<User> getUsersWithChatState(ChatState state, int max) {
synchronized (users) {
ArrayList<User> list = new ArrayList<>();
2018-03-30 06:47:37 +00:00
for (User user : users) {
if (user.chatState == state) {
list.add(user);
2017-03-08 09:32:42 +00:00
if (list.size() >= max) {
break;
}
}
}
return list;
}
}
2015-12-03 17:18:34 +00:00
public List<User> getUsers(int max) {
ArrayList<User> subset = new ArrayList<>();
HashSet<Jid> jids = new HashSet<>();
2018-03-05 17:30:40 +00:00
jids.add(account.getJid().asBareJid());
synchronized (users) {
2018-03-30 06:47:37 +00:00
for (User user : users) {
if (user.getRealJid() == null || (user.getRealJid().getLocal() != null && jids.add(user.getRealJid()))) {
subset.add(user);
}
if (subset.size() >= max) {
break;
}
}
}
return subset;
2015-12-03 17:18:34 +00:00
}
public int getUserCount() {
synchronized (users) {
return users.size();
}
2014-10-22 16:38:44 +00:00
}
private String getProposedNick() {
2014-10-22 16:38:44 +00:00
if (conversation.getBookmark() != null
2014-12-02 23:00:25 +00:00
&& conversation.getBookmark().getNick() != null
&& !conversation.getBookmark().getNick().trim().isEmpty()) {
return conversation.getBookmark().getNick().trim();
} else if (!conversation.getJid().isBareJid()) {
2018-03-05 17:30:40 +00:00
return conversation.getJid().getResource();
2014-10-22 16:38:44 +00:00
} else {
return JidHelper.localPartOrFallback(account.getJid());
2014-10-22 16:38:44 +00:00
}
}
public String getActualNick() {
if (this.self.getName() != null) {
return this.self.getName();
} else {
return this.getProposedNick();
}
}
public boolean online() {
return this.isOnline;
}
public Error getError() {
2014-10-22 16:38:44 +00:00
return this.error;
}
public void setOnRenameListener(OnRenameListener listener) {
this.onRenameListener = listener;
2014-10-22 16:38:44 +00:00
}
public void setOffline() {
synchronized (users) {
this.users.clear();
}
this.error = Error.NO_RESPONSE;
2014-10-22 16:38:44 +00:00
this.isOnline = false;
}
public User getSelf() {
return self;
}
public boolean setSubject(String subject) {
2018-03-30 06:47:37 +00:00
return this.conversation.setAttribute("subject", subject);
2014-10-22 16:38:44 +00:00
}
public String getSubject() {
return this.conversation.getAttribute("subject");
}
public String getName() {
2018-06-27 15:17:44 +00:00
return this.conversation.getAttribute("muc_name");
}
private List<User> getFallbackUsersFromCryptoTargets() {
List<User> users = new ArrayList<>();
2018-03-30 06:47:37 +00:00
for (Jid jid : conversation.getAcceptedCryptoTargets()) {
User user = new User(this, null);
user.setRealJid(jid);
users.add(user);
}
return users;
}
public List<User> getUsersRelevantForNameAndAvatar() {
final List<User> users;
if (isOnline) {
users = getUsers(5);
} else {
users = getFallbackUsersFromCryptoTargets();
}
return users;
2014-10-22 16:38:44 +00:00
}
public String createNameFromParticipants() {
List<User> users = getUsersRelevantForNameAndAvatar();
if (users.size() >= 2) {
2017-03-06 18:06:16 +00:00
StringBuilder builder = new StringBuilder();
for (User user : users) {
2017-03-06 18:06:16 +00:00
if (builder.length() != 0) {
builder.append(", ");
}
String name = UIHelper.getDisplayName(user);
if (name != null) {
builder.append(name.split("\\s+")[0]);
}
}
return builder.toString();
} else {
return null;
}
2014-10-22 16:38:44 +00:00
}
public long[] getPgpKeyIds() {
List<Long> ids = new ArrayList<>();
for (User user : this.users) {
if (user.getPgpKeyId() != 0) {
ids.add(user.getPgpKeyId());
2014-10-22 16:38:44 +00:00
}
}
ids.add(account.getPgpId());
long[] primitiveLongArray = new long[ids.size()];
2014-10-22 16:38:44 +00:00
for (int i = 0; i < ids.size(); ++i) {
primitiveLongArray[i] = ids.get(i);
2014-10-22 16:38:44 +00:00
}
return primitiveLongArray;
2014-10-22 16:38:44 +00:00
}
public boolean pgpKeysInUse() {
synchronized (users) {
for (User user : users) {
if (user.getPgpKeyId() != 0) {
return true;
}
2014-10-22 16:38:44 +00:00
}
}
return false;
}
public boolean everybodyHasKeys() {
synchronized (users) {
for (User user : users) {
if (user.getPgpKeyId() == 0) {
return false;
}
2014-10-22 16:38:44 +00:00
}
}
return true;
}
public Jid createJoinJid(String nick) {
try {
2018-03-05 17:30:40 +00:00
return Jid.of(this.conversation.getJid().asBareJid().toString() + "/" + nick);
} catch (final IllegalArgumentException e) {
return null;
}
}
2014-10-22 16:38:44 +00:00
public Jid getTrueCounterpart(Jid jid) {
if (jid.equals(getSelf().getFullJid())) {
2018-03-05 17:30:40 +00:00
return account.getJid().asBareJid();
}
User user = findUserByFullJid(jid);
return user == null ? null : user.realJid;
2014-10-22 16:38:44 +00:00
}
public String getPassword() {
this.password = conversation.getAttribute(Conversation.ATTRIBUTE_MUC_PASSWORD);
2014-10-22 16:38:44 +00:00
if (this.password == null && conversation.getBookmark() != null
&& conversation.getBookmark().getPassword() != null) {
return conversation.getBookmark().getPassword();
} else {
return this.password;
}
}
public void setPassword(String password) {
if (conversation.getBookmark() != null) {
conversation.getBookmark().setPassword(password);
} else {
this.password = password;
}
conversation.setAttribute(Conversation.ATTRIBUTE_MUC_PASSWORD, password);
2014-10-22 16:38:44 +00:00
}
public Conversation getConversation() {
return this.conversation;
}
public List<Jid> getMembers(final boolean includeDomains) {
ArrayList<Jid> members = new ArrayList<>();
synchronized (users) {
for (User user : users) {
if (user.affiliation.ranks(Affiliation.MEMBER) && user.realJid != null && (!user.isDomain() || includeDomains)) {
members.add(user.realJid);
}
}
}
return members;
}
}