aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu
diff options
context:
space:
mode:
Diffstat (limited to 'src/eu')
-rw-r--r--src/eu/siacs/conversations/entities/Conversation.java65
-rw-r--r--src/eu/siacs/conversations/entities/MucOptions.java4
-rw-r--r--src/eu/siacs/conversations/parser/MessageParser.java2
-rw-r--r--src/eu/siacs/conversations/persistance/DatabaseBackend.java10
-rw-r--r--src/eu/siacs/conversations/services/XmppConnectionService.java1
-rw-r--r--src/eu/siacs/conversations/ui/ConversationActivity.java2
-rw-r--r--src/eu/siacs/conversations/ui/ConversationFragment.java2
-rw-r--r--src/eu/siacs/conversations/ui/XmppActivity.java1
8 files changed, 75 insertions, 12 deletions
diff --git a/src/eu/siacs/conversations/entities/Conversation.java b/src/eu/siacs/conversations/entities/Conversation.java
index 8395449d..b8d37586 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 676fb4f4..91a3d260 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() {
diff --git a/src/eu/siacs/conversations/parser/MessageParser.java b/src/eu/siacs/conversations/parser/MessageParser.java
index 1c77d10d..9e2ccd92 100644
--- a/src/eu/siacs/conversations/parser/MessageParser.java
+++ b/src/eu/siacs/conversations/parser/MessageParser.java
@@ -298,6 +298,7 @@ public class MessageParser extends AbstractParser implements
Element password = x.findChild("password");
conversation.getMucOptions().setPassword(
password.getContent());
+ mXmppConnectionService.databaseBackend.updateConversation(conversation);
}
mXmppConnectionService.joinMuc(conversation);
mXmppConnectionService.updateConversationUi();
@@ -313,6 +314,7 @@ public class MessageParser extends AbstractParser implements
if (!conversation.getMucOptions().online()) {
if (password != null) {
conversation.getMucOptions().setPassword(password);
+ mXmppConnectionService.databaseBackend.updateConversation(conversation);
}
mXmppConnectionService.joinMuc(conversation);
mXmppConnectionService.updateConversationUi();
diff --git a/src/eu/siacs/conversations/persistance/DatabaseBackend.java b/src/eu/siacs/conversations/persistance/DatabaseBackend.java
index 51fd79e5..7afe387e 100644
--- a/src/eu/siacs/conversations/persistance/DatabaseBackend.java
+++ b/src/eu/siacs/conversations/persistance/DatabaseBackend.java
@@ -19,7 +19,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
private static DatabaseBackend instance = null;
private static final String DATABASE_NAME = "history";
- private static final int DATABASE_VERSION = 7;
+ private static final int DATABASE_VERSION = 8;
private static String CREATE_CONTATCS_STATEMENT = "create table "
+ Contact.TABLENAME + "(" + Contact.ACCOUNT + " TEXT, "
@@ -50,8 +50,8 @@ public class DatabaseBackend extends SQLiteOpenHelper {
+ " TEXT, " + Conversation.CONTACT + " TEXT, "
+ Conversation.ACCOUNT + " TEXT, " + Conversation.CONTACTJID
+ " TEXT, " + Conversation.CREATED + " NUMBER, "
- + Conversation.STATUS + " NUMBER," + Conversation.MODE
- + " NUMBER," + "FOREIGN KEY(" + Conversation.ACCOUNT
+ + Conversation.STATUS + " NUMBER, " + Conversation.MODE
+ + " NUMBER, "+Conversation.ATTRIBUTES + " TEXT, FOREIGN KEY(" + Conversation.ACCOUNT
+ ") REFERENCES " + Account.TABLENAME + "(" + Account.UUID
+ ") ON DELETE CASCADE);");
db.execSQL("create table " + Message.TABLENAME + "( " + Message.UUID
@@ -96,6 +96,10 @@ public class DatabaseBackend extends SQLiteOpenHelper {
db.execSQL("ALTER TABLE " + Account.TABLENAME + " ADD COLUMN "
+ Account.AVATAR + " TEXT");
}
+ if (oldVersion < 8 && newVersion >= 8) {
+ db.execSQL("ALTER TABLE " + Conversation.TABLENAME + " ADD COLUMN "
+ + Conversation.ATTRIBUTES + " TEXT");
+ }
}
public static synchronized DatabaseBackend getInstance(Context context) {
diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java
index 524a3bd7..badf1df5 100644
--- a/src/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/eu/siacs/conversations/services/XmppConnectionService.java
@@ -1119,6 +1119,7 @@ public class XmppConnectionService extends Service {
}
pushBookmarks(conversation.getAccount());
}
+ databaseBackend.updateConversation(conversation);
joinMuc(conversation);
}
}
diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java
index 6fc5d36d..b6b6aa72 100644
--- a/src/eu/siacs/conversations/ui/ConversationActivity.java
+++ b/src/eu/siacs/conversations/ui/ConversationActivity.java
@@ -297,6 +297,7 @@ public class ConversationActivity extends XmppActivity implements
int which) {
conversation
.setNextEncryption(Message.ENCRYPTION_NONE);
+ xmppConnectionService.databaseBackend.updateConversation(conversation);
selectPresenceToAttachFile(attachmentChoice);
}
});
@@ -472,6 +473,7 @@ public class ConversationActivity extends XmppActivity implements
conversation.setNextEncryption(Message.ENCRYPTION_NONE);
break;
}
+ xmppConnectionService.databaseBackend.updateConversation(conversation);
fragment.updateChatMsgHint();
return true;
}
diff --git a/src/eu/siacs/conversations/ui/ConversationFragment.java b/src/eu/siacs/conversations/ui/ConversationFragment.java
index 9e2d39e5..a8dee4f7 100644
--- a/src/eu/siacs/conversations/ui/ConversationFragment.java
+++ b/src/eu/siacs/conversations/ui/ConversationFragment.java
@@ -668,6 +668,7 @@ public class ConversationFragment extends Fragment {
int which) {
conversation
.setNextEncryption(Message.ENCRYPTION_NONE);
+ xmppService.databaseBackend.updateConversation(conversation);
message.setEncryption(Message.ENCRYPTION_NONE);
xmppService.sendMessage(message);
messageSent();
@@ -696,6 +697,7 @@ public class ConversationFragment extends Fragment {
conversation
.setNextEncryption(Message.ENCRYPTION_NONE);
message.setEncryption(Message.ENCRYPTION_NONE);
+ xmppService.databaseBackend.updateConversation(conversation);
xmppService.sendMessage(message);
messageSent();
}
diff --git a/src/eu/siacs/conversations/ui/XmppActivity.java b/src/eu/siacs/conversations/ui/XmppActivity.java
index 1a94c766..b54bc152 100644
--- a/src/eu/siacs/conversations/ui/XmppActivity.java
+++ b/src/eu/siacs/conversations/ui/XmppActivity.java
@@ -294,6 +294,7 @@ public abstract class XmppActivity extends Activity {
if (conversation != null) {
conversation
.setNextEncryption(Message.ENCRYPTION_PGP);
+ xmppConnectionService.databaseBackend.updateConversation(conversation);
}
}