Use unread thread count for bottom bar.
This commit is contained in:
parent
aa60247e42
commit
343871ed8b
5 changed files with 28 additions and 43 deletions
|
@ -190,10 +190,10 @@ public abstract class MessageDatabase extends Database implements MmsSmsColumns
|
|||
public abstract @NonNull Reader getAllStoriesFor(@NonNull RecipientId recipientId);
|
||||
public abstract @NonNull MessageId getStoryId(@NonNull RecipientId authorId, long sentTimestamp) throws NoSuchMessageException;
|
||||
public abstract int getNumberOfStoryReplies(long parentStoryId);
|
||||
public abstract long getUnreadStoryThreadCount();
|
||||
public abstract boolean containsStories(long threadId);
|
||||
public abstract boolean hasSelfReplyInStory(long parentStoryId);
|
||||
public abstract @NonNull Cursor getStoryReplies(long parentStoryId);
|
||||
public abstract long getUnreadStoryCount();
|
||||
public abstract @Nullable Long getOldestStorySendTimestamp();
|
||||
public abstract int deleteStoriesOlderThan(long timestamp);
|
||||
public abstract @NonNull StoryViewState getStoryViewState(@NonNull RecipientId recipientId);
|
||||
|
|
|
@ -649,6 +649,24 @@ public class MmsDatabase extends MessageDatabase {
|
|||
throw new NoSuchMessageException("No story sent at " + sentTimestamp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getUnreadStoryThreadCount() {
|
||||
SQLiteDatabase db = getReadableDatabase();
|
||||
String query = "SELECT DISTINCT " + ThreadDatabase.RECIPIENT_ID + "\n"
|
||||
+ "FROM " + TABLE_NAME + "\n"
|
||||
+ "JOIN " + ThreadDatabase.TABLE_NAME + "\n"
|
||||
+ "ON " + TABLE_NAME + "." + THREAD_ID + " = " + ThreadDatabase.TABLE_NAME + "." + ThreadDatabase.ID + "\n"
|
||||
+ "WHERE " + IS_STORY_CLAUSE + " AND (" + getOutgoingTypeClause() + ") = 0 AND " + VIEWED_RECEIPT_COUNT + " = 0";
|
||||
|
||||
try (Cursor cursor = db.rawQuery(query, null)) {
|
||||
if (cursor != null) {
|
||||
return cursor.getCount();
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull List<StoryResult> getOrderedStoryRecipientsAndIds() {
|
||||
SQLiteDatabase db = getReadableDatabase();
|
||||
|
@ -697,16 +715,6 @@ public class MmsDatabase extends MessageDatabase {
|
|||
return rawQuery(where, whereArgs, true, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getUnreadStoryCount() {
|
||||
String[] columns = new String[]{"COUNT(*)"};
|
||||
String where = IS_STORY_CLAUSE + " AND NOT (" + getOutgoingTypeClause() + ") AND " + VIEWED_RECEIPT_COUNT + " = 0";
|
||||
|
||||
try (Cursor cursor = getReadableDatabase().query(TABLE_NAME, columns, where, null, null, null, null, null)) {
|
||||
return cursor != null && cursor.moveToFirst() ? cursor.getInt(0) : 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNumberOfStoryReplies(long parentStoryId) {
|
||||
SQLiteDatabase db = databaseHelper.getSignalReadableDatabase();
|
||||
|
|
|
@ -1426,6 +1426,11 @@ public class SmsDatabase extends MessageDatabase {
|
|||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getUnreadStoryThreadCount() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsStories(long threadId) {
|
||||
throw new UnsupportedOperationException();
|
||||
|
@ -1441,11 +1446,6 @@ public class SmsDatabase extends MessageDatabase {
|
|||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getUnreadStoryCount() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Long getOldestStorySendTimestamp() {
|
||||
throw new UnsupportedOperationException();
|
||||
|
|
|
@ -724,29 +724,6 @@ public class ThreadDatabase extends Database {
|
|||
return positions;
|
||||
}
|
||||
|
||||
public long getTabBarUnreadCount() {
|
||||
String[] countProjection = SqlUtil.buildArgs("COUNT(*)");
|
||||
String[] sumProjection = SqlUtil.buildArgs("SUM(" + UNREAD_COUNT + ")");
|
||||
String where = ARCHIVED + " = 0 AND " + MEANINGFUL_MESSAGES + " != 0 AND " + READ + " = ?";
|
||||
String[] countArgs = SqlUtil.buildArgs(ReadStatus.FORCED_UNREAD.serialize());
|
||||
String[] sumArgs = SqlUtil.buildArgs(ReadStatus.UNREAD.serialize());
|
||||
long total = 0;
|
||||
|
||||
try (Cursor cursor = getReadableDatabase().query(TABLE_NAME, countProjection, where, countArgs, null, null, null)) {
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
total += cursor.getLong(0);
|
||||
}
|
||||
}
|
||||
|
||||
try (Cursor cursor = getReadableDatabase().query(TABLE_NAME, sumProjection, where, sumArgs, null, null, null)) {
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
total += cursor.getLong(0);
|
||||
}
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
public Cursor getArchivedConversationList(long offset, long limit) {
|
||||
return getConversationList("1", offset, limit);
|
||||
}
|
||||
|
|
|
@ -11,24 +11,24 @@ class ConversationListTabRepository {
|
|||
fun getNumberOfUnreadConversations(): Observable<Long> {
|
||||
return Observable.create<Long> {
|
||||
val listener = DatabaseObserver.Observer {
|
||||
it.onNext(SignalDatabase.threads.tabBarUnreadCount)
|
||||
it.onNext(SignalDatabase.threads.unreadThreadCount)
|
||||
}
|
||||
|
||||
ApplicationDependencies.getDatabaseObserver().registerConversationListObserver(listener)
|
||||
it.setCancellable { ApplicationDependencies.getDatabaseObserver().unregisterObserver(listener) }
|
||||
it.onNext(SignalDatabase.threads.tabBarUnreadCount)
|
||||
it.onNext(SignalDatabase.threads.unreadThreadCount)
|
||||
}.subscribeOn(Schedulers.io())
|
||||
}
|
||||
|
||||
fun getNumberOfUnseenStories(): Observable<Long> {
|
||||
return Observable.create<Long> {
|
||||
val listener = DatabaseObserver.Observer {
|
||||
it.onNext(SignalDatabase.mms.unreadStoryCount)
|
||||
it.onNext(SignalDatabase.mms.unreadStoryThreadCount)
|
||||
}
|
||||
|
||||
ApplicationDependencies.getDatabaseObserver().registerConversationListObserver(listener)
|
||||
it.setCancellable { ApplicationDependencies.getDatabaseObserver().unregisterObserver(listener) }
|
||||
it.onNext(SignalDatabase.mms.unreadStoryCount)
|
||||
it.onNext(SignalDatabase.mms.unreadStoryThreadCount)
|
||||
}.subscribeOn(Schedulers.io())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue