From 132b27adeef3ab4d305facda7dd035015b00766f Mon Sep 17 00:00:00 2001 From: steckbrief Date: Sat, 5 May 2018 20:28:04 +0200 Subject: introduces new message state model --- .../persistance/DatabaseBackend.java | 25 ++++------------------ 1 file changed, 4 insertions(+), 21 deletions(-) (limited to 'src/main/java/de/thedevstack/conversationsplus/persistance/DatabaseBackend.java') diff --git a/src/main/java/de/thedevstack/conversationsplus/persistance/DatabaseBackend.java b/src/main/java/de/thedevstack/conversationsplus/persistance/DatabaseBackend.java index e721afbb..fd227e5a 100644 --- a/src/main/java/de/thedevstack/conversationsplus/persistance/DatabaseBackend.java +++ b/src/main/java/de/thedevstack/conversationsplus/persistance/DatabaseBackend.java @@ -58,7 +58,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { private static final String DATABASE_NAME = "history"; private static final int DATABASE_VERSION = 25; private static final int C_TO_CPLUS_VERSION_OFFSET = 1000; - private static final int CPLUS_DATABASE_VERSION = 3; + private static final int CPLUS_DATABASE_VERSION = 5; private static final int CPLUS_DATABASE_VERSION_MULTIPLIER = 100; private static final int PHYSICAL_DATABASE_VERSION = DATABASE_VERSION + C_TO_CPLUS_VERSION_OFFSET + (CPLUS_DATABASE_VERSION * CPLUS_DATABASE_VERSION_MULTIPLIER); @@ -217,7 +217,8 @@ public class DatabaseBackend extends SQLiteOpenHelper { cursor.close(); } - if (oldVersion < 3 && newVersion >= 3) { + if ((oldVersion < 3 && newVersion >= 3) + || (oldVersion <= 5 && newVersion >= 4)) { MessageDatabaseAccess.upgrade(db, oldVersion, newVersion); } } @@ -719,25 +720,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { } public Pair getLastMessageReceived(Account account) { - Cursor cursor = null; - try { - SQLiteDatabase db = this.getReadableDatabase(); - String sql = "select messages.timeSent,messages.serverMsgId from accounts join conversations on accounts.uuid=conversations.accountUuid join messages on conversations.uuid=messages.conversationUuid where accounts.uuid=? and (messages.status=0 or messages.carbon=1 or messages.serverMsgId not null) order by messages.timesent desc limit 1"; - String[] args = {account.getUuid()}; - cursor = db.rawQuery(sql, args); - if (cursor.getCount() == 0) { - return null; - } else { - cursor.moveToFirst(); - return new Pair<>(cursor.getLong(0), cursor.getString(1)); - } - } catch (Exception e) { - return null; - } finally { - if (cursor != null) { - cursor.close(); - } - } + return MessageDatabaseAccess.getLastMessageReceived(this.getReadableDatabase(), account.getUuid()); } private Cursor getCursorForSession(Account account, AxolotlAddress contact) { -- cgit v1.2.3