aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/entities
diff options
context:
space:
mode:
authorlookshe <github@lookshe.org>2016-03-08 10:49:47 +0100
committerlookshe <github@lookshe.org>2016-03-08 10:49:47 +0100
commit2b86b686c52c3d82ad01a8ff81c5766d64050b62 (patch)
treead7cfd62d79e06fea673bf601c9f0823842559ce /src/main/java/eu/siacs/conversations/entities
parentf767a068423c50dde60bf570d6a05683ed6d76d7 (diff)
parent1e75283250aee20b0fd2a73b7b3407801391f953 (diff)
Merge tag '1.11.0' into trz/merge_1.11.0
Conflicts: README.md build.gradle src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java src/main/java/eu/siacs/conversations/entities/Conversation.java src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java src/main/java/eu/siacs/conversations/parser/MessageParser.java src/main/java/eu/siacs/conversations/ui/ConversationActivity.java src/main/java/eu/siacs/conversations/ui/ConversationFragment.java src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java src/main/java/eu/siacs/conversations/ui/SettingsActivity.java src/main/java/eu/siacs/conversations/ui/XmppActivity.java src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java src/main/res/values-bg/strings.xml src/main/res/values-de/strings.xml src/main/res/values-es/strings.xml src/main/res/values-fr/strings.xml src/main/res/values-it/strings.xml src/main/res/values-nl/strings.xml src/main/res/values-pl/strings.xml src/main/res/values-ro-rRO/strings.xml src/main/res/values-sr/strings.xml src/main/res/values-sv/strings.xml src/main/res/values-tr-rTR/strings.xml src/main/res/values-zh-rCN/strings.xml src/main/res/values/strings.xml
Diffstat (limited to 'src/main/java/eu/siacs/conversations/entities')
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Conversation.java92
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Message.java24
-rw-r--r--src/main/java/eu/siacs/conversations/entities/MucOptions.java13
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Roster.java16
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Transferable.java9
5 files changed, 118 insertions, 36 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java
index ad7dbc55..75477d3e 100644
--- a/src/main/java/eu/siacs/conversations/entities/Conversation.java
+++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java
@@ -9,11 +9,13 @@ import net.java.otr4j.session.SessionID;
import net.java.otr4j.session.SessionImpl;
import net.java.otr4j.session.SessionStatus;
+import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.security.interfaces.DSAPublicKey;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
@@ -50,6 +52,7 @@ public class Conversation extends AbstractEntity implements Blockable {
public static final String ATTRIBUTE_MUC_PASSWORD = "muc_password";
public static final String ATTRIBUTE_MUTED_TILL = "muted_till";
public static final String ATTRIBUTE_ALWAYS_NOTIFY = "always_notify";
+ public static final String ATTRIBUTE_CRYPTO_TARGETS = "crypto_targets";
private String name;
private String contactUuid;
@@ -307,6 +310,18 @@ public class Conversation extends AbstractEntity implements Blockable {
return this.mFirstMamReference;
}
+ public List<Jid> getAcceptedCryptoTargets() {
+ if (mode == MODE_SINGLE) {
+ return Arrays.asList(getJid().toBareJid());
+ } else {
+ return getJidListAttribute(ATTRIBUTE_CRYPTO_TARGETS);
+ }
+ }
+
+ public void setAcceptedCryptoTargets(List<Jid> acceptedTargets) {
+ setAttribute(ATTRIBUTE_CRYPTO_TARGETS, acceptedTargets);
+ }
+
public void setCorrectingMessage(Message correctingMessage) {
this.correctingMessage = correctingMessage;
}
@@ -653,8 +668,8 @@ public class Conversation extends AbstractEntity implements Blockable {
final AxolotlService axolotlService = getAccount().getAxolotlService();
int next = this.getIntAttribute(ATTRIBUTE_NEXT_ENCRYPTION, -1);
if (next == -1) {
- if (Config.X509_VERIFICATION && mode == MODE_SINGLE) {
- if (axolotlService != null && axolotlService.isContactAxolotlCapable(getContact())) {
+ if (Config.X509_VERIFICATION) {
+ if (axolotlService != null && axolotlService.isConversationAxolotlCapable(this)) {
return Message.ENCRYPTION_AXOLOTL;
} else {
return Message.ENCRYPTION_NONE;
@@ -667,16 +682,20 @@ public class Conversation extends AbstractEntity implements Blockable {
next = outgoing;
}
}
- if (!Config.supportUnencrypted()
- && (mode == MODE_SINGLE || Config.supportOpenPgpOnly())
- && next <= 0) {
- if (Config.supportOmemo() && (axolotlService != null && axolotlService.isContactAxolotlCapable(getContact()) || !Config.multipleEncryptionChoices())) {
+
+ if (!Config.supportUnencrypted() && next <= 0) {
+ if (Config.supportOmemo()
+ && (axolotlService != null && axolotlService.isConversationAxolotlCapable(this) || !Config.multipleEncryptionChoices())) {
return Message.ENCRYPTION_AXOLOTL;
- } else if (Config.supportOtr()) {
+ } else if (Config.supportOtr() && mode == MODE_SINGLE) {
return Message.ENCRYPTION_OTR;
- } else if (Config.supportOpenPgp()) {
+ } else if (Config.supportOpenPgp()
+ && (mode == MODE_SINGLE) || !Config.multipleEncryptionChoices()) {
return Message.ENCRYPTION_PGP;
}
+ } else if (next == Message.ENCRYPTION_AXOLOTL
+ && (!Config.supportOmemo() || axolotlService == null || !axolotlService.isConversationAxolotlCapable(this))) {
+ next = Message.ENCRYPTION_NONE;
}
return next;
}
@@ -780,20 +799,59 @@ public class Conversation extends AbstractEntity implements Blockable {
}
public boolean setAttribute(String key, String value) {
- try {
- this.attributes.put(key, value);
- return true;
- } catch (JSONException e) {
- return false;
+ synchronized (this.attributes) {
+ try {
+ this.attributes.put(key, value);
+ return true;
+ } catch (JSONException e) {
+ return false;
+ }
+ }
+ }
+
+ public boolean setAttribute(String key, List<Jid> jids) {
+ JSONArray array = new JSONArray();
+ for(Jid jid : jids) {
+ array.put(jid.toBareJid().toString());
+ }
+ synchronized (this.attributes) {
+ try {
+ this.attributes.put(key, array);
+ return true;
+ } catch (JSONException e) {
+ e.printStackTrace();
+ return false;
+ }
}
}
public String getAttribute(String key) {
- try {
- return this.attributes.getString(key);
- } catch (JSONException e) {
- return null;
+ synchronized (this.attributes) {
+ try {
+ return this.attributes.getString(key);
+ } catch (JSONException e) {
+ return null;
+ }
+ }
+ }
+
+ public List<Jid> getJidListAttribute(String key) {
+ ArrayList<Jid> list = new ArrayList<>();
+ synchronized (this.attributes) {
+ try {
+ JSONArray array = this.attributes.getJSONArray(key);
+ for (int i = 0; i < array.length(); ++i) {
+ try {
+ list.add(Jid.fromString(array.getString(i)));
+ } catch (InvalidJidException e) {
+ //ignored
+ }
+ }
+ } catch (JSONException e) {
+ //ignored
+ }
}
+ return list;
}
public int getIntAttribute(String key, int defaultValue) {
diff --git a/src/main/java/eu/siacs/conversations/entities/Message.java b/src/main/java/eu/siacs/conversations/entities/Message.java
index 60f0d267..599afc93 100644
--- a/src/main/java/eu/siacs/conversations/entities/Message.java
+++ b/src/main/java/eu/siacs/conversations/entities/Message.java
@@ -51,6 +51,7 @@ public class Message extends AbstractEntity {
public static final String STATUS = "status";
public static final String TYPE = "type";
public static final String CARBON = "carbon";
+ public static final String OOB = "oob";
public static final String EDITED = "edited";
public static final String REMOTE_MSG_ID = "remoteMsgId";
public static final String SERVER_MSG_ID = "serverMsgId";
@@ -71,6 +72,7 @@ public class Message extends AbstractEntity {
protected int status;
protected int type;
protected boolean carbon = false;
+ protected boolean oob = false;
protected String edited = null;
protected String relativeFilePath;
protected boolean read = true;
@@ -106,7 +108,8 @@ public class Message extends AbstractEntity {
null,
null,
true,
- null);
+ null,
+ false);
this.conversation = conversation;
}
@@ -115,7 +118,7 @@ public class Message extends AbstractEntity {
final int encryption, final int status, final int type, final boolean carbon,
final String remoteMsgId, final String relativeFilePath,
final String serverMsgId, final String fingerprint, final boolean read,
- final String edited) {
+ final String edited, final boolean oob) {
this.uuid = uuid;
this.conversationUuid = conversationUUid;
this.counterpart = counterpart;
@@ -132,6 +135,7 @@ public class Message extends AbstractEntity {
this.axolotlFingerprint = fingerprint;
this.read = read;
this.edited = edited;
+ this.oob = oob;
}
public static Message fromCursor(Cursor cursor) {
@@ -172,7 +176,8 @@ public class Message extends AbstractEntity {
cursor.getString(cursor.getColumnIndex(SERVER_MSG_ID)),
cursor.getString(cursor.getColumnIndex(FINGERPRINT)),
cursor.getInt(cursor.getColumnIndex(READ)) > 0,
- cursor.getString(cursor.getColumnIndex(EDITED)));
+ cursor.getString(cursor.getColumnIndex(EDITED)),
+ cursor.getInt(cursor.getColumnIndex(OOB)) > 0);
}
public static Message createStatusMessage(Conversation conversation, String body) {
@@ -210,6 +215,7 @@ public class Message extends AbstractEntity {
values.put(FINGERPRINT, axolotlFingerprint);
values.put(READ,read ? 1 : 0);
values.put(EDITED, edited);
+ values.put(OOB, oob ? 1 : 0);
return values;
}
@@ -543,6 +549,10 @@ public class Message extends AbstractEntity {
return edited;
}
+ public void setOob(boolean isOob) {
+ this.oob = isOob;
+ }
+
public enum Decision {
MUST,
SHOULD,
@@ -565,7 +575,7 @@ public class Message extends AbstractEntity {
if (dotPosition != -1) {
String extension = filename.substring(dotPosition + 1);
// we want the real file extension, not the crypto one
- if (Arrays.asList(Transferable.VALID_CRYPTO_EXTENSIONS).contains(extension)) {
+ if (Transferable.VALID_CRYPTO_EXTENSIONS.contains(extension)) {
return extractRelevantExtension(filename.substring(0,dotPosition));
} else {
return extension;
@@ -604,6 +614,8 @@ public class Message extends AbstractEntity {
URL url = new URL(body);
if (!url.getProtocol().equalsIgnoreCase("http") && !url.getProtocol().equalsIgnoreCase("https")) {
return Decision.NEVER;
+ } else if (oob) {
+ return Decision.MUST;
}
String extension = extractRelevantExtension(url);
if (extension == null) {
@@ -618,8 +630,8 @@ public class Message extends AbstractEntity {
} else {
return Decision.NEVER;
}
- } else if (Arrays.asList(Transferable.VALID_IMAGE_EXTENSIONS).contains(extension)
- || Arrays.asList(Transferable.WELL_KNOWN_EXTENSIONS).contains(extension)) {
+ } else if (Transferable.VALID_IMAGE_EXTENSIONS.contains(extension)
+ || Transferable.WELL_KNOWN_EXTENSIONS.contains(extension)) {
return Decision.SHOULD;
} else {
return Decision.NEVER;
diff --git a/src/main/java/eu/siacs/conversations/entities/MucOptions.java b/src/main/java/eu/siacs/conversations/entities/MucOptions.java
index 3567c14f..4fe26743 100644
--- a/src/main/java/eu/siacs/conversations/entities/MucOptions.java
+++ b/src/main/java/eu/siacs/conversations/entities/MucOptions.java
@@ -4,9 +4,11 @@ import android.annotation.SuppressLint;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import eu.siacs.conversations.R;
import eu.siacs.conversations.xmpp.forms.Data;
@@ -245,7 +247,8 @@ public class MucOptions {
private Account account;
private final Map<String, User> users = Collections.synchronizedMap(new LinkedHashMap<String, User>());
- private List<String> features = new ArrayList<>();
+ private final Set<Jid> members = Collections.synchronizedSet(new HashSet<Jid>());
+ private final List<String> features = new ArrayList<>();
private Data form = new Data();
private Conversation conversation;
private boolean isOnline = false;
@@ -501,4 +504,12 @@ public class MucOptions {
public Conversation getConversation() {
return this.conversation;
}
+
+ public void putMember(Jid jid) {
+ members.add(jid);
+ }
+
+ public List<Jid> getMembers() {
+ return new ArrayList<>(members);
+ }
}
diff --git a/src/main/java/eu/siacs/conversations/entities/Roster.java b/src/main/java/eu/siacs/conversations/entities/Roster.java
index 628a31d1..d3ad9181 100644
--- a/src/main/java/eu/siacs/conversations/entities/Roster.java
+++ b/src/main/java/eu/siacs/conversations/entities/Roster.java
@@ -9,7 +9,7 @@ import eu.siacs.conversations.xmpp.jid.Jid;
public class Roster {
final Account account;
- final HashMap<String, Contact> contacts = new HashMap<>();
+ final HashMap<Jid, Contact> contacts = new HashMap<>();
private String version = null;
public Roster(Account account) {
@@ -21,7 +21,7 @@ public class Roster {
return null;
}
synchronized (this.contacts) {
- Contact contact = contacts.get(jid.toBareJid().toString());
+ Contact contact = contacts.get(jid.toBareJid());
if (contact != null && contact.showInRoster()) {
return contact;
} else {
@@ -32,15 +32,13 @@ public class Roster {
public Contact getContact(final Jid jid) {
synchronized (this.contacts) {
- final Jid bareJid = jid.toBareJid();
- if (contacts.containsKey(bareJid.toString())) {
- return contacts.get(bareJid.toString());
- } else {
- Contact contact = new Contact(bareJid);
+ if (!contacts.containsKey(jid.toBareJid())) {
+ Contact contact = new Contact(jid.toBareJid());
contact.setAccount(account);
- contacts.put(bareJid.toString(), contact);
+ contacts.put(contact.getJid().toBareJid(), contact);
return contact;
}
+ return contacts.get(jid.toBareJid());
}
}
@@ -80,7 +78,7 @@ public class Roster {
contact.setAccount(account);
contact.setOption(Contact.Options.IN_ROSTER);
synchronized (this.contacts) {
- contacts.put(contact.getJid().toBareJid().toString(), contact);
+ contacts.put(contact.getJid().toBareJid(), contact);
}
}
diff --git a/src/main/java/eu/siacs/conversations/entities/Transferable.java b/src/main/java/eu/siacs/conversations/entities/Transferable.java
index 016c81bd..5a47c451 100644
--- a/src/main/java/eu/siacs/conversations/entities/Transferable.java
+++ b/src/main/java/eu/siacs/conversations/entities/Transferable.java
@@ -1,10 +1,13 @@
package eu.siacs.conversations.entities;
+import java.util.Arrays;
+import java.util.List;
+
public interface Transferable {
- String[] VALID_IMAGE_EXTENSIONS = {"webp", "jpeg", "jpg", "png", "jpe"};
- String[] VALID_CRYPTO_EXTENSIONS = {"pgp", "gpg", "otr"};
- String[] WELL_KNOWN_EXTENSIONS = {"pdf","m4a","mp4"};
+ List<String> VALID_IMAGE_EXTENSIONS = Arrays.asList("webp", "jpeg", "jpg", "png", "jpe");
+ List<String> VALID_CRYPTO_EXTENSIONS = Arrays.asList("pgp", "gpg", "otr");
+ List<String> WELL_KNOWN_EXTENSIONS = Arrays.asList("pdf","m4a","mp4","3gp","aac","amr","mp3");
int STATUS_UNKNOWN = 0x200;
int STATUS_CHECKING = 0x201;