aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/entities
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2014-09-27 18:16:31 +0200
committeriNPUTmice <daniel@gultsch.de>2014-09-27 18:16:31 +0200
commit1ae9338fc9d5f8e1f6505445f07f4476efd8f139 (patch)
treeab69023e8b39ece36334072ebc9f82e520fddd67 /src/eu/siacs/conversations/entities
parent4a9ed0e208f716d41e5bd4fb525a64661c0de8f8 (diff)
made muc passwords and prefereced encryption method persistant across restarts
Diffstat (limited to 'src/eu/siacs/conversations/entities')
-rw-r--r--src/eu/siacs/conversations/entities/Conversation.java65
-rw-r--r--src/eu/siacs/conversations/entities/MucOptions.java4
2 files changed, 60 insertions, 9 deletions
diff --git a/src/eu/siacs/conversations/entities/Conversation.java b/src/eu/siacs/conversations/entities/Conversation.java
index 8395449db..b8d375860 100644
--- a/src/eu/siacs/conversations/entities/Conversation.java
+++ b/src/eu/siacs/conversations/entities/Conversation.java
@@ -4,6 +4,9 @@ import java.security.interfaces.DSAPublicKey;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
+import org.json.JSONException;
+import org.json.JSONObject;
+
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.utils.UIHelper;
@@ -36,6 +39,10 @@ public class Conversation extends AbstractEntity {
public static final String STATUS = "status";
public static final String CREATED = "created";
public static final String MODE = "mode";
+ public static final String ATTRIBUTES = "attributes";
+
+ public static final String ATTRIBUTE_NEXT_ENCRYPTION = "next_encryption";
+ public static final String ATTRIBUTE_MUC_PASSWORD = "muc_password";
private String name;
private String contactUuid;
@@ -44,6 +51,8 @@ public class Conversation extends AbstractEntity {
private int status;
private long created;
private int mode;
+
+ private JSONObject attributes = new JSONObject();
private long mutedTill = 0;
@@ -56,7 +65,6 @@ public class Conversation extends AbstractEntity {
private transient String otrFingerprint = null;
- private int nextMessageEncryption = -1;
private String nextMessage;
private transient MucOptions mucOptions = null;
@@ -73,13 +81,13 @@ public class Conversation extends AbstractEntity {
int mode) {
this(java.util.UUID.randomUUID().toString(), name, null, account
.getUuid(), contactJid, System.currentTimeMillis(),
- STATUS_AVAILABLE, mode);
+ STATUS_AVAILABLE, mode,"");
this.account = account;
}
public Conversation(String uuid, String name, String contactUuid,
String accountUuid, String contactJid, long created, int status,
- int mode) {
+ int mode, String attributes) {
this.uuid = uuid;
this.name = name;
this.contactUuid = contactUuid;
@@ -88,6 +96,14 @@ public class Conversation extends AbstractEntity {
this.created = created;
this.status = status;
this.mode = mode;
+ try {
+ if (attributes==null) {
+ attributes = new String();
+ }
+ this.attributes = new JSONObject(attributes);
+ } catch (JSONException e) {
+ this.attributes = new JSONObject();
+ }
}
public List<Message> getMessages() {
@@ -198,6 +214,7 @@ public class Conversation extends AbstractEntity {
values.put(CREATED, created);
values.put(STATUS, status);
values.put(MODE, mode);
+ values.put(ATTRIBUTES,attributes.toString());
return values;
}
@@ -209,7 +226,8 @@ public class Conversation extends AbstractEntity {
cursor.getString(cursor.getColumnIndex(CONTACTJID)),
cursor.getLong(cursor.getColumnIndex(CREATED)),
cursor.getInt(cursor.getColumnIndex(STATUS)),
- cursor.getInt(cursor.getColumnIndex(MODE)));
+ cursor.getInt(cursor.getColumnIndex(MODE)),
+ cursor.getString(cursor.getColumnIndex(ATTRIBUTES)));
}
public void setStatus(int status) {
@@ -345,7 +363,8 @@ public class Conversation extends AbstractEntity {
}
public int getNextEncryption(boolean force) {
- if (this.nextMessageEncryption == -1) {
+ int next = this.getIntAttribute(ATTRIBUTE_NEXT_ENCRYPTION, -1);
+ if (next == -1) {
int latest = this.getLatestEncryption();
if (latest == Message.ENCRYPTION_NONE) {
if (force && getMode() == MODE_SINGLE) {
@@ -363,16 +382,16 @@ public class Conversation extends AbstractEntity {
return latest;
}
}
- if (this.nextMessageEncryption == Message.ENCRYPTION_NONE && force
+ if (next == Message.ENCRYPTION_NONE && force
&& getMode() == MODE_SINGLE) {
return Message.ENCRYPTION_OTR;
} else {
- return this.nextMessageEncryption;
+ return next;
}
}
public void setNextEncryption(int encryption) {
- this.nextMessageEncryption = encryption;
+ this.setAttribute(ATTRIBUTE_NEXT_ENCRYPTION, String.valueOf(encryption));
}
public String getNextMessage() {
@@ -440,4 +459,34 @@ public class Conversation extends AbstractEntity {
public boolean isMuted() {
return SystemClock.elapsedRealtime() < this.mutedTill;
}
+
+ public boolean setAttribute(String key, String value) {
+ try {
+ this.attributes.put(key, value);
+ return true;
+ } catch (JSONException e) {
+ return false;
+ }
+ }
+
+ public String getAttribute(String key) {
+ try {
+ return this.attributes.getString(key);
+ } catch (JSONException e) {
+ return null;
+ }
+ }
+
+ public int getIntAttribute(String key, int defaultValue) {
+ String value = this.getAttribute(key);
+ if (value==null) {
+ return defaultValue;
+ } else {
+ try {
+ return Integer.parseInt(value);
+ } catch (NumberFormatException e) {
+ return defaultValue;
+ }
+ }
+ }
}
diff --git a/src/eu/siacs/conversations/entities/MucOptions.java b/src/eu/siacs/conversations/entities/MucOptions.java
index 676fb4f40..91a3d260a 100644
--- a/src/eu/siacs/conversations/entities/MucOptions.java
+++ b/src/eu/siacs/conversations/entities/MucOptions.java
@@ -323,7 +323,8 @@ public class MucOptions {
}
public String getPassword() {
- if (conversation.getBookmark() != null
+ this.password = conversation.getAttribute(Conversation.ATTRIBUTE_MUC_PASSWORD);
+ if (this.password == null && conversation.getBookmark() != null
&& conversation.getBookmark().getPassword() != null) {
return conversation.getBookmark().getPassword();
} else {
@@ -338,6 +339,7 @@ public class MucOptions {
} else {
this.password = password;
}
+ conversation.setAttribute(Conversation.ATTRIBUTE_MUC_PASSWORD, password);
}
public boolean isPasswordChanged() {