diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2015-12-11 13:52:04 +0100 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2015-12-11 13:52:04 +0100 |
commit | 293e820a5857ffff5301babc43fc08120a35385c (patch) | |
tree | 0088453d3bb87a943904f0ad47f2afcc75f94256 /src/main/java/eu/siacs/conversations/persistance | |
parent | 61b068110983c279fa31b9a1062b76dd6ae38416 (diff) |
get rid of lastMessageTransmitted in favor of db query
Diffstat (limited to 'src/main/java/eu/siacs/conversations/persistance')
-rw-r--r-- | src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java index 2347c318..e482f0f8 100644 --- a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java @@ -9,6 +9,7 @@ import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.util.Base64; import android.util.Log; +import android.util.Pair; import org.whispersystems.libaxolotl.AxolotlAddress; import org.whispersystems.libaxolotl.IdentityKey; @@ -591,6 +592,19 @@ public class DatabaseBackend extends SQLiteOpenHelper { db.delete(Message.TABLENAME, Message.CONVERSATION + "=?", args); } + public Pair<Long,String> getLastMessageReceived(Account account) { + 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 cursor = db.rawQuery(sql,args); + if (cursor.getCount() ==0) { + return null; + } else { + cursor.moveToFirst(); + return new Pair<>(cursor.getLong(0),cursor.getString(1)); + } + } + public Conversation findConversationByUuid(String conversationUuid) { SQLiteDatabase db = this.getReadableDatabase(); String[] selectionArgs = {conversationUuid}; |