2014-10-22 12:38:44 -04:00
|
|
|
package eu.siacs.conversations.entities;
|
|
|
|
|
2015-07-20 08:26:29 -04:00
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
|
2014-10-22 12:38:44 -04:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.concurrent.CopyOnWriteArrayList;
|
|
|
|
|
2015-01-05 09:06:39 -05:00
|
|
|
import eu.siacs.conversations.R;
|
2014-10-22 12:38:44 -04:00
|
|
|
import eu.siacs.conversations.crypto.PgpEngine;
|
|
|
|
import eu.siacs.conversations.xml.Element;
|
2014-11-05 15:55:47 -05:00
|
|
|
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
|
|
|
|
import eu.siacs.conversations.xmpp.jid.Jid;
|
2014-10-22 12:38:44 -04:00
|
|
|
import eu.siacs.conversations.xmpp.stanzas.PresencePacket;
|
2015-01-05 09:06:39 -05:00
|
|
|
|
2014-10-22 12:38:44 -04:00
|
|
|
@SuppressLint("DefaultLocale")
|
|
|
|
public class MucOptions {
|
2015-01-05 09:06:39 -05:00
|
|
|
|
|
|
|
public enum Affiliation {
|
2015-01-07 09:03:29 -05: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);
|
2015-01-05 09:06:39 -05:00
|
|
|
|
2015-09-13 11:13:46 -04:00
|
|
|
Affiliation(String string, int rank, int resId) {
|
2015-01-07 09:03:29 -05:00
|
|
|
this.string = string;
|
2015-01-05 09:06:39 -05:00
|
|
|
this.resId = resId;
|
2015-01-07 09:03:29 -05:00
|
|
|
this.rank = rank;
|
2015-01-05 09:06:39 -05:00
|
|
|
}
|
|
|
|
|
2015-01-07 09:03:29 -05:00
|
|
|
private String string;
|
2015-01-05 09:06:39 -05:00
|
|
|
private int resId;
|
2015-01-07 09:03:29 -05:00
|
|
|
private int rank;
|
2015-01-05 09:06:39 -05:00
|
|
|
|
|
|
|
public int getResId() {
|
|
|
|
return resId;
|
|
|
|
}
|
2015-01-07 09:03:29 -05: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;
|
|
|
|
}
|
2015-01-05 09:06:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public enum Role {
|
2015-09-13 11:13:46 -04: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);
|
2015-01-05 09:06:39 -05:00
|
|
|
|
2015-09-13 11:13:46 -04:00
|
|
|
private Role(String string, int resId, int rank) {
|
2015-01-07 09:03:29 -05:00
|
|
|
this.string = string;
|
2015-01-05 09:06:39 -05:00
|
|
|
this.resId = resId;
|
2015-09-13 11:13:46 -04:00
|
|
|
this.rank = rank;
|
2015-01-05 09:06:39 -05:00
|
|
|
}
|
|
|
|
|
2015-01-07 09:03:29 -05:00
|
|
|
private String string;
|
2015-01-05 09:06:39 -05:00
|
|
|
private int resId;
|
2015-09-13 11:13:46 -04:00
|
|
|
private int rank;
|
2015-01-05 09:06:39 -05:00
|
|
|
|
|
|
|
public int getResId() {
|
|
|
|
return resId;
|
|
|
|
}
|
2015-01-07 09:03:29 -05:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return this.string;
|
|
|
|
}
|
2015-09-13 11:13:46 -04:00
|
|
|
|
|
|
|
public boolean ranks(Role role) {
|
|
|
|
return rank >= role.rank;
|
|
|
|
}
|
2015-01-05 09:06:39 -05:00
|
|
|
}
|
|
|
|
|
2014-10-22 12:38:44 -04:00
|
|
|
public static final int ERROR_NO_ERROR = 0;
|
|
|
|
public static final int ERROR_NICK_IN_USE = 1;
|
2014-11-20 12:20:42 -05:00
|
|
|
public static final int ERROR_UNKNOWN = 2;
|
2014-10-22 12:38:44 -04:00
|
|
|
public static final int ERROR_PASSWORD_REQUIRED = 3;
|
|
|
|
public static final int ERROR_BANNED = 4;
|
|
|
|
public static final int ERROR_MEMBERS_ONLY = 5;
|
|
|
|
|
|
|
|
public static final int KICKED_FROM_ROOM = 9;
|
|
|
|
|
2015-01-07 12:34:24 -05:00
|
|
|
public static final String STATUS_CODE_ROOM_CONFIG_CHANGED = "104";
|
2014-11-20 15:31:29 -05:00
|
|
|
public static final String STATUS_CODE_SELF_PRESENCE = "110";
|
2014-10-22 12:38:44 -04:00
|
|
|
public static final String STATUS_CODE_BANNED = "301";
|
2014-11-20 15:31:29 -05:00
|
|
|
public static final String STATUS_CODE_CHANGED_NICK = "303";
|
2014-10-22 12:38:44 -04:00
|
|
|
public static final String STATUS_CODE_KICKED = "307";
|
2014-11-21 10:14:56 -05:00
|
|
|
public static final String STATUS_CODE_LOST_MEMBERSHIP = "321";
|
2014-10-22 12:38:44 -04:00
|
|
|
|
2014-11-20 12:20:42 -05:00
|
|
|
private interface OnEventListener {
|
|
|
|
public void onSuccess();
|
2015-01-05 09:06:39 -05:00
|
|
|
|
2014-11-20 12:20:42 -05:00
|
|
|
public void onFailure();
|
|
|
|
}
|
|
|
|
|
|
|
|
public interface OnRenameListener extends OnEventListener {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public interface OnJoinListener extends OnEventListener {
|
|
|
|
|
2014-10-22 12:38:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public class User {
|
2015-01-07 12:34:24 -05:00
|
|
|
private Role role = Role.NONE;
|
|
|
|
private Affiliation affiliation = Affiliation.NONE;
|
2014-10-22 12:38:44 -04:00
|
|
|
private String name;
|
2014-11-17 14:02:46 -05:00
|
|
|
private Jid jid;
|
2014-10-22 12:38:44 -04:00
|
|
|
private long pgpKeyId = 0;
|
|
|
|
|
|
|
|
public String getName() {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setName(String user) {
|
|
|
|
this.name = user;
|
|
|
|
}
|
|
|
|
|
2014-11-17 14:02:46 -05:00
|
|
|
public void setJid(Jid jid) {
|
2014-10-22 12:38:44 -04:00
|
|
|
this.jid = jid;
|
|
|
|
}
|
|
|
|
|
2014-11-17 14:02:46 -05:00
|
|
|
public Jid getJid() {
|
2014-10-22 12:38:44 -04:00
|
|
|
return this.jid;
|
|
|
|
}
|
|
|
|
|
2015-01-05 09:06:39 -05:00
|
|
|
public Role getRole() {
|
2014-10-22 12:38:44 -04:00
|
|
|
return this.role;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setRole(String role) {
|
|
|
|
role = role.toLowerCase();
|
2014-12-21 15:43:58 -05:00
|
|
|
switch (role) {
|
|
|
|
case "moderator":
|
2015-01-05 09:06:39 -05:00
|
|
|
this.role = Role.MODERATOR;
|
2014-12-21 15:43:58 -05:00
|
|
|
break;
|
|
|
|
case "participant":
|
2015-01-05 09:06:39 -05:00
|
|
|
this.role = Role.PARTICIPANT;
|
2014-12-21 15:43:58 -05:00
|
|
|
break;
|
|
|
|
case "visitor":
|
2015-01-05 09:06:39 -05:00
|
|
|
this.role = Role.VISITOR;
|
2014-12-21 15:43:58 -05:00
|
|
|
break;
|
|
|
|
default:
|
2015-01-05 09:06:39 -05:00
|
|
|
this.role = Role.NONE;
|
2014-12-21 15:43:58 -05:00
|
|
|
break;
|
|
|
|
}
|
2014-10-22 12:38:44 -04:00
|
|
|
}
|
|
|
|
|
2015-02-21 16:19:10 -05:00
|
|
|
@Override
|
|
|
|
public boolean equals(Object other) {
|
|
|
|
if (this == other) {
|
|
|
|
return true;
|
|
|
|
} else if (!(other instanceof User)) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
User o = (User) other;
|
|
|
|
return name != null && name.equals(o.name)
|
|
|
|
&& jid != null && jid.equals(o.jid)
|
|
|
|
&& affiliation == o.affiliation
|
|
|
|
&& role == o.role;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-05 09:06:39 -05:00
|
|
|
public Affiliation getAffiliation() {
|
2014-10-22 12:38:44 -04:00
|
|
|
return this.affiliation;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setAffiliation(String affiliation) {
|
2015-01-05 09:06:39 -05:00
|
|
|
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 12:38:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setPgpKeyId(long id) {
|
|
|
|
this.pgpKeyId = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getPgpKeyId() {
|
|
|
|
return this.pgpKeyId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Contact getContact() {
|
|
|
|
return account.getRoster().getContactFromRoster(getJid());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private Account account;
|
2014-11-05 15:55:47 -05:00
|
|
|
private List<User> users = new CopyOnWriteArrayList<>();
|
2015-01-07 12:34:24 -05:00
|
|
|
private List<String> features = new ArrayList<>();
|
2014-10-22 12:38:44 -04:00
|
|
|
private Conversation conversation;
|
|
|
|
private boolean isOnline = false;
|
2014-11-20 12:20:42 -05:00
|
|
|
private int error = ERROR_UNKNOWN;
|
|
|
|
private OnRenameListener onRenameListener = null;
|
|
|
|
private OnJoinListener onJoinListener = null;
|
2014-10-22 12:38:44 -04:00
|
|
|
private User self = new User();
|
|
|
|
private String subject = null;
|
|
|
|
private String password = null;
|
2014-11-20 12:20:42 -05:00
|
|
|
private boolean mNickChangingInProgress = false;
|
2014-10-22 12:38:44 -04:00
|
|
|
|
|
|
|
public MucOptions(Conversation conversation) {
|
|
|
|
this.account = conversation.getAccount();
|
|
|
|
this.conversation = conversation;
|
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:24 -05:00
|
|
|
public void updateFeatures(ArrayList<String> features) {
|
|
|
|
this.features.clear();
|
|
|
|
this.features.addAll(features);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasFeature(String feature) {
|
|
|
|
return this.features.contains(feature);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canInvite() {
|
|
|
|
return !membersOnly() || self.getAffiliation().ranks(Affiliation.ADMIN);
|
|
|
|
}
|
|
|
|
|
2015-09-13 11:13:46 -04:00
|
|
|
public boolean participating() {
|
|
|
|
return !online() || self.getRole().ranks(Role.PARTICIPANT);
|
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:24 -05:00
|
|
|
public boolean membersOnly() {
|
|
|
|
return hasFeature("muc_membersonly");
|
|
|
|
}
|
|
|
|
|
2015-01-08 15:29:26 -05:00
|
|
|
public boolean nonanonymous() {
|
|
|
|
return hasFeature("muc_nonanonymous");
|
|
|
|
}
|
|
|
|
|
2015-01-10 17:10:32 -05:00
|
|
|
public boolean persistent() {
|
|
|
|
return hasFeature("muc_persistent");
|
|
|
|
}
|
|
|
|
|
2015-09-13 11:13:46 -04:00
|
|
|
public boolean moderated() {
|
|
|
|
return hasFeature("muc_moderated");
|
|
|
|
}
|
|
|
|
|
2014-10-22 12:38:44 -04:00
|
|
|
public void deleteUser(String name) {
|
|
|
|
for (int i = 0; i < users.size(); ++i) {
|
|
|
|
if (users.get(i).getName().equals(name)) {
|
|
|
|
users.remove(i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addUser(User user) {
|
|
|
|
for (int i = 0; i < users.size(); ++i) {
|
|
|
|
if (users.get(i).getName().equals(user.getName())) {
|
|
|
|
users.set(i, user);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
users.add(user);
|
|
|
|
}
|
|
|
|
|
2015-07-22 09:57:17 -04:00
|
|
|
public boolean isUserInRoom(String name) {
|
|
|
|
for (int i = 0; i < users.size(); ++i) {
|
|
|
|
if (users.get(i).getName().equals(name)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-10-22 12:38:44 -04:00
|
|
|
public void processPacket(PresencePacket packet, PgpEngine pgp) {
|
2014-12-21 15:43:58 -05:00
|
|
|
final Jid from = packet.getFrom();
|
2014-11-06 14:10:03 -05:00
|
|
|
if (!from.isBareJid()) {
|
|
|
|
final String name = from.getResourcepart();
|
2014-11-20 12:20:42 -05:00
|
|
|
final String type = packet.getAttribute("type");
|
2015-01-05 09:06:39 -05:00
|
|
|
final Element x = packet.findChild("x", "http://jabber.org/protocol/muc#user");
|
2014-11-20 12:20:42 -05:00
|
|
|
final List<String> codes = getStatusCodes(x);
|
2014-10-22 12:38:44 -04:00
|
|
|
if (type == null) {
|
|
|
|
User user = new User();
|
2014-11-13 08:27:10 -05:00
|
|
|
if (x != null) {
|
|
|
|
Element item = x.findChild("item");
|
2015-02-27 11:04:13 -05:00
|
|
|
if (item != null && name != null) {
|
2014-11-13 08:27:10 -05:00
|
|
|
user.setName(name);
|
|
|
|
user.setAffiliation(item.getAttribute("affiliation"));
|
|
|
|
user.setRole(item.getAttribute("role"));
|
2014-11-17 14:02:46 -05:00
|
|
|
user.setJid(item.getAttributeAsJid("jid"));
|
2014-12-21 15:43:58 -05:00
|
|
|
if (codes.contains(STATUS_CODE_SELF_PRESENCE) || packet.getFrom().equals(this.conversation.getJid())) {
|
2014-11-13 08:27:10 -05:00
|
|
|
this.isOnline = true;
|
|
|
|
this.error = ERROR_NO_ERROR;
|
|
|
|
self = user;
|
2014-11-20 12:20:42 -05:00
|
|
|
if (mNickChangingInProgress) {
|
|
|
|
onRenameListener.onSuccess();
|
|
|
|
mNickChangingInProgress = false;
|
|
|
|
} else if (this.onJoinListener != null) {
|
|
|
|
this.onJoinListener.onSuccess();
|
|
|
|
this.onJoinListener = null;
|
2014-11-13 08:27:10 -05:00
|
|
|
}
|
2014-10-22 12:38:44 -04:00
|
|
|
} else {
|
2014-11-13 08:27:10 -05:00
|
|
|
addUser(user);
|
|
|
|
}
|
|
|
|
if (pgp != null) {
|
|
|
|
Element signed = packet.findChild("x", "jabber:x:signed");
|
|
|
|
if (signed != null) {
|
|
|
|
Element status = packet.findChild("status");
|
|
|
|
String msg;
|
|
|
|
if (status != null) {
|
|
|
|
msg = status.getContent();
|
|
|
|
} else {
|
|
|
|
msg = "";
|
|
|
|
}
|
|
|
|
user.setPgpKeyId(pgp.fetchKeyId(account, msg,
|
2015-01-05 09:06:39 -05:00
|
|
|
signed.getContent()));
|
2014-11-13 08:27:10 -05:00
|
|
|
}
|
2014-10-22 12:38:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-11-21 10:14:56 -05:00
|
|
|
} else if (type.equals("unavailable")) {
|
|
|
|
if (codes.contains(STATUS_CODE_SELF_PRESENCE) ||
|
2014-12-21 15:43:58 -05:00
|
|
|
packet.getFrom().equals(this.conversation.getJid())) {
|
2014-11-21 10:14:56 -05:00
|
|
|
if (codes.contains(STATUS_CODE_CHANGED_NICK)) {
|
|
|
|
this.mNickChangingInProgress = true;
|
|
|
|
} else if (codes.contains(STATUS_CODE_KICKED)) {
|
|
|
|
setError(KICKED_FROM_ROOM);
|
|
|
|
} else if (codes.contains(STATUS_CODE_BANNED)) {
|
|
|
|
setError(ERROR_BANNED);
|
|
|
|
} else if (codes.contains(STATUS_CODE_LOST_MEMBERSHIP)) {
|
|
|
|
setError(ERROR_MEMBERS_ONLY);
|
|
|
|
} else {
|
|
|
|
setError(ERROR_UNKNOWN);
|
|
|
|
}
|
2014-11-20 12:20:42 -05:00
|
|
|
} else {
|
2014-11-21 10:14:56 -05:00
|
|
|
deleteUser(name);
|
2014-10-22 12:38:44 -04:00
|
|
|
}
|
|
|
|
} else if (type.equals("error")) {
|
|
|
|
Element error = packet.findChild("error");
|
|
|
|
if (error != null && error.hasChild("conflict")) {
|
2014-11-20 12:20:42 -05:00
|
|
|
if (isOnline) {
|
|
|
|
if (onRenameListener != null) {
|
|
|
|
onRenameListener.onFailure();
|
2014-10-22 12:38:44 -04:00
|
|
|
}
|
|
|
|
} else {
|
2014-11-20 12:20:42 -05:00
|
|
|
setError(ERROR_NICK_IN_USE);
|
2014-10-22 12:38:44 -04:00
|
|
|
}
|
|
|
|
} else if (error != null && error.hasChild("not-authorized")) {
|
2014-11-20 12:20:42 -05:00
|
|
|
setError(ERROR_PASSWORD_REQUIRED);
|
2014-10-22 12:38:44 -04:00
|
|
|
} else if (error != null && error.hasChild("forbidden")) {
|
2014-11-20 12:20:42 -05:00
|
|
|
setError(ERROR_BANNED);
|
|
|
|
} else if (error != null && error.hasChild("registration-required")) {
|
|
|
|
setError(ERROR_MEMBERS_ONLY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setError(int error) {
|
|
|
|
this.isOnline = false;
|
|
|
|
this.error = error;
|
|
|
|
if (onJoinListener != null) {
|
|
|
|
onJoinListener.onFailure();
|
|
|
|
onJoinListener = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private List<String> getStatusCodes(Element x) {
|
2015-01-07 12:34:24 -05:00
|
|
|
List<String> codes = new ArrayList<>();
|
2014-11-20 12:20:42 -05:00
|
|
|
if (x != null) {
|
2015-01-05 09:06:39 -05:00
|
|
|
for (Element child : x.getChildren()) {
|
2014-11-20 12:20:42 -05:00
|
|
|
if (child.getName().equals("status")) {
|
|
|
|
String code = child.getAttribute("code");
|
2015-01-05 09:06:39 -05:00
|
|
|
if (code != null) {
|
2014-11-20 12:20:42 -05:00
|
|
|
codes.add(code);
|
|
|
|
}
|
2014-10-22 12:38:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-11-20 12:20:42 -05:00
|
|
|
return codes;
|
2014-10-22 12:38:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public List<User> getUsers() {
|
|
|
|
return this.users;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getProposedNick() {
|
|
|
|
if (conversation.getBookmark() != null
|
2014-12-02 18:00:25 -05:00
|
|
|
&& conversation.getBookmark().getNick() != null
|
|
|
|
&& !conversation.getBookmark().getNick().isEmpty()) {
|
2014-10-22 12:38:44 -04:00
|
|
|
return conversation.getBookmark().getNick();
|
2014-12-21 15:43:58 -05:00
|
|
|
} else if (!conversation.getJid().isBareJid()) {
|
|
|
|
return conversation.getJid().getResourcepart();
|
2014-10-22 12:38:44 -04:00
|
|
|
} else {
|
2014-12-02 18:00:25 -05:00
|
|
|
return account.getUsername();
|
2014-10-22 12:38:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getActualNick() {
|
|
|
|
if (this.self.getName() != null) {
|
|
|
|
return this.self.getName();
|
|
|
|
} else {
|
|
|
|
return this.getProposedNick();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean online() {
|
|
|
|
return this.isOnline;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getError() {
|
|
|
|
return this.error;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setOnRenameListener(OnRenameListener listener) {
|
2014-11-20 12:20:42 -05:00
|
|
|
this.onRenameListener = listener;
|
2014-10-22 12:38:44 -04:00
|
|
|
}
|
|
|
|
|
2014-11-20 12:20:42 -05:00
|
|
|
public void setOnJoinListener(OnJoinListener listener) {
|
|
|
|
this.onJoinListener = listener;
|
2014-10-22 12:38:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setOffline() {
|
|
|
|
this.users.clear();
|
|
|
|
this.error = 0;
|
|
|
|
this.isOnline = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public User getSelf() {
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setSubject(String content) {
|
|
|
|
this.subject = content;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getSubject() {
|
|
|
|
return this.subject;
|
|
|
|
}
|
|
|
|
|
2014-11-20 12:20:42 -05:00
|
|
|
public String createNameFromParticipants() {
|
|
|
|
if (users.size() >= 2) {
|
|
|
|
List<String> names = new ArrayList<String>();
|
2014-12-21 15:43:58 -05:00
|
|
|
for (User user : users) {
|
|
|
|
Contact contact = user.getContact();
|
|
|
|
if (contact != null && !contact.getDisplayName().isEmpty()) {
|
|
|
|
names.add(contact.getDisplayName().split("\\s+")[0]);
|
|
|
|
} else {
|
|
|
|
names.add(user.getName());
|
2014-11-20 12:20:42 -05:00
|
|
|
}
|
2014-12-21 15:43:58 -05:00
|
|
|
}
|
2014-11-20 12:20:42 -05:00
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
for (int i = 0; i < names.size(); ++i) {
|
|
|
|
builder.append(names.get(i));
|
|
|
|
if (i != names.size() - 1) {
|
|
|
|
builder.append(", ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return builder.toString();
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2014-10-22 12:38:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public long[] getPgpKeyIds() {
|
2014-11-05 15:55:47 -05:00
|
|
|
List<Long> ids = new ArrayList<>();
|
2014-10-22 12:38:44 -04:00
|
|
|
for (User user : getUsers()) {
|
|
|
|
if (user.getPgpKeyId() != 0) {
|
|
|
|
ids.add(user.getPgpKeyId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
long[] primitivLongArray = new long[ids.size()];
|
|
|
|
for (int i = 0; i < ids.size(); ++i) {
|
|
|
|
primitivLongArray[i] = ids.get(i);
|
|
|
|
}
|
|
|
|
return primitivLongArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean pgpKeysInUse() {
|
|
|
|
for (User user : getUsers()) {
|
|
|
|
if (user.getPgpKeyId() != 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean everybodyHasKeys() {
|
|
|
|
for (User user : getUsers()) {
|
|
|
|
if (user.getPgpKeyId() == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-20 12:20:42 -05:00
|
|
|
public Jid createJoinJid(String nick) {
|
2014-12-21 15:43:58 -05:00
|
|
|
try {
|
2015-01-05 09:06:39 -05:00
|
|
|
return Jid.fromString(this.conversation.getJid().toBareJid().toString() + "/" + nick);
|
2014-12-21 15:43:58 -05:00
|
|
|
} catch (final InvalidJidException e) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2014-10-22 12:38:44 -04:00
|
|
|
|
2014-11-17 14:02:46 -05:00
|
|
|
public Jid getTrueCounterpart(String counterpart) {
|
2014-10-22 12:38:44 -04:00
|
|
|
for (User user : this.getUsers()) {
|
|
|
|
if (user.getName().equals(counterpart)) {
|
|
|
|
return user.getJid();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getPassword() {
|
2014-11-20 12:20:42 -05:00
|
|
|
this.password = conversation.getAttribute(Conversation.ATTRIBUTE_MUC_PASSWORD);
|
2014-10-22 12:38:44 -04: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;
|
|
|
|
}
|
2014-11-20 12:20:42 -05:00
|
|
|
conversation.setAttribute(Conversation.ATTRIBUTE_MUC_PASSWORD, password);
|
2014-10-22 12:38:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public Conversation getConversation() {
|
|
|
|
return this.conversation;
|
|
|
|
}
|
2014-11-09 13:13:19 -05:00
|
|
|
}
|