Search in sources :

Example 1 with MegaphoneRecord

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

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 2 with MegaphoneRecord

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

the class Megaphones method getNextMegaphone.

@WorkerThread
@Nullable
static Megaphone getNextMegaphone(@NonNull Context context, @NonNull Map<Event, MegaphoneRecord> records) {
    long currentTime = System.currentTimeMillis();
    List<Megaphone> megaphones = Stream.of(buildDisplayOrder(context, records)).filter(e -> {
        MegaphoneRecord record = Objects.requireNonNull(records.get(e.getKey()));
        MegaphoneSchedule schedule = e.getValue();
        return !record.isFinished() && schedule.shouldDisplay(record.getSeenCount(), record.getLastSeen(), record.getFirstVisible(), currentTime);
    }).map(Map.Entry::getKey).map(records::get).map(record -> Megaphones.forRecord(context, record)).toList();
    if (megaphones.size() > 0) {
        return megaphones.get(0);
    } else {
        return null;
    }
}
Also used : SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) Context(android.content.Context) Stream(com.annimon.stream.Stream) NonNull(androidx.annotation.NonNull) LocalDateTime(java.time.LocalDateTime) WorkerThread(androidx.annotation.WorkerThread) Intent(android.content.Intent) R(org.thoughtcrime.securesms.R) LinkedHashMap(java.util.LinkedHashMap) LocaleFeatureFlags(org.thoughtcrime.securesms.util.LocaleFeatureFlags) SignalPinReminders(org.thoughtcrime.securesms.lock.SignalPinReminders) NotificationChannels(org.thoughtcrime.securesms.notifications.NotificationChannels) TranslationDetection(org.signal.core.util.TranslationDetection) Locale(java.util.Locale) Map(java.util.Map) Badge(org.thoughtcrime.securesms.badges.models.Badge) Settings(android.provider.Settings) Recipient(org.thoughtcrime.securesms.recipients.Recipient) KbsMigrationActivity(org.thoughtcrime.securesms.lock.v2.KbsMigrationActivity) Build(android.os.Build) PlayServicesUtil(org.thoughtcrime.securesms.util.PlayServicesUtil) AppSettingsActivity(org.thoughtcrime.securesms.components.settings.app.AppSettingsActivity) MegaphoneRecord(org.thoughtcrime.securesms.database.model.MegaphoneRecord) AvatarHelper(org.thoughtcrime.securesms.profiles.AvatarHelper) Month(java.time.Month) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) Set(java.util.Set) NetworkConstraint(org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint) DynamicLanguageContextWrapper(org.thoughtcrime.securesms.util.dynamiclanguage.DynamicLanguageContextWrapper) SetUtil(org.thoughtcrime.securesms.util.SetUtil) CreateKbsPinActivity(org.thoughtcrime.securesms.lock.v2.CreateKbsPinActivity) SignalPinReminderDialog(org.thoughtcrime.securesms.lock.SignalPinReminderDialog) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) Log(org.signal.core.util.logging.Log) FeatureFlags(org.thoughtcrime.securesms.util.FeatureFlags) List(java.util.List) Nullable(androidx.annotation.Nullable) VersionTracker(org.thoughtcrime.securesms.util.VersionTracker) ChatWallpaperActivity(org.thoughtcrime.securesms.wallpaper.ChatWallpaperActivity) ManageProfileActivity(org.thoughtcrime.securesms.profiles.manage.ManageProfileActivity) MegaphoneRecord(org.thoughtcrime.securesms.database.model.MegaphoneRecord) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) WorkerThread(androidx.annotation.WorkerThread) Nullable(androidx.annotation.Nullable)

Example 3 with MegaphoneRecord

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

the class MegaphoneRepository method markSeen.

@AnyThread
public void markSeen(@NonNull Event event) {
    long lastSeen = System.currentTimeMillis();
    executor.execute(() -> {
        MegaphoneRecord record = getRecord(event);
        database.markSeen(event, record.getSeenCount() + 1, lastSeen);
        enabled = false;
        resetDatabaseCache();
    });
}
Also used : MegaphoneRecord(org.thoughtcrime.securesms.database.model.MegaphoneRecord) AnyThread(androidx.annotation.AnyThread)

Example 4 with MegaphoneRecord

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

the class Megaphones method getNextMegaphone.

@WorkerThread
@Nullable
static Megaphone getNextMegaphone(@NonNull Context context, @NonNull Map<Event, MegaphoneRecord> records) {
    long currentTime = System.currentTimeMillis();
    List<Megaphone> megaphones = Stream.of(buildDisplayOrder(context, records)).filter(e -> {
        MegaphoneRecord record = Objects.requireNonNull(records.get(e.getKey()));
        MegaphoneSchedule schedule = e.getValue();
        return !record.isFinished() && schedule.shouldDisplay(record.getSeenCount(), record.getLastSeen(), record.getFirstVisible(), currentTime);
    }).map(Map.Entry::getKey).map(records::get).map(record -> Megaphones.forRecord(context, record)).toList();
    if (megaphones.size() > 0) {
        return megaphones.get(0);
    } else {
        return null;
    }
}
Also used : SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) Context(android.content.Context) Stream(com.annimon.stream.Stream) NonNull(androidx.annotation.NonNull) LocalDateTime(java.time.LocalDateTime) WorkerThread(androidx.annotation.WorkerThread) Intent(android.content.Intent) R(org.thoughtcrime.securesms.R) LinkedHashMap(java.util.LinkedHashMap) LocaleFeatureFlags(org.thoughtcrime.securesms.util.LocaleFeatureFlags) SignalPinReminders(org.thoughtcrime.securesms.lock.SignalPinReminders) NotificationChannels(org.thoughtcrime.securesms.notifications.NotificationChannels) TranslationDetection(org.signal.core.util.TranslationDetection) Locale(java.util.Locale) Map(java.util.Map) Badge(org.thoughtcrime.securesms.badges.models.Badge) Settings(android.provider.Settings) Recipient(org.thoughtcrime.securesms.recipients.Recipient) KbsMigrationActivity(org.thoughtcrime.securesms.lock.v2.KbsMigrationActivity) Build(android.os.Build) PlayServicesUtil(org.thoughtcrime.securesms.util.PlayServicesUtil) AppSettingsActivity(org.thoughtcrime.securesms.components.settings.app.AppSettingsActivity) MegaphoneRecord(org.thoughtcrime.securesms.database.model.MegaphoneRecord) AvatarHelper(org.thoughtcrime.securesms.profiles.AvatarHelper) Month(java.time.Month) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) Set(java.util.Set) NetworkConstraint(org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint) DynamicLanguageContextWrapper(org.thoughtcrime.securesms.util.dynamiclanguage.DynamicLanguageContextWrapper) SetUtil(org.thoughtcrime.securesms.util.SetUtil) CreateKbsPinActivity(org.thoughtcrime.securesms.lock.v2.CreateKbsPinActivity) SignalPinReminderDialog(org.thoughtcrime.securesms.lock.SignalPinReminderDialog) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) Log(org.signal.core.util.logging.Log) FeatureFlags(org.thoughtcrime.securesms.util.FeatureFlags) List(java.util.List) Nullable(androidx.annotation.Nullable) VersionTracker(org.thoughtcrime.securesms.util.VersionTracker) ChatWallpaperActivity(org.thoughtcrime.securesms.wallpaper.ChatWallpaperActivity) ManageProfileActivity(org.thoughtcrime.securesms.profiles.manage.ManageProfileActivity) MegaphoneRecord(org.thoughtcrime.securesms.database.model.MegaphoneRecord) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) WorkerThread(androidx.annotation.WorkerThread) Nullable(androidx.annotation.Nullable)

Example 5 with MegaphoneRecord

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

the class MegaphoneRepository method markSeen.

@AnyThread
public void markSeen(@NonNull Event event) {
    long lastSeen = System.currentTimeMillis();
    executor.execute(() -> {
        MegaphoneRecord record = getRecord(event);
        database.markSeen(event, record.getSeenCount() + 1, lastSeen);
        enabled = false;
        resetDatabaseCache();
    });
}
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