use of net.sqlcipher.database.SQLiteDatabase in project Signal-Android by signalapp.
the class ThreadDatabase method getThreadIdFor.
public long getThreadIdFor(Recipient recipient, int distributionType) {
SQLiteDatabase db = databaseHelper.getReadableDatabase();
String where = ADDRESS + " = ?";
String[] recipientsArg = new String[] { recipient.getAddress().serialize() };
Cursor cursor = null;
try {
cursor = db.query(TABLE_NAME, new String[] { ID }, where, recipientsArg, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
return cursor.getLong(cursor.getColumnIndexOrThrow(ID));
} else {
return createThreadForRecipient(recipient.getAddress(), recipient.isGroupRecipient(), distributionType);
}
} finally {
if (cursor != null)
cursor.close();
}
}
use of net.sqlcipher.database.SQLiteDatabase in project Signal-Android by signalapp.
the class ThreadDatabase method getConversationList.
private Cursor getConversationList(String archived) {
SQLiteDatabase db = databaseHelper.getReadableDatabase();
String query = createQuery(ARCHIVED + " = ? AND " + MESSAGE_COUNT + " != 0", 0);
Cursor cursor = db.rawQuery(query, new String[] { archived });
setNotifyConverationListListeners(cursor);
return cursor;
}
use of net.sqlcipher.database.SQLiteDatabase in project Signal-Android by signalapp.
the class ThreadDatabase method getRecentConversationList.
public Cursor getRecentConversationList(int limit) {
SQLiteDatabase db = databaseHelper.getReadableDatabase();
String query = createQuery(MESSAGE_COUNT + " != 0", limit);
return db.rawQuery(query, null);
}
use of net.sqlcipher.database.SQLiteDatabase in project Signal-Android by signalapp.
the class ThreadDatabase method updateThread.
private void updateThread(long threadId, long count, String body, @Nullable Uri attachment, long date, int status, int deliveryReceiptCount, long type, boolean unarchive, long expiresIn, int readReceiptCount) {
ContentValues contentValues = new ContentValues(7);
contentValues.put(DATE, date - date % 1000);
contentValues.put(MESSAGE_COUNT, count);
contentValues.put(SNIPPET, body);
contentValues.put(SNIPPET_URI, attachment == null ? null : attachment.toString());
contentValues.put(SNIPPET_TYPE, type);
contentValues.put(STATUS, status);
contentValues.put(DELIVERY_RECEIPT_COUNT, deliveryReceiptCount);
contentValues.put(READ_RECEIPT_COUNT, readReceiptCount);
contentValues.put(EXPIRES_IN, expiresIn);
if (unarchive) {
contentValues.put(ARCHIVED, 0);
}
SQLiteDatabase db = databaseHelper.getWritableDatabase();
db.update(TABLE_NAME, contentValues, ID + " = ?", new String[] { threadId + "" });
notifyConversationListListeners();
}
use of net.sqlcipher.database.SQLiteDatabase in project Signal-Android by signalapp.
the class ThreadDatabase method getLastSeenAndHasSent.
public Pair<Long, Boolean> getLastSeenAndHasSent(long threadId) {
SQLiteDatabase db = databaseHelper.getReadableDatabase();
Cursor cursor = db.query(TABLE_NAME, new String[] { LAST_SEEN, HAS_SENT }, ID_WHERE, new String[] { String.valueOf(threadId) }, null, null, null);
try {
if (cursor != null && cursor.moveToFirst()) {
return new Pair<>(cursor.getLong(0), cursor.getLong(1) == 1);
}
return new Pair<>(-1L, false);
} finally {
if (cursor != null)
cursor.close();
}
}
Aggregations