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