Restore setting functionality for unimportant unread type and count

Change-Id: Ied403f8fad4a7fa4e9dd1422c9ca08690183c1b1
This commit is contained in:
SpiritCroc 2021-04-14 13:55:44 +02:00
parent 04c0d7c121
commit 20e185ef48
8 changed files with 30 additions and 12 deletions

View File

@ -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()

View File

@ -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
}
}
}
}

View File

@ -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<RoomSummary> {

View File

@ -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,

View File

@ -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<HomeDetailViewState, HomeDetailAction, EmptyViewEvents>(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 {

View File

@ -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
}
}

View File

@ -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<RoomListViewState, RoomListAction, RoomListViewEvents>(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()

View File

@ -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<Session>,
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
)
}