kopia lustrzana https://github.com/ryukoposting/Signal-Android
Add logging for unread thread ids.
rodzic
359a39ddaf
commit
e69d944f11
|
@ -25,6 +25,7 @@ import android.net.Uri;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.arch.core.util.Function;
|
||||||
|
|
||||||
import com.annimon.stream.Collectors;
|
import com.annimon.stream.Collectors;
|
||||||
import com.annimon.stream.Stream;
|
import com.annimon.stream.Stream;
|
||||||
|
@ -516,17 +517,21 @@ public class ThreadDatabase extends Database {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getUnreadThreadCount() {
|
public @NonNull Long getUnreadThreadCount() {
|
||||||
SQLiteDatabase db = databaseHelper.getSignalReadableDatabase();
|
return getUnreadThreadIdAggregate(SqlUtil.COUNT, cursor -> CursorUtil.getAggregateOrDefault(cursor, 0L, cursor::getLong));
|
||||||
String[] projection = SqlUtil.buildArgs("COUNT(*)");
|
}
|
||||||
String where = READ + " != " + ReadStatus.READ.serialize() + " AND " + ARCHIVED + " = 0 AND " + MEANINGFUL_MESSAGES + " != 0";
|
|
||||||
|
|
||||||
try (Cursor cursor = db.query(TABLE_NAME, projection, where, null, null, null, null)) {
|
public @Nullable String getUnreadThreadIdList() {
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
return getUnreadThreadIdAggregate(SqlUtil.buildArgs("GROUP_CONCAT(" + ID + ")"),
|
||||||
return cursor.getLong(0);
|
cursor -> CursorUtil.getAggregateOrDefault(cursor, null, cursor::getString));
|
||||||
} else {
|
}
|
||||||
return 0;
|
|
||||||
}
|
private @NonNull <T> T getUnreadThreadIdAggregate(@NonNull String[] aggregator, @NonNull Function<Cursor, T> mapCursorToType) {
|
||||||
|
SQLiteDatabase db = databaseHelper.getSignalReadableDatabase();
|
||||||
|
String where = READ + " != " + ReadStatus.READ.serialize() + " AND " + ARCHIVED + " = 0 AND " + MEANINGFUL_MESSAGES + " != 0";
|
||||||
|
|
||||||
|
try (Cursor cursor = db.query(TABLE_NAME, aggregator, where, null, null, null, null)) {
|
||||||
|
return mapCursorToType.apply(cursor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.stories.tabs
|
||||||
|
|
||||||
import io.reactivex.rxjava3.core.Observable
|
import io.reactivex.rxjava3.core.Observable
|
||||||
import io.reactivex.rxjava3.schedulers.Schedulers
|
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||||
|
import org.signal.core.util.logging.Log
|
||||||
import org.thoughtcrime.securesms.database.DatabaseObserver
|
import org.thoughtcrime.securesms.database.DatabaseObserver
|
||||||
import org.thoughtcrime.securesms.database.SignalDatabase
|
import org.thoughtcrime.securesms.database.SignalDatabase
|
||||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
|
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
|
||||||
|
@ -9,15 +10,27 @@ import org.thoughtcrime.securesms.recipients.Recipient
|
||||||
|
|
||||||
class ConversationListTabRepository {
|
class ConversationListTabRepository {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val TAG = Log.tag(ConversationListTabRepository::class.java)
|
||||||
|
}
|
||||||
|
|
||||||
fun getNumberOfUnreadConversations(): Observable<Long> {
|
fun getNumberOfUnreadConversations(): Observable<Long> {
|
||||||
return Observable.create<Long> {
|
return Observable.create<Long> {
|
||||||
val listener = DatabaseObserver.Observer {
|
fun refresh() {
|
||||||
it.onNext(SignalDatabase.threads.unreadThreadCount)
|
it.onNext(SignalDatabase.threads.unreadThreadCount)
|
||||||
|
|
||||||
|
val ids = SignalDatabase.threads.unreadThreadIdList
|
||||||
|
Log.d(TAG, "Unread threads: { $ids }")
|
||||||
|
}
|
||||||
|
|
||||||
|
val listener = DatabaseObserver.Observer {
|
||||||
|
refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
ApplicationDependencies.getDatabaseObserver().registerConversationListObserver(listener)
|
ApplicationDependencies.getDatabaseObserver().registerConversationListObserver(listener)
|
||||||
it.setCancellable { ApplicationDependencies.getDatabaseObserver().unregisterObserver(listener) }
|
it.setCancellable { ApplicationDependencies.getDatabaseObserver().unregisterObserver(listener) }
|
||||||
it.onNext(SignalDatabase.threads.unreadThreadCount)
|
|
||||||
|
refresh()
|
||||||
}.subscribeOn(Schedulers.io())
|
}.subscribeOn(Schedulers.io())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,10 @@ package org.signal.core.util;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
|
||||||
public final class CursorUtil {
|
public final class CursorUtil {
|
||||||
|
@ -94,4 +96,12 @@ public final class CursorUtil {
|
||||||
|
|
||||||
return row.toString();
|
return row.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static @Nullable <T> T getAggregateOrDefault(@NonNull Cursor cursor, @Nullable T defaultValue, @NonNull Function<Integer, T> cursorColumnFn) {
|
||||||
|
if (cursor.moveToFirst()) {
|
||||||
|
return cursorColumnFn.apply(0);
|
||||||
|
} else {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,9 @@ object SqlUtil {
|
||||||
/** The maximum number of arguments (i.e. question marks) allowed in a SQL statement. */
|
/** The maximum number of arguments (i.e. question marks) allowed in a SQL statement. */
|
||||||
private const val MAX_QUERY_ARGS = 999
|
private const val MAX_QUERY_ARGS = 999
|
||||||
|
|
||||||
|
@JvmField
|
||||||
|
val COUNT = arrayOf("COUNT(*)")
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun tableExists(db: SupportSQLiteDatabase, table: String): Boolean {
|
fun tableExists(db: SupportSQLiteDatabase, table: String): Boolean {
|
||||||
db.query("SELECT name FROM sqlite_master WHERE type=? AND name=?", arrayOf("table", table)).use { cursor ->
|
db.query("SELECT name FROM sqlite_master WHERE type=? AND name=?", arrayOf("table", table)).use { cursor ->
|
||||||
|
|
Ładowanie…
Reference in New Issue