Search in sources :

Example 1 with ViewOnceExpirationInfo

use of org.thoughtcrime.securesms.revealable.ViewOnceExpirationInfo in project Signal-Android by WhisperSystems.

the class MmsDatabase method getNearestExpiringViewOnceMessage.

@Override
@Nullable
public ViewOnceExpirationInfo getNearestExpiringViewOnceMessage() {
    SQLiteDatabase db = databaseHelper.getSignalReadableDatabase();
    ViewOnceExpirationInfo info = null;
    long nearestExpiration = Long.MAX_VALUE;
    String query = "SELECT " + TABLE_NAME + "." + ID + ", " + VIEW_ONCE + ", " + DATE_RECEIVED + " " + "FROM " + TABLE_NAME + " INNER JOIN " + AttachmentDatabase.TABLE_NAME + " " + "ON " + TABLE_NAME + "." + ID + " = " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.MMS_ID + " " + "WHERE " + VIEW_ONCE + " > 0 AND " + "(" + AttachmentDatabase.DATA + " NOT NULL OR " + AttachmentDatabase.TRANSFER_STATE + " != ?)";
    String[] args = new String[] { String.valueOf(AttachmentDatabase.TRANSFER_PROGRESS_DONE) };
    try (Cursor cursor = db.rawQuery(query, args)) {
        while (cursor != null && cursor.moveToNext()) {
            long id = cursor.getLong(cursor.getColumnIndexOrThrow(ID));
            long dateReceived = cursor.getLong(cursor.getColumnIndexOrThrow(DATE_RECEIVED));
            long expiresAt = dateReceived + ViewOnceUtil.MAX_LIFESPAN;
            if (info == null || expiresAt < nearestExpiration) {
                info = new ViewOnceExpirationInfo(id, dateReceived);
                nearestExpiration = expiresAt;
            }
        }
    }
    return info;
}
Also used : Cursor(android.database.Cursor) ViewOnceExpirationInfo(org.thoughtcrime.securesms.revealable.ViewOnceExpirationInfo) Nullable(androidx.annotation.Nullable)

Example 2 with ViewOnceExpirationInfo

use of org.thoughtcrime.securesms.revealable.ViewOnceExpirationInfo in project Signal-Android by signalapp.

the class MmsDatabase method getNearestExpiringViewOnceMessage.

@Override
@Nullable
public ViewOnceExpirationInfo getNearestExpiringViewOnceMessage() {
    SQLiteDatabase db = databaseHelper.getSignalReadableDatabase();
    ViewOnceExpirationInfo info = null;
    long nearestExpiration = Long.MAX_VALUE;
    String query = "SELECT " + TABLE_NAME + "." + ID + ", " + VIEW_ONCE + ", " + DATE_RECEIVED + " " + "FROM " + TABLE_NAME + " INNER JOIN " + AttachmentDatabase.TABLE_NAME + " " + "ON " + TABLE_NAME + "." + ID + " = " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.MMS_ID + " " + "WHERE " + VIEW_ONCE + " > 0 AND " + "(" + AttachmentDatabase.DATA + " NOT NULL OR " + AttachmentDatabase.TRANSFER_STATE + " != ?)";
    String[] args = new String[] { String.valueOf(AttachmentDatabase.TRANSFER_PROGRESS_DONE) };
    try (Cursor cursor = db.rawQuery(query, args)) {
        while (cursor != null && cursor.moveToNext()) {
            long id = cursor.getLong(cursor.getColumnIndexOrThrow(ID));
            long dateReceived = cursor.getLong(cursor.getColumnIndexOrThrow(DATE_RECEIVED));
            long expiresAt = dateReceived + ViewOnceUtil.MAX_LIFESPAN;
            if (info == null || expiresAt < nearestExpiration) {
                info = new ViewOnceExpirationInfo(id, dateReceived);
                nearestExpiration = expiresAt;
            }
        }
    }
    return info;
}
Also used : Cursor(android.database.Cursor) ViewOnceExpirationInfo(org.thoughtcrime.securesms.revealable.ViewOnceExpirationInfo) Nullable(androidx.annotation.Nullable)

Aggregations

Cursor (android.database.Cursor)2 Nullable (androidx.annotation.Nullable)2 ViewOnceExpirationInfo (org.thoughtcrime.securesms.revealable.ViewOnceExpirationInfo)2