Search in sources :

Example 6 with MegaphoneRecord

use of org.thoughtcrime.securesms.database.model.MegaphoneRecord in project Signal-Android by WhisperSystems.

the class MegaphoneRepository method markFinished.

@AnyThread
public void markFinished(@NonNull Event event, @Nullable Runnable onComplete) {
    executor.execute(() -> {
        MegaphoneRecord record = databaseCache.get(event);
        if (record != null && record.isFinished()) {
            return;
        }
        database.markFinished(event);
        resetDatabaseCache();
        if (onComplete != null) {
            onComplete.run();
        }
    });
}
Also used : MegaphoneRecord(org.thoughtcrime.securesms.database.model.MegaphoneRecord) AnyThread(androidx.annotation.AnyThread)

Example 7 with MegaphoneRecord

use of org.thoughtcrime.securesms.database.model.MegaphoneRecord in project Signal-Android by signalapp.

the class MegaphoneDatabase method getAllAndDeleteMissing.

@NonNull
public List<MegaphoneRecord> getAllAndDeleteMissing() {
    SQLiteDatabase db = getWritableDatabase();
    List<MegaphoneRecord> records = new ArrayList<>();
    db.beginTransaction();
    try {
        Set<String> missingKeys = new HashSet<>();
        try (Cursor cursor = db.query(TABLE_NAME, null, null, null, null, null, null)) {
            while (cursor != null && cursor.moveToNext()) {
                String event = cursor.getString(cursor.getColumnIndexOrThrow(EVENT));
                int seenCount = cursor.getInt(cursor.getColumnIndexOrThrow(SEEN_COUNT));
                long lastSeen = cursor.getLong(cursor.getColumnIndexOrThrow(LAST_SEEN));
                long firstVisible = cursor.getLong(cursor.getColumnIndexOrThrow(FIRST_VISIBLE));
                boolean finished = cursor.getInt(cursor.getColumnIndexOrThrow(FINISHED)) == 1;
                if (Event.hasKey(event)) {
                    records.add(new MegaphoneRecord(Event.fromKey(event), seenCount, lastSeen, firstVisible, finished));
                } else {
                    Log.w(TAG, "No in-app handing for event '" + event + "'! Deleting it from the database.");
                    missingKeys.add(event);
                }
            }
        }
        for (String missing : missingKeys) {
            String query = EVENT + " = ?";
            String[] args = new String[] { missing };
            db.delete(TABLE_NAME, query, args);
        }
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
    return records;
}
Also used : MegaphoneRecord(org.thoughtcrime.securesms.database.model.MegaphoneRecord) SQLiteDatabase(net.zetetic.database.sqlcipher.SQLiteDatabase) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) HashSet(java.util.HashSet) NonNull(androidx.annotation.NonNull)

Example 8 with MegaphoneRecord

use of org.thoughtcrime.securesms.database.model.MegaphoneRecord in project Signal-Android by signalapp.

the class MegaphoneRepository method markFinished.

@AnyThread
public void markFinished(@NonNull Event event, @Nullable Runnable onComplete) {
    executor.execute(() -> {
        MegaphoneRecord record = databaseCache.get(event);
        if (record != null && record.isFinished()) {
            return;
        }
        database.markFinished(event);
        resetDatabaseCache();
        if (onComplete != null) {
            onComplete.run();
        }
    });
}
Also used : MegaphoneRecord(org.thoughtcrime.securesms.database.model.MegaphoneRecord) AnyThread(androidx.annotation.AnyThread)

Aggregations

MegaphoneRecord (org.thoughtcrime.securesms.database.model.MegaphoneRecord)8 NonNull (androidx.annotation.NonNull)4 AnyThread (androidx.annotation.AnyThread)3 Context (android.content.Context)2 Intent (android.content.Intent)2 Build (android.os.Build)2 Settings (android.provider.Settings)2 Nullable (androidx.annotation.Nullable)2 WorkerThread (androidx.annotation.WorkerThread)2 Stream (com.annimon.stream.Stream)2 LocalDateTime (java.time.LocalDateTime)2 Month (java.time.Month)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Locale (java.util.Locale)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Set (java.util.Set)2 TimeUnit (java.util.concurrent.TimeUnit)2 TranslationDetection (org.signal.core.util.TranslationDetection)2