diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomService.kt index 8c833644ee..af5a8a8091 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomService.kt @@ -196,7 +196,7 @@ interface RoomService { /** * TODO Doc */ - fun getNotificationCountForRooms(queryParams: RoomSummaryQueryParams): RoomAggregateNotificationCount + fun getNotificationCountForRooms(queryParams: RoomSummaryQueryParams, preferenceProvider: RoomSummary.RoomSummaryPreferenceProvider): RoomAggregateNotificationCount private val defaultPagedListConfig get() = PagedList.Config.Builder() diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomSummary.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomSummary.kt index 810d1df53c..6171251e4d 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomSummary.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomSummary.kt @@ -21,6 +21,7 @@ import org.matrix.android.sdk.api.session.room.model.tag.RoomTag import org.matrix.android.sdk.api.session.room.send.UserDraft import org.matrix.android.sdk.api.session.room.sender.SenderInfo import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent +import org.matrix.android.sdk.internal.database.model.RoomSummaryEntityFields /** * This class holds some data of a room. @@ -134,5 +135,13 @@ data class RoomSummary constructor( // SC addition interface RoomSummaryPreferenceProvider { fun getUnreadKind(isDirect: Boolean): Int + fun shouldShowUnimportantCounterBadge(): Boolean + fun getUnreadRoomSummaryField(isDirect: Boolean): String { + return when(getUnreadKind(isDirect)) { + UNREAD_KIND_ORIGINAL_CONTENT -> RoomSummaryEntityFields.HAS_UNREAD_ORIGINAL_CONTENT_MESSAGES + UNREAD_KIND_CONTENT -> RoomSummaryEntityFields.HAS_UNREAD_CONTENT_MESSAGES + /*UNREAD_KIND_FULL*/ else -> RoomSummaryEntityFields.HAS_UNREAD_MESSAGES + } + } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/DefaultRoomService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/DefaultRoomService.kt index bd63ba480e..989c8cb788 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/DefaultRoomService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/DefaultRoomService.kt @@ -109,8 +109,8 @@ internal class DefaultRoomService @Inject constructor( return roomSummaryDataSource.getFilteredPagedRoomSummariesLive(queryParams, pagedListConfig) } - override fun getNotificationCountForRooms(queryParams: RoomSummaryQueryParams): RoomAggregateNotificationCount { - return roomSummaryDataSource.getNotificationCountForRooms(queryParams) + override fun getNotificationCountForRooms(queryParams: RoomSummaryQueryParams, preferenceProvider: RoomSummary.RoomSummaryPreferenceProvider): RoomAggregateNotificationCount { + return roomSummaryDataSource.getNotificationCountForRooms(queryParams, preferenceProvider) } override fun getBreadcrumbs(queryParams: RoomSummaryQueryParams): List { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryDataSource.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryDataSource.kt index e0458a2579..6fce67d2ba 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryDataSource.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryDataSource.kt @@ -147,14 +147,14 @@ internal class RoomSummaryDataSource @Inject constructor(@SessionDatabase privat } } - fun getNotificationCountForRooms(queryParams: RoomSummaryQueryParams): RoomAggregateNotificationCount { + fun getNotificationCountForRooms(queryParams: RoomSummaryQueryParams, preferenceProvider: RoomSummary.RoomSummaryPreferenceProvider): RoomAggregateNotificationCount { var notificationCount: RoomAggregateNotificationCount? = null monarchy.doWithRealm { realm -> val roomSummariesQuery = roomSummariesQuery(realm, queryParams) val notifCount = roomSummariesQuery.sum(RoomSummaryEntityFields.NOTIFICATION_COUNT).toInt() val highlightCount = roomSummariesQuery.sum(RoomSummaryEntityFields.HIGHLIGHT_COUNT).toInt() // TODO-SC-merge: respect setting for selecting right field here (HAS_UNREAD_CONTENT_MESSAGES, HAS_UNREAD_MESSAGES, HAS_UNREAD_ORIGINAL_CONTENT_MESSAGES) - val unreadCount = roomSummariesQuery(realm, queryParams).equalTo(RoomSummaryEntityFields.HAS_UNREAD_ORIGINAL_CONTENT_MESSAGES, true).count().toInt() + val unreadCount = if (preferenceProvider.shouldShowUnimportantCounterBadge()) roomSummariesQuery(realm, queryParams).equalTo(preferenceProvider.getUnreadRoomSummaryField(false), true).count().toInt() else 0 val markedUnreadCount = roomSummariesQuery(realm, queryParams).equalTo(RoomSummaryEntityFields.MARKED_UNREAD, true).count().toInt() notificationCount = RoomAggregateNotificationCount( notifCount, diff --git a/vector/src/main/java/im/vector/app/features/home/HomeDetailViewModel.kt b/vector/src/main/java/im/vector/app/features/home/HomeDetailViewModel.kt index c87b19f0e6..ceead1749e 100644 --- a/vector/src/main/java/im/vector/app/features/home/HomeDetailViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/HomeDetailViewModel.kt @@ -28,6 +28,7 @@ import im.vector.app.core.platform.EmptyViewEvents import im.vector.app.core.platform.VectorViewModel import im.vector.app.core.resources.StringProvider import im.vector.app.features.grouplist.SelectedGroupDataSource +import im.vector.app.features.home.room.ScSdkPreferences import im.vector.app.features.ui.UiStateRepository import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -49,6 +50,7 @@ class HomeDetailViewModel @AssistedInject constructor(@Assisted initialState: Ho private val session: Session, private val uiStateRepository: UiStateRepository, private val selectedGroupStore: SelectedGroupDataSource, + private val scSdkPreferences: ScSdkPreferences, private val stringProvider: StringProvider) : VectorViewModel(initialState) { @@ -167,14 +169,16 @@ class HomeDetailViewModel @AssistedInject constructor(@Assisted initialState: Ho roomSummaryQueryParams { memberships = listOf(Membership.JOIN) roomCategoryFilter = RoomCategoryFilter.ONLY_DM - } + }, + scSdkPreferences ) val otherRooms = session.getNotificationCountForRooms( roomSummaryQueryParams { memberships = listOf(Membership.JOIN) roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS - } + }, + scSdkPreferences ) setState { diff --git a/vector/src/main/java/im/vector/app/features/home/room/ScSdkPreferences.kt b/vector/src/main/java/im/vector/app/features/home/room/ScSdkPreferences.kt index 21341b8e37..d20f0b8cad 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/ScSdkPreferences.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/ScSdkPreferences.kt @@ -12,4 +12,8 @@ class ScSdkPreferences @Inject constructor(private val vectorPreferences: Vector override fun getUnreadKind(isDirect: Boolean): Int { return vectorPreferences?.roomUnreadKind(isDirect) ?: RoomSummary.UNREAD_KIND_FULL } + + override fun shouldShowUnimportantCounterBadge(): Boolean { + return vectorPreferences?.shouldShowUnimportantCounterBadge() ?: false + } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt index 21c03a9c67..0e7944b148 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt @@ -16,7 +16,6 @@ package im.vector.app.features.home.room.list -import android.content.Context import androidx.annotation.StringRes import androidx.lifecycle.viewModelScope import com.airbnb.mvrx.FragmentViewModelContext @@ -27,7 +26,7 @@ import im.vector.app.core.extensions.exhaustive import im.vector.app.core.platform.VectorViewModel import im.vector.app.core.resources.StringProvider import im.vector.app.features.home.RoomListDisplayMode -import im.vector.app.features.settings.VectorPreferences +import im.vector.app.features.home.room.ScSdkPreferences import io.reactivex.schedulers.Schedulers import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -51,11 +50,10 @@ import javax.inject.Inject class RoomListViewModel @Inject constructor( initialState: RoomListViewState, private val session: Session, + private val scSdkPreferences: ScSdkPreferences, private val stringProvider: StringProvider ) : VectorViewModel(initialState) { - private var vectorPreferences: VectorPreferences? = null - interface Factory { fun create(initialState: RoomListViewState): RoomListViewModel } @@ -213,7 +211,7 @@ class RoomListViewModel @Inject constructor( .subscribe { sections.find { it.sectionName == name } ?.notificationCount - ?.postValue(session.getNotificationCountForRooms(roomQueryParams)) + ?.postValue(session.getNotificationCountForRooms(roomQueryParams, scSdkPreferences)) } .disposeOnClear() diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModelFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModelFactory.kt index d36bc45ab6..34d5041a1c 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModelFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModelFactory.kt @@ -17,11 +17,13 @@ package im.vector.app.features.home.room.list import im.vector.app.core.resources.StringProvider +import im.vector.app.features.home.room.ScSdkPreferences import org.matrix.android.sdk.api.session.Session import javax.inject.Inject import javax.inject.Provider class RoomListViewModelFactory @Inject constructor(private val session: Provider, + private val scSdkPreferences: ScSdkPreferences, private val stringProvider: StringProvider) : RoomListViewModel.Factory { @@ -29,6 +31,7 @@ class RoomListViewModelFactory @Inject constructor(private val session: Provider return RoomListViewModel( initialState, session.get(), + scSdkPreferences, stringProvider ) }