Restore setting functionality for unimportant unread type and count
Change-Id: Ied403f8fad4a7fa4e9dd1422c9ca08690183c1b1
This commit is contained in:
parent
04c0d7c121
commit
20e185ef48
|
@ -196,7 +196,7 @@ interface RoomService {
|
||||||
/**
|
/**
|
||||||
* TODO Doc
|
* TODO Doc
|
||||||
*/
|
*/
|
||||||
fun getNotificationCountForRooms(queryParams: RoomSummaryQueryParams): RoomAggregateNotificationCount
|
fun getNotificationCountForRooms(queryParams: RoomSummaryQueryParams, preferenceProvider: RoomSummary.RoomSummaryPreferenceProvider): RoomAggregateNotificationCount
|
||||||
|
|
||||||
private val defaultPagedListConfig
|
private val defaultPagedListConfig
|
||||||
get() = PagedList.Config.Builder()
|
get() = PagedList.Config.Builder()
|
||||||
|
|
|
@ -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.send.UserDraft
|
||||||
import org.matrix.android.sdk.api.session.room.sender.SenderInfo
|
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.api.session.room.timeline.TimelineEvent
|
||||||
|
import org.matrix.android.sdk.internal.database.model.RoomSummaryEntityFields
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class holds some data of a room.
|
* This class holds some data of a room.
|
||||||
|
@ -134,5 +135,13 @@ data class RoomSummary constructor(
|
||||||
// SC addition
|
// SC addition
|
||||||
interface RoomSummaryPreferenceProvider {
|
interface RoomSummaryPreferenceProvider {
|
||||||
fun getUnreadKind(isDirect: Boolean): Int
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,8 +109,8 @@ internal class DefaultRoomService @Inject constructor(
|
||||||
return roomSummaryDataSource.getFilteredPagedRoomSummariesLive(queryParams, pagedListConfig)
|
return roomSummaryDataSource.getFilteredPagedRoomSummariesLive(queryParams, pagedListConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getNotificationCountForRooms(queryParams: RoomSummaryQueryParams): RoomAggregateNotificationCount {
|
override fun getNotificationCountForRooms(queryParams: RoomSummaryQueryParams, preferenceProvider: RoomSummary.RoomSummaryPreferenceProvider): RoomAggregateNotificationCount {
|
||||||
return roomSummaryDataSource.getNotificationCountForRooms(queryParams)
|
return roomSummaryDataSource.getNotificationCountForRooms(queryParams, preferenceProvider)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getBreadcrumbs(queryParams: RoomSummaryQueryParams): List<RoomSummary> {
|
override fun getBreadcrumbs(queryParams: RoomSummaryQueryParams): List<RoomSummary> {
|
||||||
|
|
|
@ -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
|
var notificationCount: RoomAggregateNotificationCount? = null
|
||||||
monarchy.doWithRealm { realm ->
|
monarchy.doWithRealm { realm ->
|
||||||
val roomSummariesQuery = roomSummariesQuery(realm, queryParams)
|
val roomSummariesQuery = roomSummariesQuery(realm, queryParams)
|
||||||
val notifCount = roomSummariesQuery.sum(RoomSummaryEntityFields.NOTIFICATION_COUNT).toInt()
|
val notifCount = roomSummariesQuery.sum(RoomSummaryEntityFields.NOTIFICATION_COUNT).toInt()
|
||||||
val highlightCount = roomSummariesQuery.sum(RoomSummaryEntityFields.HIGHLIGHT_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)
|
// 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()
|
val markedUnreadCount = roomSummariesQuery(realm, queryParams).equalTo(RoomSummaryEntityFields.MARKED_UNREAD, true).count().toInt()
|
||||||
notificationCount = RoomAggregateNotificationCount(
|
notificationCount = RoomAggregateNotificationCount(
|
||||||
notifCount,
|
notifCount,
|
||||||
|
|
|
@ -28,6 +28,7 @@ import im.vector.app.core.platform.EmptyViewEvents
|
||||||
import im.vector.app.core.platform.VectorViewModel
|
import im.vector.app.core.platform.VectorViewModel
|
||||||
import im.vector.app.core.resources.StringProvider
|
import im.vector.app.core.resources.StringProvider
|
||||||
import im.vector.app.features.grouplist.SelectedGroupDataSource
|
import im.vector.app.features.grouplist.SelectedGroupDataSource
|
||||||
|
import im.vector.app.features.home.room.ScSdkPreferences
|
||||||
import im.vector.app.features.ui.UiStateRepository
|
import im.vector.app.features.ui.UiStateRepository
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
@ -49,6 +50,7 @@ class HomeDetailViewModel @AssistedInject constructor(@Assisted initialState: Ho
|
||||||
private val session: Session,
|
private val session: Session,
|
||||||
private val uiStateRepository: UiStateRepository,
|
private val uiStateRepository: UiStateRepository,
|
||||||
private val selectedGroupStore: SelectedGroupDataSource,
|
private val selectedGroupStore: SelectedGroupDataSource,
|
||||||
|
private val scSdkPreferences: ScSdkPreferences,
|
||||||
private val stringProvider: StringProvider)
|
private val stringProvider: StringProvider)
|
||||||
: VectorViewModel<HomeDetailViewState, HomeDetailAction, EmptyViewEvents>(initialState) {
|
: VectorViewModel<HomeDetailViewState, HomeDetailAction, EmptyViewEvents>(initialState) {
|
||||||
|
|
||||||
|
@ -167,14 +169,16 @@ class HomeDetailViewModel @AssistedInject constructor(@Assisted initialState: Ho
|
||||||
roomSummaryQueryParams {
|
roomSummaryQueryParams {
|
||||||
memberships = listOf(Membership.JOIN)
|
memberships = listOf(Membership.JOIN)
|
||||||
roomCategoryFilter = RoomCategoryFilter.ONLY_DM
|
roomCategoryFilter = RoomCategoryFilter.ONLY_DM
|
||||||
}
|
},
|
||||||
|
scSdkPreferences
|
||||||
)
|
)
|
||||||
|
|
||||||
val otherRooms = session.getNotificationCountForRooms(
|
val otherRooms = session.getNotificationCountForRooms(
|
||||||
roomSummaryQueryParams {
|
roomSummaryQueryParams {
|
||||||
memberships = listOf(Membership.JOIN)
|
memberships = listOf(Membership.JOIN)
|
||||||
roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
|
roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
|
||||||
}
|
},
|
||||||
|
scSdkPreferences
|
||||||
)
|
)
|
||||||
|
|
||||||
setState {
|
setState {
|
||||||
|
|
|
@ -12,4 +12,8 @@ class ScSdkPreferences @Inject constructor(private val vectorPreferences: Vector
|
||||||
override fun getUnreadKind(isDirect: Boolean): Int {
|
override fun getUnreadKind(isDirect: Boolean): Int {
|
||||||
return vectorPreferences?.roomUnreadKind(isDirect) ?: RoomSummary.UNREAD_KIND_FULL
|
return vectorPreferences?.roomUnreadKind(isDirect) ?: RoomSummary.UNREAD_KIND_FULL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun shouldShowUnimportantCounterBadge(): Boolean {
|
||||||
|
return vectorPreferences?.shouldShowUnimportantCounterBadge() ?: false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
package im.vector.app.features.home.room.list
|
package im.vector.app.features.home.room.list
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
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.platform.VectorViewModel
|
||||||
import im.vector.app.core.resources.StringProvider
|
import im.vector.app.core.resources.StringProvider
|
||||||
import im.vector.app.features.home.RoomListDisplayMode
|
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 io.reactivex.schedulers.Schedulers
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
@ -51,11 +50,10 @@ import javax.inject.Inject
|
||||||
class RoomListViewModel @Inject constructor(
|
class RoomListViewModel @Inject constructor(
|
||||||
initialState: RoomListViewState,
|
initialState: RoomListViewState,
|
||||||
private val session: Session,
|
private val session: Session,
|
||||||
|
private val scSdkPreferences: ScSdkPreferences,
|
||||||
private val stringProvider: StringProvider
|
private val stringProvider: StringProvider
|
||||||
) : VectorViewModel<RoomListViewState, RoomListAction, RoomListViewEvents>(initialState) {
|
) : VectorViewModel<RoomListViewState, RoomListAction, RoomListViewEvents>(initialState) {
|
||||||
|
|
||||||
private var vectorPreferences: VectorPreferences? = null
|
|
||||||
|
|
||||||
interface Factory {
|
interface Factory {
|
||||||
fun create(initialState: RoomListViewState): RoomListViewModel
|
fun create(initialState: RoomListViewState): RoomListViewModel
|
||||||
}
|
}
|
||||||
|
@ -213,7 +211,7 @@ class RoomListViewModel @Inject constructor(
|
||||||
.subscribe {
|
.subscribe {
|
||||||
sections.find { it.sectionName == name }
|
sections.find { it.sectionName == name }
|
||||||
?.notificationCount
|
?.notificationCount
|
||||||
?.postValue(session.getNotificationCountForRooms(roomQueryParams))
|
?.postValue(session.getNotificationCountForRooms(roomQueryParams, scSdkPreferences))
|
||||||
}
|
}
|
||||||
.disposeOnClear()
|
.disposeOnClear()
|
||||||
|
|
||||||
|
|
|
@ -17,11 +17,13 @@
|
||||||
package im.vector.app.features.home.room.list
|
package im.vector.app.features.home.room.list
|
||||||
|
|
||||||
import im.vector.app.core.resources.StringProvider
|
import im.vector.app.core.resources.StringProvider
|
||||||
|
import im.vector.app.features.home.room.ScSdkPreferences
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Provider
|
import javax.inject.Provider
|
||||||
|
|
||||||
class RoomListViewModelFactory @Inject constructor(private val session: Provider<Session>,
|
class RoomListViewModelFactory @Inject constructor(private val session: Provider<Session>,
|
||||||
|
private val scSdkPreferences: ScSdkPreferences,
|
||||||
private val stringProvider: StringProvider)
|
private val stringProvider: StringProvider)
|
||||||
: RoomListViewModel.Factory {
|
: RoomListViewModel.Factory {
|
||||||
|
|
||||||
|
@ -29,6 +31,7 @@ class RoomListViewModelFactory @Inject constructor(private val session: Provider
|
||||||
return RoomListViewModel(
|
return RoomListViewModel(
|
||||||
initialState,
|
initialState,
|
||||||
session.get(),
|
session.get(),
|
||||||
|
scSdkPreferences,
|
||||||
stringProvider
|
stringProvider
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue