aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/persistance/DatabaseBackend.java
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2014-05-19 21:05:17 +0200
committerDaniel Gultsch <daniel@gultsch.de>2014-05-19 21:05:17 +0200
commit371c985c25d0b7ed348a1f2328673636acb939d7 (patch)
tree1cf341a3b6eaf43b33ffd031d82a1b42b403140c /src/eu/siacs/conversations/persistance/DatabaseBackend.java
parenta6f9a742c0dffeaa2f7fc26ad65e9c972a9d2288 (diff)
made roster persistant aka enabled versioning again
Diffstat (limited to 'src/eu/siacs/conversations/persistance/DatabaseBackend.java')
-rw-r--r--src/eu/siacs/conversations/persistance/DatabaseBackend.java42
1 files changed, 16 insertions, 26 deletions
diff --git a/src/eu/siacs/conversations/persistance/DatabaseBackend.java b/src/eu/siacs/conversations/persistance/DatabaseBackend.java
index 63e050e3..771027f2 100644
--- a/src/eu/siacs/conversations/persistance/DatabaseBackend.java
+++ b/src/eu/siacs/conversations/persistance/DatabaseBackend.java
@@ -2,21 +2,17 @@ package eu.siacs.conversations.persistance;
import java.util.ArrayList;
import java.util.List;
-import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
-import eu.siacs.conversations.entities.Presences;
import eu.siacs.conversations.entities.Roster;
-import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
-import android.os.Bundle;
import android.util.Log;
public class DatabaseBackend extends SQLiteOpenHelper {
@@ -27,16 +23,16 @@ public class DatabaseBackend extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 5;
private static String CREATE_CONTATCS_STATEMENT = "create table "
- + Contact.TABLENAME + "(" + Contact.UUID + " TEXT PRIMARY KEY, "
- + Contact.ACCOUNT + " TEXT, " + Contact.SERVERNAME + " TEXT, "
+ + Contact.TABLENAME + "(" + Contact.ACCOUNT + " TEXT, " + Contact.SERVERNAME + " TEXT, "
+ Contact.SYSTEMNAME + " TEXT," + Contact.JID + " TEXT,"
+ Contact.KEYS + " TEXT," + Contact.PHOTOURI + " TEXT,"
+ Contact.OPTIONS + " NUMBER," + Contact.SYSTEMACCOUNT
+ " NUMBER, " + "FOREIGN KEY(" + Contact.ACCOUNT + ") REFERENCES "
- + Account.TABLENAME + "(" + Account.UUID + ") ON DELETE CASCADE);";
+ + Account.TABLENAME + "(" + Account.UUID + ") ON DELETE CASCADE, UNIQUE("+Contact.ACCOUNT+", "+Contact.JID+") ON CONFLICT REPLACE);";
public DatabaseBackend(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
+ Log.d("xmppService",CREATE_CONTATCS_STATEMENT);
}
@Override
@@ -220,7 +216,19 @@ public class DatabaseBackend extends SQLiteOpenHelper {
}
public void writeRoster(Roster roster) {
-
+ Account account = roster.getAccount();
+ SQLiteDatabase db = this.getWritableDatabase();
+ for(Contact contact : roster.getContacts()) {
+ if (contact.getOption(Contact.Options.IN_ROSTER)) {
+ db.insert(Contact.TABLENAME, null, contact.getContentValues());
+ } else {
+ String where = Contact.ACCOUNT + "=? AND "+Contact.JID+"=?";
+ String[] whereArgs = {account.getUuid(), contact.getJid()};
+ db.delete(Contact.TABLENAME, where, whereArgs);
+ }
+ }
+ account.setRosterVersion(roster.getVersion());
+ updateAccount(account);
}
public void deleteMessage(Message message) {
@@ -235,24 +243,6 @@ public class DatabaseBackend extends SQLiteOpenHelper {
db.delete(Message.TABLENAME, Message.CONVERSATION + "=?", args);
}
- public void deleteContact(Contact contact) {
- SQLiteDatabase db = this.getWritableDatabase();
- String[] args = { contact.getUuid() };
- db.delete(Contact.TABLENAME, Contact.UUID + "=?", args);
- }
-
- public Contact getContact(String uuid) {
- SQLiteDatabase db = this.getWritableDatabase();
- String[] args = { uuid };
- Cursor cursor = db.query(Contact.TABLENAME, null, Contact.UUID + "=?",
- args, null, null, null);
- if (cursor.getCount() == 0) {
- return null;
- }
- cursor.moveToFirst();
- return Contact.fromCursor(cursor);
- }
-
public Conversation findConversationByUuid(String conversationUuid) {
SQLiteDatabase db = this.getReadableDatabase();
String[] selectionArgs = { conversationUuid };