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;
}
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;
}
Aggregations