aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/entities
diff options
context:
space:
mode:
authorSam Whited <sam@samwhited.com>2014-12-21 15:43:58 -0500
committerSam Whited <sam@samwhited.com>2014-12-22 08:19:00 -0500
commitaf7a64491fa5c514866d0f1952c034a7672bb508 (patch)
tree38e73cc693fef7462ecabffd984348a86b768ae3 /src/main/java/eu/siacs/conversations/entities
parent96569700512e9618efa18eeb277665045678e16d (diff)
Add support for XEP-0191 (Blocking command)
Fixes #791 Squash of commits: 534f25d7dae3ce6852243e28fdd0a69ac01e9463 808fdf5147f27a912a60bee39aa4bf1ddd4f43b4 1eaf8a8330710ad35ba7c368e04f909af623ae4c 31585242c2359efdcd0eeddb9745077f54dbc9eb 2e69bd0bd0286ed1e98a42f4c3421ba4d8cf524b e904fb5015bf3a1904ab941a1957edf3b1e7abd2 eebbadf3b3816bbf8fcccb763e419fed252d266f 7c5b87724ce494e5a6e8026557ed50a8fd9f23e8 b0eaaf446937794fe19cbdb4f8309c3ff83d4e42 8c652f9e8bb3512958d9ad8c6f1326505f2d98c8 ad0ea1ad948ff6f8fde7b0b10f5163dc8852032f f5d49897e0dba691ef53a0eddb9ed34d129ad442 a08fa64c505bd895b7c626cfad182380373be20b de67079113e08394a276048c31f6b21baa300829 9069f342173ba30c2b20c67529c7ff497a6a257d 0169fa79d161ee898c4b6762e207087682a952d8 8585a5bd75a5d56927fed8317729bd15fffe4dcc 0053528a078369e0b65dcf71bda251072a1299c7 e901a9c3554bd7cca193e92919b463991eadfea7 c5c78257434813c69ab9b7558bcc8f7cbe858433 e905af348d46d77bc46b5f7211527684acc02fab 13a0f9a10c7892b0f90f5fabd2f2615701b0fd66 2cfba1e24b0139839e4453b92be7e20634d150cf 58e074fb5bb44b05a8104250fccd7c024c808c1a 0d6cf98fc8eab212d798ac79b336f9b70a14f06d e23620f56b85bcab9f3b5d9ce1c01524cd9674dc d72cd2fcc8d54176c3ff53411a69b9bb4642eff3 195143dff8836623a37094a6b8fa6aa01ef31580 5f5f3caf3a1e480a99d27ee5c34ba516419c52e4 1dee3d5861c9f9c710da4cbda3688d94c622ca93 23949b8aa32c78b27bab49bb3c4f3ff588925ce1 9bf97f8ae522796e0dacb7f6fe7a7f90f86a93a1
Diffstat (limited to 'src/main/java/eu/siacs/conversations/entities')
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Account.java30
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Blockable.java11
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Bookmark.java1
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Contact.java52
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Conversation.java72
-rw-r--r--src/main/java/eu/siacs/conversations/entities/ListItem.java8
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Message.java24
-rw-r--r--src/main/java/eu/siacs/conversations/entities/MucOptions.java66
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Roster.java10
9 files changed, 171 insertions, 103 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/Account.java b/src/main/java/eu/siacs/conversations/entities/Account.java
index d90010174..d42974c68 100644
--- a/src/main/java/eu/siacs/conversations/entities/Account.java
+++ b/src/main/java/eu/siacs/conversations/entities/Account.java
@@ -11,8 +11,10 @@ import org.json.JSONException;
import org.json.JSONObject;
import java.security.interfaces.DSAPublicKey;
+import java.util.Collection;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.CopyOnWriteArraySet;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
@@ -56,7 +58,7 @@ public class Account extends AbstractEntity {
SECURITY_ERROR(true),
INCOMPATIBLE_SERVER(true);
- private boolean isError;
+ private final boolean isError;
public boolean isError() {
return this.isError;
@@ -120,6 +122,7 @@ public class Account extends AbstractEntity {
private String otrFingerprint;
private final Roster roster = new Roster(this);
private List<Bookmark> bookmarks = new CopyOnWriteArrayList<>();
+ private final Collection<Jid> blocklist = new CopyOnWriteArraySet<>();
public Account() {
this.uuid = "0";
@@ -279,7 +282,7 @@ public class Account extends AbstractEntity {
return values;
}
- public void initOtrEngine(XmppConnectionService context) {
+ public void initOtrEngine(final XmppConnectionService context) {
this.otrEngine = new OtrEngine(context, this);
}
@@ -291,7 +294,7 @@ public class Account extends AbstractEntity {
return this.xmppConnection;
}
- public void setXmppConnection(XmppConnection connection) {
+ public void setXmppConnection(final XmppConnection connection) {
this.xmppConnection = connection;
}
@@ -323,7 +326,7 @@ public class Account extends AbstractEntity {
}
}
- public void setRosterVersion(String version) {
+ public void setRosterVersion(final String version) {
this.rosterVersion = version;
}
@@ -351,7 +354,7 @@ public class Account extends AbstractEntity {
return this.bookmarks;
}
- public void setBookmarks(List<Bookmark> bookmarks) {
+ public void setBookmarks(final List<Bookmark> bookmarks) {
this.bookmarks = bookmarks;
}
@@ -399,4 +402,21 @@ public class Account extends AbstractEntity {
return "xmpp:" + this.getJid().toBareJid().toString();
}
}
+
+ public boolean isBlocked(final ListItem contact) {
+ final Jid jid = contact.getJid();
+ return jid != null && (blocklist.contains(jid.toBareJid()) || blocklist.contains(jid.toDomainJid()));
+ }
+
+ public boolean isBlocked(final Jid jid) {
+ return jid != null && blocklist.contains(jid.toBareJid());
+ }
+
+ public Collection<Jid> getBlocklist() {
+ return this.blocklist;
+ }
+
+ public void clearBlocklist() {
+ getBlocklist().clear();
+ }
}
diff --git a/src/main/java/eu/siacs/conversations/entities/Blockable.java b/src/main/java/eu/siacs/conversations/entities/Blockable.java
new file mode 100644
index 000000000..dbcd55c43
--- /dev/null
+++ b/src/main/java/eu/siacs/conversations/entities/Blockable.java
@@ -0,0 +1,11 @@
+package eu.siacs.conversations.entities;
+
+import eu.siacs.conversations.xmpp.jid.Jid;
+
+public interface Blockable {
+ public boolean isBlocked();
+ public boolean isDomainBlocked();
+ public Jid getBlockedJid();
+ public Jid getJid();
+ public Account getAccount();
+}
diff --git a/src/main/java/eu/siacs/conversations/entities/Bookmark.java b/src/main/java/eu/siacs/conversations/entities/Bookmark.java
index 209056485..f81f1a876 100644
--- a/src/main/java/eu/siacs/conversations/entities/Bookmark.java
+++ b/src/main/java/eu/siacs/conversations/entities/Bookmark.java
@@ -6,7 +6,6 @@ import java.util.Locale;
import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.xml.Element;
-import eu.siacs.conversations.xmpp.jid.InvalidJidException;
import eu.siacs.conversations.xmpp.jid.Jid;
public class Bookmark extends Element implements ListItem {
diff --git a/src/main/java/eu/siacs/conversations/entities/Contact.java b/src/main/java/eu/siacs/conversations/entities/Contact.java
index 0820504fc..af26981ee 100644
--- a/src/main/java/eu/siacs/conversations/entities/Contact.java
+++ b/src/main/java/eu/siacs/conversations/entities/Contact.java
@@ -16,7 +16,7 @@ import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
import eu.siacs.conversations.xmpp.jid.Jid;
-public class Contact implements ListItem {
+public class Contact implements ListItem, Blockable {
public static final String TABLENAME = "contacts";
public static final String SYSTEMNAME = "systemname";
@@ -47,8 +47,8 @@ public class Contact implements ListItem {
protected Account account;
public Contact(final String account, final String systemName, final String serverName,
- final Jid jid, final int subscription, final String photoUri,
- final String systemAccount, final String keys, final String avatar, final Lastseen lastseen, final String groups) {
+ final Jid jid, final int subscription, final String photoUri,
+ final String systemAccount, final String keys, final String avatar, final Lastseen lastseen, final String groups) {
this.accountUuid = account;
this.systemName = systemName;
this.serverName = serverName;
@@ -122,11 +122,10 @@ public class Contact implements ListItem {
@Override
public List<Tag> getTags() {
- ArrayList<Tag> tags = new ArrayList<Tag>();
- for (String group : getGroups()) {
+ final ArrayList<Tag> tags = new ArrayList<>();
+ for (final String group : getGroups()) {
tags.add(new Tag(group, UIHelper.getColorForName(group)));
}
- int status = getMostAvailableStatus();
switch (getMostAvailableStatus()) {
case Presences.CHAT:
case Presences.ONLINE:
@@ -142,6 +141,9 @@ public class Contact implements ListItem {
tags.add(new Tag("dnd", 0xffe51c23));
break;
}
+ if (isBlocked()) {
+ tags.add(new Tag("blocked", 0xff2e2f3b));
+ }
return tags;
}
@@ -176,7 +178,7 @@ public class Contact implements ListItem {
}
public ContentValues getContentValues() {
- ContentValues values = new ContentValues();
+ final ContentValues values = new ContentValues();
values.put(ACCOUNT, accountUuid);
values.put(SYSTEMNAME, systemName);
values.put(SERVERNAME, serverName);
@@ -213,11 +215,11 @@ public class Contact implements ListItem {
this.presences = pres;
}
- public void updatePresence(String resource, int status) {
+ public void updatePresence(final String resource, final int status) {
this.presences.updatePresence(resource, status);
}
- public void removePresence(String resource) {
+ public void removePresence(final String resource) {
this.presences.removePresence(resource);
}
@@ -337,8 +339,8 @@ public class Contact implements ListItem {
public boolean showInRoster() {
return (this.getOption(Contact.Options.IN_ROSTER) && (!this
- .getOption(Contact.Options.DIRTY_DELETE)))
- || (this.getOption(Contact.Options.DIRTY_PUSH));
+ .getOption(Contact.Options.DIRTY_DELETE)))
+ || (this.getOption(Contact.Options.DIRTY_PUSH));
}
public void parseSubscriptionFromElement(Element item) {
@@ -428,7 +430,7 @@ public class Contact implements ListItem {
if (this.keys.has("otr_fingerprints")) {
JSONArray newPrints = new JSONArray();
JSONArray oldPrints = this.keys
- .getJSONArray("otr_fingerprints");
+ .getJSONArray("otr_fingerprints");
for (int i = 0; i < oldPrints.length(); ++i) {
if (!oldPrints.getString(i).equals(fingerprint)) {
newPrints.put(oldPrints.getString(i));
@@ -457,22 +459,40 @@ public class Contact implements ListItem {
}
}
+ @Override
+ public boolean isBlocked() {
+ return getAccount().isBlocked(this);
+ }
+
+ @Override
+ public boolean isDomainBlocked() {
+ return getAccount().isBlocked(this.getJid().toDomainJid());
+ }
+
+ @Override
+ public Jid getBlockedJid() {
+ if (isDomainBlocked()) {
+ return getJid().toDomainJid();
+ } else {
+ return getJid();
+ }
+ }
+
public static class Lastseen {
public long time;
public String presence;
public Lastseen() {
- time = 0;
- presence = null;
+ this(null, 0);
}
public Lastseen(final String presence, final long time) {
- this.time = time;
this.presence = presence;
+ this.time = time;
}
}
- public class Options {
+ public final class Options {
public static final int TO = 0;
public static final int FROM = 1;
public static final int ASKING = 2;
diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java
index e8482a962..22ddd307a 100644
--- a/src/main/java/eu/siacs/conversations/entities/Conversation.java
+++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java
@@ -3,7 +3,6 @@ package eu.siacs.conversations.entities;
import android.content.ContentValues;
import android.database.Cursor;
import android.os.SystemClock;
-import android.util.Log;
import net.java.otr4j.OtrException;
import net.java.otr4j.crypto.OtrCryptoEngineImpl;
@@ -25,7 +24,7 @@ import eu.siacs.conversations.Config;
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
import eu.siacs.conversations.xmpp.jid.Jid;
-public class Conversation extends AbstractEntity {
+public class Conversation extends AbstractEntity implements Blockable {
public static final String TABLENAME = "conversations";
public static final int STATUS_AVAILABLE = 0;
@@ -105,7 +104,7 @@ public class Conversation extends AbstractEntity {
if ((message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE)
&& message.getEncryption() != Message.ENCRYPTION_PGP) {
onMessageFound.onMessageFound(message);
- }
+ }
}
}
}
@@ -117,7 +116,7 @@ public class Conversation extends AbstractEntity {
&& message.getEncryption() != Message.ENCRYPTION_PGP
&& message.getUuid().equals(uuid)) {
return message;
- }
+ }
}
}
return null;
@@ -145,7 +144,7 @@ public class Conversation extends AbstractEntity {
if ((message.getStatus() == Message.STATUS_UNSEND || message.getStatus() == Message.STATUS_WAITING)
&& (message.getEncryption() == Message.ENCRYPTION_OTR)) {
onMessageFound.onMessageFound(message);
- }
+ }
}
}
}
@@ -156,7 +155,7 @@ public class Conversation extends AbstractEntity {
if (message.getType() != Message.TYPE_IMAGE
&& message.getStatus() == Message.STATUS_UNSEND) {
onMessageFound.onMessageFound(message);
- }
+ }
}
}
}
@@ -166,21 +165,37 @@ public class Conversation extends AbstractEntity {
for (Message message : this.messages) {
if (uuid.equals(message.getUuid())
|| (message.getStatus() >= Message.STATUS_SEND && uuid
- .equals(message.getRemoteMsgId()))) {
+ .equals(message.getRemoteMsgId()))) {
return message;
- }
+ }
}
}
return null;
}
- public void populateWithMessages(List<Message> messages) {
+ public void populateWithMessages(final List<Message> messages) {
synchronized (this.messages) {
messages.clear();
messages.addAll(this.messages);
}
}
+ @Override
+ public boolean isBlocked() {
+ return getContact().isBlocked();
+ }
+
+ @Override
+ public boolean isDomainBlocked() {
+ return getContact().isDomainBlocked();
+ }
+
+ @Override
+ public Jid getBlockedJid() {
+ return getContact().getBlockedJid();
+ }
+
+
public interface OnMessageFound {
public void onMessageFound(final Message message);
}
@@ -212,8 +227,8 @@ public class Conversation extends AbstractEntity {
}
public boolean isRead() {
- return (this.messages == null) || (this.messages.size() == 0) || this.messages.get(this.messages.size() - 1).isRead();
- }
+ return (this.messages == null) || (this.messages.size() == 0) || this.messages.get(this.messages.size() - 1).isRead();
+ }
public void markRead() {
if (this.messages == null) {
@@ -239,7 +254,7 @@ public class Conversation extends AbstractEntity {
} else {
return this.messages.get(i);
}
- }
+ }
}
return null;
}
@@ -267,7 +282,7 @@ public class Conversation extends AbstractEntity {
if (generatedName != null) {
return generatedName;
} else {
- return getContactJid().getLocalpart();
+ return getJid().getLocalpart();
}
}
} else {
@@ -287,11 +302,12 @@ public class Conversation extends AbstractEntity {
return this.account.getRoster().getContact(this.contactJid);
}
- public void setAccount(Account account) {
+ public void setAccount(final Account account) {
this.account = account;
}
- public Jid getContactJid() {
+ @Override
+ public Jid getJid() {
return this.contactJid;
}
@@ -318,14 +334,14 @@ public class Conversation extends AbstractEntity {
}
public static Conversation fromCursor(Cursor cursor) {
- Jid jid;
- try {
- jid = Jid.fromString(cursor.getString(cursor.getColumnIndex(CONTACTJID)));
- } catch (final InvalidJidException e) {
- // Borked DB..
- jid = null;
- }
- return new Conversation(cursor.getString(cursor.getColumnIndex(UUID)),
+ Jid jid;
+ try {
+ jid = Jid.fromString(cursor.getString(cursor.getColumnIndex(CONTACTJID)));
+ } catch (final InvalidJidException e) {
+ // Borked DB..
+ jid = null;
+ }
+ return new Conversation(cursor.getString(cursor.getColumnIndex(UUID)),
cursor.getString(cursor.getColumnIndex(NAME)),
cursor.getString(cursor.getColumnIndex(CONTACT)),
cursor.getString(cursor.getColumnIndex(ACCOUNT)),
@@ -352,9 +368,9 @@ public class Conversation extends AbstractEntity {
if (this.otrSession != null) {
return this.otrSession;
} else {
- final SessionID sessionId = new SessionID(this.getContactJid().toBareJid().toString(),
- presence,
- "xmpp");
+ final SessionID sessionId = new SessionID(this.getJid().toBareJid().toString(),
+ presence,
+ "xmpp");
this.otrSession = new SessionImpl(sessionId, getAccount().getOtrEngine());
try {
if (sendStart) {
@@ -393,7 +409,7 @@ public class Conversation extends AbstractEntity {
} catch (OtrException e) {
this.resetOtrSession();
}
- }
+ }
}
public boolean endOtrIfNeeded() {
@@ -427,7 +443,7 @@ public class Conversation extends AbstractEntity {
return "";
}
DSAPublicKey remotePubKey = (DSAPublicKey) getOtrSession()
- .getRemotePublicKey();
+ .getRemotePublicKey();
StringBuilder builder = new StringBuilder(
new OtrCryptoEngineImpl().getFingerprint(remotePubKey));
builder.insert(8, " ");
diff --git a/src/main/java/eu/siacs/conversations/entities/ListItem.java b/src/main/java/eu/siacs/conversations/entities/ListItem.java
index db9fbc374..efc1c2b93 100644
--- a/src/main/java/eu/siacs/conversations/entities/ListItem.java
+++ b/src/main/java/eu/siacs/conversations/entities/ListItem.java
@@ -12,10 +12,10 @@ public interface ListItem extends Comparable<ListItem> {
public List<Tag> getTags();
public final class Tag {
- private String name;
- private int color;
+ private final String name;
+ private final int color;
- public Tag(String name, int color) {
+ public Tag(final String name, final int color) {
this.name = name;
this.color = color;
}
@@ -28,4 +28,6 @@ public interface ListItem extends Comparable<ListItem> {
return this.name;
}
}
+
+ public boolean match(final String needle);
}
diff --git a/src/main/java/eu/siacs/conversations/entities/Message.java b/src/main/java/eu/siacs/conversations/entities/Message.java
index 5b9371386..38e88fa4a 100644
--- a/src/main/java/eu/siacs/conversations/entities/Message.java
+++ b/src/main/java/eu/siacs/conversations/entities/Message.java
@@ -77,7 +77,7 @@ public class Message extends AbstractEntity {
public Message(Conversation conversation, String body, int encryption, int status) {
this(java.util.UUID.randomUUID().toString(),
conversation.getUuid(),
- conversation.getContactJid() == null ? null : conversation.getContactJid().toBareJid(),
+ conversation.getJid() == null ? null : conversation.getJid().toBareJid(),
null,
body,
System.currentTimeMillis(),
@@ -91,9 +91,9 @@ public class Message extends AbstractEntity {
}
private Message(final String uuid, final String conversationUUid, final Jid counterpart,
- final Jid trueCounterpart, final String body, final long timeSent,
- final int encryption, final int status, final int type, final String remoteMsgId,
- final String relativeFilePath, final String serverMsgId) {
+ final Jid trueCounterpart, final String body, final long timeSent,
+ final int encryption, final int status, final int type, final String remoteMsgId,
+ final String relativeFilePath, final String serverMsgId) {
this.uuid = uuid;
this.conversationUuid = conversationUUid;
this.counterpart = counterpart;
@@ -206,7 +206,7 @@ public class Message extends AbstractEntity {
return null;
} else {
return this.conversation.getAccount().getRoster()
- .getContactFromRoster(this.trueCounterpart);
+ .getContactFromRoster(this.trueCounterpart);
}
}
}
@@ -312,10 +312,10 @@ public class Message extends AbstractEntity {
return this.serverMsgId.equals(message.getServerMsgId());
} else {
return this.body != null
- && this.counterpart != null
- && ((this.remoteMsgId != null && this.remoteMsgId.equals(message.getRemoteMsgId()))
- || this.uuid.equals(message.getRemoteMsgId())) && this.body.equals(message.getBody())
- && this.counterpart.equals(message.getCounterpart());
+ && this.counterpart != null
+ && ((this.remoteMsgId != null && this.remoteMsgId.equals(message.getRemoteMsgId()))
+ || this.uuid.equals(message.getRemoteMsgId())) && this.body.equals(message.getBody())
+ && this.counterpart.equals(message.getCounterpart());
}
}
@@ -388,7 +388,7 @@ public class Message extends AbstractEntity {
if (!url.getProtocol().equalsIgnoreCase("http")
&& !url.getProtocol().equalsIgnoreCase("https")) {
return false;
- }
+ }
if (url.getPath() == null) {
return false;
}
@@ -402,14 +402,14 @@ public class Message extends AbstractEntity {
String[] extensionParts = filename.split("\\.");
if (extensionParts.length == 2
&& Arrays.asList(Downloadable.VALID_IMAGE_EXTENSIONS).contains(
- extensionParts[extensionParts.length - 1])) {
+ extensionParts[extensionParts.length - 1])) {
return true;
} else if (extensionParts.length == 3
&& Arrays
.asList(Downloadable.VALID_CRYPTO_EXTENSIONS)
.contains(extensionParts[extensionParts.length - 1])
&& Arrays.asList(Downloadable.VALID_IMAGE_EXTENSIONS).contains(
- extensionParts[extensionParts.length - 2])) {
+ extensionParts[extensionParts.length - 2])) {
return true;
} else {
return false;
diff --git a/src/main/java/eu/siacs/conversations/entities/MucOptions.java b/src/main/java/eu/siacs/conversations/entities/MucOptions.java
index c8706fc95..97a63532f 100644
--- a/src/main/java/eu/siacs/conversations/entities/MucOptions.java
+++ b/src/main/java/eu/siacs/conversations/entities/MucOptions.java
@@ -80,20 +80,20 @@ public class MucOptions {
public void setRole(String role) {
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;
- }
+ 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() {
@@ -164,7 +164,7 @@ public class MucOptions {
}
public void processPacket(PresencePacket packet, PgpEngine pgp) {
- final Jid from = packet.getFrom();
+ final Jid from = packet.getFrom();
if (!from.isBareJid()) {
final String name = from.getResourcepart();
final String type = packet.getAttribute("type");
@@ -179,7 +179,7 @@ public class MucOptions {
user.setAffiliation(item.getAttribute("affiliation"));
user.setRole(item.getAttribute("role"));
user.setJid(item.getAttributeAsJid("jid"));
- if (codes.contains(STATUS_CODE_SELF_PRESENCE) || packet.getFrom().equals(this.conversation.getContactJid())) {
+ if (codes.contains(STATUS_CODE_SELF_PRESENCE) || packet.getFrom().equals(this.conversation.getJid())) {
this.isOnline = true;
this.error = ERROR_NO_ERROR;
self = user;
@@ -204,14 +204,14 @@ public class MucOptions {
msg = "";
}
user.setPgpKeyId(pgp.fetchKeyId(account, msg,
- signed.getContent()));
+ signed.getContent()));
}
}
}
}
} else if (type.equals("unavailable")) {
if (codes.contains(STATUS_CODE_SELF_PRESENCE) ||
- packet.getFrom().equals(this.conversation.getContactJid())) {
+ packet.getFrom().equals(this.conversation.getJid())) {
if (codes.contains(STATUS_CODE_CHANGED_NICK)) {
this.mNickChangingInProgress = true;
} else if (codes.contains(STATUS_CODE_KICKED)) {
@@ -282,8 +282,8 @@ public class MucOptions {
&& conversation.getBookmark().getNick() != null
&& !conversation.getBookmark().getNick().isEmpty()) {
return conversation.getBookmark().getNick();
- } else if (!conversation.getContactJid().isBareJid()) {
- return conversation.getContactJid().getResourcepart();
+ } else if (!conversation.getJid().isBareJid()) {
+ return conversation.getJid().getResourcepart();
} else {
return account.getUsername();
}
@@ -334,14 +334,14 @@ public class MucOptions {
public String createNameFromParticipants() {
if (users.size() >= 2) {
List<String> names = new ArrayList<String>();
- 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());
- }
+ 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());
}
+ }
StringBuilder builder = new StringBuilder();
for (int i = 0; i < names.size(); ++i) {
builder.append(names.get(i));
@@ -388,12 +388,12 @@ public class MucOptions {
}
public Jid createJoinJid(String nick) {
- try {
- return Jid.fromString(this.conversation.getContactJid().toBareJid().toString() + "/"+nick);
- } catch (final InvalidJidException e) {
- return null;
- }
- }
+ try {
+ return Jid.fromString(this.conversation.getJid().toBareJid().toString() + "/"+nick);
+ } catch (final InvalidJidException e) {
+ return null;
+ }
+ }
public Jid getTrueCounterpart(String counterpart) {
for (User user : this.getUsers()) {
diff --git a/src/main/java/eu/siacs/conversations/entities/Roster.java b/src/main/java/eu/siacs/conversations/entities/Roster.java
index 12a89cec2..1a81a419e 100644
--- a/src/main/java/eu/siacs/conversations/entities/Roster.java
+++ b/src/main/java/eu/siacs/conversations/entities/Roster.java
@@ -7,7 +7,7 @@ import java.util.concurrent.ConcurrentHashMap;
import eu.siacs.conversations.xmpp.jid.Jid;
public class Roster {
- Account account;
+ final Account account;
final ConcurrentHashMap<String, Contact> contacts = new ConcurrentHashMap<>();
private String version = null;
@@ -19,7 +19,7 @@ public class Roster {
if (jid == null) {
return null;
}
- Contact contact = contacts.get(jid.toBareJid().toString());
+ final Contact contact = contacts.get(jid.toBareJid().toString());
if (contact != null && contact.showInRoster()) {
return contact;
} else {
@@ -32,7 +32,7 @@ public class Roster {
if (contacts.containsKey(bareJid.toString())) {
return contacts.get(bareJid.toString());
} else {
- Contact contact = new Contact(bareJid);
+ final Contact contact = new Contact(bareJid);
contact.setAccount(account);
contacts.put(bareJid.toString(), contact);
return contact;
@@ -46,13 +46,13 @@ public class Roster {
}
public void markAllAsNotInRoster() {
- for (Contact contact : getContacts()) {
+ for (final Contact contact : getContacts()) {
contact.resetOption(Contact.Options.IN_ROSTER);
}
}
public void clearSystemAccounts() {
- for (Contact contact : getContacts()) {
+ for (final Contact contact : getContacts()) {
contact.setPhotoUri(null);
contact.setSystemName(null);
contact.setSystemAccount(null);