Refactor SC SDK preferences

- Fix message preview setting
- Fixes some issue with chats being marked as unread
- Prepare for more SDK preferences

Change-Id: I7522624175c00ddf32c1bbec2a985ff34eb8d317
This commit is contained in:
SpiritCroc 2021-10-22 10:34:06 +02:00
parent c1b1d855d4
commit a6f809c613
26 changed files with 137 additions and 126 deletions

View File

@ -0,0 +1,19 @@
package de.spiritcroc.matrixsdk
/**
* Allows us to set some variables globally where Element hadn't planned
* to make them available, to save us some work hunting down the
* many indirections of the Element code, but instead allowing direct access
* from the Matrix SDK.
*/
object StaticScSdkHelper {
var scSdkPreferenceProvider: ScSdkPreferenceProvider? = null
interface ScSdkPreferenceProvider {
// RoomSummary preferences
fun roomUnreadKind(isDirect: Boolean): Int
fun aggregateUnreadRoomCounts(): Boolean
}
}

View File

@ -210,7 +210,7 @@ interface RoomService {
/**
* TODO Doc
*/
fun getNotificationCountForRooms(queryParams: RoomSummaryQueryParams, preferenceProvider: RoomSummary.RoomSummaryPreferenceProvider): RoomAggregateNotificationCount
fun getNotificationCountForRooms(queryParams: RoomSummaryQueryParams): RoomAggregateNotificationCount
private val defaultPagedListConfig
get() = PagedList.Config.Builder()

View File

@ -16,13 +16,14 @@
package org.matrix.android.sdk.api.session.room.model
import de.spiritcroc.matrixsdk.StaticScSdkHelper
import org.matrix.android.sdk.api.crypto.RoomEncryptionTrustLevel
import org.matrix.android.sdk.api.session.presence.model.UserPresence
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
import timber.log.Timber
/**
* This class holds some data of a room.
@ -105,33 +106,37 @@ data class RoomSummary(
val canStartCall: Boolean
get() = joinedMembersCount == 2
fun scIsUnread(preferenceProvider: RoomSummaryPreferenceProvider?): Boolean {
return markedUnread || scHasUnreadMessages(preferenceProvider)
fun scIsUnread(): Boolean {
return markedUnread || scHasUnreadMessages()
}
fun scHasUnreadMessages(preferenceProvider: RoomSummaryPreferenceProvider?): Boolean {
// Keep sync with RoomSummary.scHasUnreadMessages!
fun scHasUnreadMessages(): Boolean {
val preferenceProvider = StaticScSdkHelper.scSdkPreferenceProvider
if (preferenceProvider == null) {
// Fallback to default
return hasUnreadMessages
return hasUnreadOriginalContentMessages
}
return when(preferenceProvider.getUnreadKind(isDirect)) {
return when(preferenceProvider.roomUnreadKind(isDirect)) {
UNREAD_KIND_ORIGINAL_CONTENT -> hasUnreadOriginalContentMessages
UNREAD_KIND_CONTENT -> hasUnreadContentMessages
// UNREAD_KIND_FULL
else -> hasUnreadMessages
UNREAD_KIND_CONTENT -> hasUnreadContentMessages
UNREAD_KIND_FULL -> hasUnreadMessages
else -> hasUnreadOriginalContentMessages
}
}
fun scLatestPreviewableEvent(preferenceProvider: RoomSummaryPreferenceProvider?): TimelineEvent? {
// Keep sync with RoomSummaryEntity.scLatestPreviewableEvent!
fun scLatestPreviewableEvent(): TimelineEvent? {
val preferenceProvider = StaticScSdkHelper.scSdkPreferenceProvider
if (preferenceProvider == null) {
// Fallback to default
return latestPreviewableOriginalContentEvent
}
return when(preferenceProvider.getUnreadKind(isDirect)) {
return when(preferenceProvider.roomUnreadKind(isDirect)) {
UNREAD_KIND_ORIGINAL_CONTENT -> latestPreviewableOriginalContentEvent
UNREAD_KIND_CONTENT -> latestPreviewableContentEvent
// UNREAD_KIND_DEFAULT
else -> latestPreviewableOriginalContentEvent
UNREAD_KIND_CONTENT -> latestPreviewableContentEvent
UNREAD_KIND_FULL -> latestPreviewableEvent
else -> latestPreviewableOriginalContentEvent
}
}
@ -156,17 +161,4 @@ data class RoomSummary(
const val UNREAD_KIND_CONTENT = 1
const val UNREAD_KIND_ORIGINAL_CONTENT = 2
}
// SC addition
interface RoomSummaryPreferenceProvider {
fun getUnreadKind(isDirect: Boolean): Int
fun aggregateUnreadRoomCounts(): 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

@ -16,6 +16,7 @@
package org.matrix.android.sdk.internal.database.model
import de.spiritcroc.matrixsdk.StaticScSdkHelper
import io.realm.RealmList
import io.realm.RealmObject
import io.realm.annotations.Index
@ -27,7 +28,9 @@ import org.matrix.android.sdk.api.session.room.model.RoomJoinRules
import org.matrix.android.sdk.api.session.room.model.RoomSummary
import org.matrix.android.sdk.api.session.room.model.VersioningState
import org.matrix.android.sdk.api.session.room.model.tag.RoomTag
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
import org.matrix.android.sdk.internal.database.model.presence.UserPresenceEntity
import timber.log.Timber
internal open class RoomSummaryEntity(
@PrimaryKey var roomId: String = "",
@ -342,4 +345,36 @@ internal open class RoomSummaryEntity(
}
}
companion object
// Keep sync with RoomSummary.scHasUnreadMessages!
fun scHasUnreadMessages(): Boolean {
val preferenceProvider = StaticScSdkHelper.scSdkPreferenceProvider
if (preferenceProvider == null) {
// Fallback to default
return hasUnreadOriginalContentMessages
}
return when(preferenceProvider.roomUnreadKind(isDirect)) {
RoomSummary.UNREAD_KIND_ORIGINAL_CONTENT -> hasUnreadOriginalContentMessages
RoomSummary.UNREAD_KIND_CONTENT -> hasUnreadContentMessages
RoomSummary.UNREAD_KIND_FULL -> hasUnreadMessages
else -> hasUnreadOriginalContentMessages
}
}
// Keep sync with RoomSummary.scLatestPreviewableEvent!
fun scLatestPreviewableEvent(): TimelineEventEntity? {
val preferenceProvider = StaticScSdkHelper.scSdkPreferenceProvider
if (preferenceProvider == null) {
// Fallback to default
Timber.w("No preference provider set!")
return latestPreviewableOriginalContentEvent
}
return when(preferenceProvider.roomUnreadKind(isDirect)) {
RoomSummary.UNREAD_KIND_ORIGINAL_CONTENT -> latestPreviewableOriginalContentEvent
RoomSummary.UNREAD_KIND_CONTENT -> latestPreviewableContentEvent
RoomSummary.UNREAD_KIND_FULL -> latestPreviewableEvent
else -> latestPreviewableOriginalContentEvent
}
}
}

View File

@ -105,8 +105,8 @@ internal class DefaultRoomService @Inject constructor(
return roomSummaryDataSource.getUpdatablePagedRoomSummariesLive(queryParams, pagedListConfig, sortOrder)
}
override fun getNotificationCountForRooms(queryParams: RoomSummaryQueryParams, preferenceProvider: RoomSummary.RoomSummaryPreferenceProvider): RoomAggregateNotificationCount {
return roomSummaryDataSource.getNotificationCountForRooms(queryParams, preferenceProvider)
override fun getNotificationCountForRooms(queryParams: RoomSummaryQueryParams): RoomAggregateNotificationCount {
return roomSummaryDataSource.getNotificationCountForRooms(queryParams)
}
override fun getBreadcrumbs(queryParams: RoomSummaryQueryParams): List<RoomSummary> {

View File

@ -23,6 +23,7 @@ import androidx.lifecycle.Transformations
import androidx.paging.LivePagedListBuilder
import androidx.paging.PagedList
import com.zhuinden.monarchy.Monarchy
import de.spiritcroc.matrixsdk.StaticScSdkHelper
import io.realm.Realm
import io.realm.RealmQuery
import io.realm.Sort
@ -43,7 +44,6 @@ import org.matrix.android.sdk.api.session.space.SpaceSummaryQueryParams
import org.matrix.android.sdk.api.util.Optional
import org.matrix.android.sdk.api.util.toOptional
import org.matrix.android.sdk.internal.database.mapper.RoomSummaryMapper
import org.matrix.android.sdk.internal.database.model.RoomEntityFields
import org.matrix.android.sdk.internal.database.model.RoomSummaryEntity
import org.matrix.android.sdk.internal.database.model.RoomSummaryEntityFields
import org.matrix.android.sdk.internal.database.query.findByAlias
@ -225,12 +225,13 @@ internal class RoomSummaryDataSource @Inject constructor(@SessionDatabase privat
}
}
fun getNotificationCountForRooms(queryParams: RoomSummaryQueryParams, preferenceProvider: RoomSummary.RoomSummaryPreferenceProvider): RoomAggregateNotificationCount {
fun getNotificationCountForRooms(queryParams: RoomSummaryQueryParams): RoomAggregateNotificationCount {
val preferenceProvider = StaticScSdkHelper.scSdkPreferenceProvider
var notificationCount: RoomAggregateNotificationCount? = null
monarchy.doWithRealm { realm ->
val roomSummariesQuery = roomSummariesQuery(realm, queryParams)
val markedUnreadCount = roomSummariesQuery(realm, queryParams).equalTo(RoomSummaryEntityFields.MARKED_UNREAD, true).count().toInt()
notificationCount = if (preferenceProvider.aggregateUnreadRoomCounts()) {
notificationCount = if (preferenceProvider?.aggregateUnreadRoomCounts() != false) {
// Count chats
val notifCount = roomSummariesQuery.greaterThan(RoomSummaryEntityFields.NOTIFICATION_COUNT, 0).count().toInt()
val highlightCount = roomSummariesQuery.greaterThan(RoomSummaryEntityFields.HIGHLIGHT_COUNT, 0).count().toInt()
@ -238,7 +239,7 @@ internal class RoomSummaryDataSource @Inject constructor(@SessionDatabase privat
// Preferred since MSC 2654
roomSummariesQuery.greaterThan(RoomSummaryEntityFields.UNREAD_COUNT, 0).count().toInt(),
// TODO-SC-merge: properly use dm/non-dm flag? (note that this will be likely overwritten either way by above field from MSC 2654)
roomSummariesQuery(realm, queryParams).equalTo(preferenceProvider.getUnreadRoomSummaryField(false), true).count().toInt()
roomSummariesQuery(realm, queryParams).equalTo(getUnreadRoomSummaryField(false), true).count().toInt()
)
RoomAggregateNotificationCount(
notifCount,
@ -254,7 +255,7 @@ internal class RoomSummaryDataSource @Inject constructor(@SessionDatabase privat
// Preferred since MSC 2654
roomSummariesQuery.sum(RoomSummaryEntityFields.UNREAD_COUNT).toInt(),
// TODO-SC-merge: properly use dm/non-dm flag? (note that this will be likely overwritten either way by above field from MSC 2654)
roomSummariesQuery(realm, queryParams).equalTo(preferenceProvider.getUnreadRoomSummaryField(false), true).count().toInt()
roomSummariesQuery(realm, queryParams).equalTo(getUnreadRoomSummaryField(false), true).count().toInt()
)
RoomAggregateNotificationCount(
notifCount,
@ -456,4 +457,13 @@ internal class RoomSummaryDataSource @Inject constructor(@SessionDatabase privat
}
}
}
fun getUnreadRoomSummaryField(isDirect: Boolean): String {
return when(StaticScSdkHelper.scSdkPreferenceProvider?.roomUnreadKind(isDirect)) {
RoomSummary.UNREAD_KIND_ORIGINAL_CONTENT -> RoomSummaryEntityFields.HAS_UNREAD_ORIGINAL_CONTENT_MESSAGES
RoomSummary.UNREAD_KIND_CONTENT -> RoomSummaryEntityFields.HAS_UNREAD_CONTENT_MESSAGES
RoomSummary.UNREAD_KIND_FULL -> RoomSummaryEntityFields.HAS_UNREAD_MESSAGES
else /* null */ -> RoomSummaryEntityFields.HAS_UNREAD_ORIGINAL_CONTENT_MESSAGES
}
}
}

View File

@ -134,7 +134,12 @@ internal class RoomSummaryUpdater @Inject constructor(
val latestPreviewableContentEvent = RoomSummaryEventsHelper.getLatestPreviewableEvent(realm, roomId)
val latestPreviewableOriginalContentEvent = RoomSummaryEventsHelper.getLatestPreviewableEventScOriginalContent(realm, roomId)
val lastActivityFromEvent = latestPreviewableOriginalContentEvent?.root?.originServerTs
roomSummaryEntity.latestPreviewableEvent = latestPreviewableEvent
roomSummaryEntity.latestPreviewableContentEvent = latestPreviewableContentEvent
roomSummaryEntity.latestPreviewableOriginalContentEvent = latestPreviewableOriginalContentEvent
val scLatestPreviewableEvent = roomSummaryEntity.scLatestPreviewableEvent()
val lastActivityFromEvent = scLatestPreviewableEvent?.root?.originServerTs
if (lastActivityFromEvent != null) {
roomSummaryEntity.lastActivityTime = lastActivityFromEvent
}
@ -156,9 +161,6 @@ internal class RoomSummaryUpdater @Inject constructor(
roomSummaryEntity.name = ContentMapper.map(lastNameEvent?.content).toModel<RoomNameContent>()?.name
roomSummaryEntity.topic = ContentMapper.map(lastTopicEvent?.content).toModel<RoomTopicContent>()?.topic
roomSummaryEntity.joinRules = ContentMapper.map(joinRulesEvent?.content).toModel<RoomJoinRulesContent>()?.joinRules
roomSummaryEntity.latestPreviewableEvent = latestPreviewableEvent
roomSummaryEntity.latestPreviewableContentEvent = latestPreviewableContentEvent
roomSummaryEntity.latestPreviewableOriginalContentEvent = latestPreviewableOriginalContentEvent
roomSummaryEntity.canonicalAlias = ContentMapper.map(lastCanonicalAliasEvent?.content).toModel<RoomCanonicalAliasContent>()
?.canonicalAlias
@ -203,7 +205,7 @@ internal class RoomSummaryUpdater @Inject constructor(
fun updateRoomPreviews(realm: Realm) {
RoomSummaryEntity.where(realm).findAll().forEach { entity ->
val previewEvent = entity.latestPreviewableOriginalContentEvent
val previewEvent = entity.scLatestPreviewableEvent()
val root = previewEvent?.root
if (root?.type == EventType.ENCRYPTED && root.decryptionResultJson == null) {
Timber.v("Retry decrypt ${previewEvent.eventId}")
@ -406,7 +408,8 @@ internal class RoomSummaryUpdater @Inject constructor(
// we need also to filter DMs...
// it's more annoying as based on if the other members belong the space or not
/*
if (false /*TODO setting*/) {
// Wrong indention for upstream merge-ability
RoomSummaryEntity.where(realm)
.equalTo(RoomSummaryEntityFields.IS_DIRECT, true)
.process(RoomSummaryEntityFields.MEMBERSHIP_STR, Membership.activeMemberships())
@ -431,7 +434,7 @@ internal class RoomSummaryUpdater @Inject constructor(
}
// Timber.v("## SPACES: flatten of ${dmRoom.otherMemberIds.joinToString(",")} is ${dmRoom.flattenParentIds}")
}
*/
}
// Maybe a good place to count the number of notifications for spaces?

View File

@ -174,7 +174,7 @@ internal class TokenChunkEventPersistor @Inject constructor(@SessionDatabase pri
currentChunk.isLastForward = true
currentLastForwardChunk?.deleteOnCascade(deleteStateEvents = false, canDeleteRoot = false)
RoomSummaryEntity.where(realm, roomId).findFirst()?.apply {
latestPreviewableEvent = RoomSummaryEventsHelper.getLatestPreviewableEvent(realm, roomId)
latestPreviewableEvent = RoomSummaryEventsHelper.getLatestPreviewableEventScAll(realm, roomId)
latestPreviewableContentEvent = RoomSummaryEventsHelper.getLatestPreviewableEvent(realm, roomId)
latestPreviewableOriginalContentEvent = RoomSummaryEventsHelper.getLatestPreviewableEventScOriginalContent(realm, roomId)
}
@ -240,9 +240,11 @@ internal class TokenChunkEventPersistor @Inject constructor(@SessionDatabase pri
it.deleteOnCascade(deleteStateEvents = false, canDeleteRoot = false)
}
val roomSummaryEntity = RoomSummaryEntity.getOrCreate(realm, roomId)
val shouldUpdateSummary = roomSummaryEntity.latestPreviewableOriginalContentEvent == null ||
val shouldUpdateSummary = roomSummaryEntity.scLatestPreviewableEvent() == null ||
(chunksToDelete.isNotEmpty() && currentChunk.isLastForward && direction == PaginationDirection.FORWARDS)
if (shouldUpdateSummary) {
roomSummaryEntity.latestPreviewableEvent = RoomSummaryEventsHelper.getLatestPreviewableEventScAll(realm, roomId)
roomSummaryEntity.latestPreviewableContentEvent = RoomSummaryEventsHelper.getLatestPreviewableEvent(realm, roomId)
roomSummaryEntity.latestPreviewableOriginalContentEvent = RoomSummaryEventsHelper.getLatestPreviewableEventScOriginalContent(realm, roomId)
}
if (currentChunk.isValid) {

View File

@ -39,6 +39,7 @@ import com.facebook.stetho.Stetho
import com.gabrielittner.threetenbp.LazyThreeTen
import com.vanniktech.emoji.EmojiManager
import com.vanniktech.emoji.google.GoogleEmojiProvider
import de.spiritcroc.matrixsdk.StaticScSdkHelper
import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.di.DaggerVectorComponent
import im.vector.app.core.di.HasVectorInjector
@ -124,6 +125,9 @@ class VectorApplication :
vectorUncaughtExceptionHandler.activate(this)
rxConfig.setupRxPlugin()
// SC SDK helper initialization
StaticScSdkHelper.scSdkPreferenceProvider = vectorPreferences
// Remove Log handler statically added by Jitsi
Timber.forest()
.filterIsInstance(JitsiMeetDefaultLogHandler::class.java)

View File

@ -23,7 +23,6 @@ import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isVisible
import androidx.core.view.iterator
import androidx.fragment.app.Fragment
import com.airbnb.mvrx.activityViewModel
import com.airbnb.mvrx.fragmentViewModel
@ -88,7 +87,7 @@ class HomeDetailFragment @Inject constructor(
// When this changes, restart the activity for changes to apply
private val shouldShowUnimportantCounterBadge = vectorPreferences.shouldShowUnimportantCounterBadge()
private val useAggregateCounts = vectorPreferences.useAggregateCounts()
private val useAggregateCounts = vectorPreferences.aggregateUnreadRoomCounts()
private var hasUnreadRooms = false
set(value) {
@ -216,7 +215,7 @@ class HomeDetailFragment @Inject constructor(
super.onResume()
if (vectorPreferences.shouldShowUnimportantCounterBadge() != shouldShowUnimportantCounterBadge ||
vectorPreferences.useAggregateCounts() != useAggregateCounts) {
vectorPreferences.aggregateUnreadRoomCounts() != useAggregateCounts) {
activity?.restart()
return
}

View File

@ -31,7 +31,6 @@ import im.vector.app.features.call.dialpad.DialPadLookup
import im.vector.app.features.call.lookup.CallProtocolsChecker
import im.vector.app.features.call.webrtc.WebRtcCallManager
import im.vector.app.features.createdirect.DirectRoomHelper
import im.vector.app.features.home.room.ScSdkPreferences
import im.vector.app.features.invite.AutoAcceptInvites
import im.vector.app.features.invite.showInvites
import im.vector.app.features.settings.VectorDataStore
@ -61,7 +60,6 @@ import java.util.concurrent.TimeUnit
class HomeDetailViewModel @AssistedInject constructor(@Assisted initialState: HomeDetailViewState,
private val session: Session,
private val uiStateRepository: UiStateRepository,
private val scSdkPreferences: ScSdkPreferences,
private val vectorDataStore: VectorDataStore,
private val callManager: WebRtcCallManager,
private val directRoomHelper: DirectRoomHelper,
@ -256,8 +254,7 @@ class HomeDetailViewModel @AssistedInject constructor(@Assisted initialState: Ho
memberships = listOf(Membership.JOIN)
roomCategoryFilter = RoomCategoryFilter.ONLY_DM
activeSpaceFilter = activeSpaceRoomId?.let { ActiveSpaceFilter.ActiveSpace(it) } ?: ActiveSpaceFilter.None
},
scSdkPreferences
}
)
val otherRooms = session.getNotificationCountForRooms(
@ -265,8 +262,7 @@ class HomeDetailViewModel @AssistedInject constructor(@Assisted initialState: Ho
memberships = listOf(Membership.JOIN)
roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(groupingMethod.spaceSummary?.roomId)
},
scSdkPreferences
}
)
setState {

View File

@ -29,7 +29,6 @@ import im.vector.app.RoomGroupingMethod
import im.vector.app.core.platform.EmptyAction
import im.vector.app.core.platform.EmptyViewEvents
import im.vector.app.core.platform.VectorViewModel
import im.vector.app.features.home.room.ScSdkPreferences
import im.vector.app.features.invite.AutoAcceptInvites
import im.vector.app.features.settings.VectorPreferences
import io.reactivex.Observable
@ -56,7 +55,6 @@ data class CountInfo(
class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initialState: UnreadMessagesState,
session: Session,
private val scSdkPreferences: ScSdkPreferences,
private val vectorPreferences: VectorPreferences,
appStateHandler: AppStateHandler,
private val autoAcceptInvites: AutoAcceptInvites) :
@ -95,8 +93,7 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia
roomSummaryQueryParams {
this.memberships = listOf(Membership.JOIN)
this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null)
},
scSdkPreferences
}
)
val invites = if (autoAcceptInvites.hideInvites) {
0
@ -168,8 +165,7 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia
this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null).takeIf {
!spacesShowAllRoomsInHome
} ?: ActiveSpaceFilter.None
},
scSdkPreferences
}
)
val counts = RoomAggregateNotificationCount(
@ -188,8 +184,7 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia
roomSummaryQueryParams {
this.memberships = listOf(Membership.JOIN)
this.activeSpaceFilter = ActiveSpaceFilter.None
},
scSdkPreferences
}
)
}
@ -219,7 +214,7 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia
(counts.highlightCount.takeIf { selectedSpace != null } ?: 0) +
spaceInviteCount,
unreadCount = rootCounts.fold(0, { acc, rs -> acc + (if (rs.scIsUnread(scSdkPreferences)) 1 else 0) }) +
unreadCount = rootCounts.fold(0, { acc, rs -> acc + (if (rs.scIsUnread()) 1 else 0) }) +
(counts.unreadCount.takeIf { selectedSpace != null } ?: 0) +
spaceInviteCount,
markedUnreadCount = rootCounts.fold(0, { acc, rs -> acc + (if (rs.markedUnread) 1 else 0) }) +

View File

@ -1,19 +0,0 @@
package im.vector.app.features.home.room
import android.content.Context
import im.vector.app.features.settings.VectorPreferences
import org.matrix.android.sdk.api.session.room.model.RoomSummary
import javax.inject.Inject
class ScSdkPreferences @Inject constructor(private val vectorPreferences: VectorPreferences?): RoomSummary.RoomSummaryPreferenceProvider {
constructor(context: Context?) : this(vectorPreferences = context?.let { VectorPreferences(it) })
override fun getUnreadKind(isDirect: Boolean): Int {
return vectorPreferences?.roomUnreadKind(isDirect) ?: RoomSummary.UNREAD_KIND_FULL
}
override fun aggregateUnreadRoomCounts(): Boolean {
return vectorPreferences?.useAggregateCounts() ?: true
}
}

View File

@ -19,13 +19,11 @@ package im.vector.app.features.home.room.breadcrumbs
import com.airbnb.epoxy.EpoxyController
import im.vector.app.core.epoxy.zeroItem
import im.vector.app.features.home.AvatarRenderer
import im.vector.app.features.home.room.ScSdkPreferences
import org.matrix.android.sdk.api.util.toMatrixItem
import javax.inject.Inject
class BreadcrumbsController @Inject constructor(
private val avatarRenderer: AvatarRenderer,
private val scSdkPreferences: ScSdkPreferences
private val avatarRenderer: AvatarRenderer
) : EpoxyController() {
var listener: Listener? = null
@ -63,7 +61,7 @@ class BreadcrumbsController @Inject constructor(
unreadNotificationCount(roomSummary.notificationCount)
markedUnread(roomSummary.markedUnread)
showHighlighted(roomSummary.highlightCount > 0)
hasUnreadMessage(roomSummary.scIsUnread(host.scSdkPreferences))
hasUnreadMessage(roomSummary.scIsUnread())
hasDraft(roomSummary.userDrafts.isNotEmpty())
itemClickListener {
host.listener?.onBreadcrumbClicked(roomSummary.roomId)

View File

@ -135,7 +135,6 @@ import im.vector.app.features.command.Command
import im.vector.app.features.crypto.keysbackup.restore.KeysBackupRestoreActivity
import im.vector.app.features.crypto.verification.VerificationBottomSheet
import im.vector.app.features.home.AvatarRenderer
import im.vector.app.features.home.room.ScSdkPreferences
import im.vector.app.features.home.room.detail.composer.SendMode
import im.vector.app.features.home.room.detail.composer.TextComposerAction
import im.vector.app.features.home.room.detail.composer.TextComposerView
@ -1434,7 +1433,7 @@ class RoomDetailFragment @Inject constructor(
val inviter = mainState.asyncInviter()
if (summary?.membership == Membership.JOIN) {
views.jumpToBottomView.count = summary.notificationCount
views.jumpToBottomView.drawBadge = summary.scIsUnread(ScSdkPreferences(context))
views.jumpToBottomView.drawBadge = summary.scIsUnread()
timelineEventController.update(mainState)
lazyLoadedViews.inviteView(false)?.isVisible = false
if (mainState.tombstoneEvent == null) {

View File

@ -16,19 +16,18 @@
package im.vector.app.features.home.room.list
import im.vector.app.features.home.room.ScSdkPreferences
import org.matrix.android.sdk.api.session.room.model.RoomSummary
import javax.inject.Inject
class ChronologicalRoomComparator @Inject constructor(val scSdkPreferences: ScSdkPreferences) : Comparator<RoomSummary> {
class ChronologicalRoomComparator @Inject constructor() : Comparator<RoomSummary> {
override fun compare(leftRoomSummary: RoomSummary?, rightRoomSummary: RoomSummary?): Int {
return when {
rightRoomSummary?.scLatestPreviewableEvent(scSdkPreferences)?.root == null -> -1
leftRoomSummary?.scLatestPreviewableEvent(scSdkPreferences)?.root == null -> 1
rightRoomSummary?.scLatestPreviewableEvent()?.root == null -> -1
leftRoomSummary?.scLatestPreviewableEvent()?.root == null -> 1
else -> {
val rightTimestamp = rightRoomSummary.scLatestPreviewableEvent(scSdkPreferences)?.root?.originServerTs ?: 0
val leftTimestamp = leftRoomSummary.scLatestPreviewableEvent(scSdkPreferences)?.root?.originServerTs ?: 0
val rightTimestamp = rightRoomSummary.scLatestPreviewableEvent()?.root?.originServerTs ?: 0
val leftTimestamp = leftRoomSummary.scLatestPreviewableEvent()?.root?.originServerTs ?: 0
val deltaTimestamp = rightTimestamp - leftTimestamp

View File

@ -22,7 +22,6 @@ import im.vector.app.R
import im.vector.app.RoomGroupingMethod
import im.vector.app.core.resources.StringProvider
import im.vector.app.features.home.RoomListDisplayMode
import im.vector.app.features.home.room.ScSdkPreferences
import im.vector.app.features.invite.AutoAcceptInvites
import im.vector.app.features.invite.showInvites
import io.reactivex.disposables.CompositeDisposable
@ -37,7 +36,6 @@ import org.matrix.android.sdk.rx.asObservable
class RoomListSectionBuilderGroup(
private val session: Session,
private val scSdkPreferences: ScSdkPreferences,
private val stringProvider: StringProvider,
private val appStateHandler: AppStateHandler,
private val autoAcceptInvites: AutoAcceptInvites,
@ -320,7 +318,7 @@ class RoomListSectionBuilderGroup(
.subscribe {
sections.find { it.sectionName == name }
?.notificationCount
?.postValue(session.getNotificationCountForRooms(roomQueryParams, scSdkPreferences))
?.postValue(session.getNotificationCountForRooms(roomQueryParams))
}.also {
disposables.add(it)
}

View File

@ -26,7 +26,6 @@ import im.vector.app.AppStateHandler
import im.vector.app.R
import im.vector.app.core.resources.StringProvider
import im.vector.app.features.home.RoomListDisplayMode
import im.vector.app.features.home.room.ScSdkPreferences
import im.vector.app.features.invite.AutoAcceptInvites
import im.vector.app.features.invite.showInvites
import im.vector.app.space
@ -49,7 +48,6 @@ import org.matrix.android.sdk.rx.asObservable
class RoomListSectionBuilderSpace(
private val session: Session,
private val scSdkPreferences: ScSdkPreferences,
private val stringProvider: StringProvider,
private val appStateHandler: AppStateHandler,
private val viewModelScope: CoroutineScope,
@ -504,8 +502,7 @@ class RoomListSectionBuilderSpace(
RoomAggregateNotificationCount(it.size, it.size, 0, 0)
} else {
session.getNotificationCountForRooms(
roomQueryParams.process(spaceFilterStrategy, appStateHandler.safeActiveSpaceId()),
scSdkPreferences
roomQueryParams.process(spaceFilterStrategy, appStateHandler.safeActiveSpaceId())
)
}
)

View File

@ -30,7 +30,6 @@ 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.displayname.getBestName
import im.vector.app.features.home.room.ScSdkPreferences
import im.vector.app.features.invite.AutoAcceptInvites
import im.vector.app.features.settings.VectorPreferences
import kotlinx.coroutines.Dispatchers
@ -54,7 +53,6 @@ class RoomListViewModel @Inject constructor(
private val session: Session,
private val stringProvider: StringProvider,
private val appStateHandler: AppStateHandler,
private val scSdkPreferences: ScSdkPreferences,
private val vectorPreferences: VectorPreferences,
private val autoAcceptInvites: AutoAcceptInvites
) : VectorViewModel<RoomListViewState, RoomListAction, RoomListViewEvents>(initialState) {
@ -129,7 +127,6 @@ class RoomListViewModel @Inject constructor(
private val roomListSectionBuilder = if (appStateHandler.getCurrentRoomGroupingMethod() is RoomGroupingMethod.BySpace) {
RoomListSectionBuilderSpace(
session,
scSdkPreferences,
stringProvider,
appStateHandler,
viewModelScope,
@ -143,7 +140,6 @@ class RoomListViewModel @Inject constructor(
} else {
RoomListSectionBuilderGroup(
session,
scSdkPreferences,
stringProvider,
appStateHandler,
autoAcceptInvites

View File

@ -18,7 +18,6 @@ package im.vector.app.features.home.room.list
import im.vector.app.AppStateHandler
import im.vector.app.core.resources.StringProvider
import im.vector.app.features.home.room.ScSdkPreferences
import im.vector.app.features.invite.AutoAcceptInvites
import im.vector.app.features.settings.VectorPreferences
import org.matrix.android.sdk.api.session.Session
@ -26,7 +25,6 @@ import javax.inject.Inject
import javax.inject.Provider
class RoomListViewModelFactory @Inject constructor(private val session: Provider<Session>,
private val scSdkPreferences: ScSdkPreferences,
private val appStateHandler: AppStateHandler,
private val stringProvider: StringProvider,
private val vectorPreferences: VectorPreferences,
@ -39,7 +37,6 @@ class RoomListViewModelFactory @Inject constructor(private val session: Provider
session = session.get(),
stringProvider = stringProvider,
appStateHandler = appStateHandler,
scSdkPreferences = scSdkPreferences,
vectorPreferences = vectorPreferences,
autoAcceptInvites = autoAcceptInvites
)

View File

@ -21,7 +21,6 @@ import com.airbnb.mvrx.MavericksState
import com.airbnb.mvrx.Uninitialized
import im.vector.app.RoomGroupingMethod
import im.vector.app.features.home.RoomListDisplayMode
import im.vector.app.features.home.room.ScSdkPreferences
import org.matrix.android.sdk.api.session.room.members.ChangeMembershipState
import org.matrix.android.sdk.api.session.room.model.SpaceChildInfo

View File

@ -26,7 +26,6 @@ import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.core.error.ErrorFormatter
import im.vector.app.core.resources.StringProvider
import im.vector.app.features.home.AvatarRenderer
import im.vector.app.features.home.room.ScSdkPreferences
import im.vector.app.features.home.room.detail.timeline.format.DisplayableEventFormatter
import im.vector.app.features.home.room.typing.TypingHelper
import org.matrix.android.sdk.api.session.room.members.ChangeMembershipState
@ -41,7 +40,6 @@ class RoomSummaryItemFactory @Inject constructor(private val displayableEventFor
private val stringProvider: StringProvider,
private val typingHelper: TypingHelper,
private val avatarRenderer: AvatarRenderer,
private val scSdkPreferences: ScSdkPreferences,
private val errorFormatter: ErrorFormatter) {
fun create(roomSummary: RoomSummary,
@ -114,7 +112,7 @@ class RoomSummaryItemFactory @Inject constructor(private val displayableEventFor
val showSelected = selectedRoomIds.contains(roomSummary.roomId)
var latestFormattedEvent: CharSequence = ""
var latestEventTime: CharSequence = ""
val latestEvent = roomSummary.scLatestPreviewableEvent(scSdkPreferences)
val latestEvent = roomSummary.scLatestPreviewableEvent()
if (latestEvent != null) {
latestFormattedEvent = displayableEventFormatter.format(latestEvent, roomSummary.isDirect, roomSummary.isDirect.not())
latestEventTime = dateFormatter.format(latestEvent.root.originServerTs, DateFormatKind.ROOM_LIST)
@ -137,7 +135,7 @@ class RoomSummaryItemFactory @Inject constructor(private val displayableEventFor
.showSelected(showSelected)
.hasFailedSending(roomSummary.hasFailedSending)
.unreadNotificationCount(unreadCount)
.hasUnreadMessage(roomSummary.scIsUnread(scSdkPreferences))
.hasUnreadMessage(roomSummary.scIsUnread())
.markedUnread(roomSummary.markedUnread)
.unreadCount(roomSummary.unreadCount)
.hasDraft(roomSummary.userDrafts.isNotEmpty())

View File

@ -28,7 +28,6 @@ import im.vector.app.core.epoxy.profiles.notifications.radioButtonItem
import im.vector.app.core.resources.ColorProvider
import im.vector.app.core.resources.StringProvider
import im.vector.app.features.home.AvatarRenderer
import im.vector.app.features.home.room.ScSdkPreferences
import im.vector.app.features.roomprofile.notifications.notificationOptions
import im.vector.app.features.roomprofile.notifications.notificationStateMapped
import im.vector.app.features.settings.VectorPreferences
@ -44,7 +43,6 @@ class RoomListQuickActionsEpoxyController @Inject constructor(
private val colorProvider: ColorProvider,
private val stringProvider: StringProvider,
private val vectorPreferences: VectorPreferences,
private val scSdkPreferences: ScSdkPreferences
) : TypedEpoxyController<RoomListQuickActionViewState>() {
var listener: Listener? = null
@ -77,7 +75,7 @@ class RoomListQuickActionsEpoxyController @Inject constructor(
bottomSheetDividerItem {
id("mark_unread_separator")
}
if (roomSummary.scIsUnread(scSdkPreferences)) {
if (roomSummary.scIsUnread()) {
RoomListQuickActionsSharedAction.MarkRead(roomSummary.roomId).toBottomSheetItem(-1)
} else {
RoomListQuickActionsSharedAction.MarkUnread(roomSummary.roomId).toBottomSheetItem(-1)

View File

@ -23,6 +23,7 @@ import android.os.Build
import android.provider.MediaStore
import androidx.core.content.edit
import com.squareup.seismic.ShakeDetector
import de.spiritcroc.matrixsdk.StaticScSdkHelper
import im.vector.app.BuildConfig
import im.vector.app.R
import im.vector.app.core.di.DefaultSharedPreferences
@ -35,7 +36,7 @@ import org.matrix.android.sdk.api.session.room.model.RoomSummary
import timber.log.Timber
import javax.inject.Inject
class VectorPreferences @Inject constructor(private val context: Context) {
class VectorPreferences @Inject constructor(private val context: Context): StaticScSdkHelper.ScSdkPreferenceProvider {
companion object {
const val SETTINGS_CHANGE_PASSWORD_PREFERENCE_KEY = "SETTINGS_CHANGE_PASSWORD_PREFERENCE_KEY"
@ -959,7 +960,7 @@ class VectorPreferences @Inject constructor(private val context: Context) {
default
}
}
fun roomUnreadKind(isDirect: Boolean): Int {
override fun roomUnreadKind(isDirect: Boolean): Int {
return if (isDirect) {
roomUnreadKindDm()
} else {
@ -979,7 +980,7 @@ class VectorPreferences @Inject constructor(private val context: Context) {
}
// SC additions - for spaces/categories: whether to count unread chats, or messages
fun useAggregateCounts(): Boolean {
override fun aggregateUnreadRoomCounts(): Boolean {
return defaultPrefs.getBoolean(SETTINGS_AGGREGATE_UNREAD_COUNTS, true)
}

View File

@ -26,7 +26,6 @@ import im.vector.app.core.ui.list.genericHeaderItem
import im.vector.app.features.grouplist.groupSummaryItem
import im.vector.app.features.grouplist.homeSpaceSummaryItem
import im.vector.app.features.home.AvatarRenderer
import im.vector.app.features.home.room.ScSdkPreferences
import im.vector.app.features.home.room.list.UnreadCounterBadgeView
import im.vector.app.features.settings.VectorPreferences
import im.vector.app.group
@ -37,7 +36,6 @@ import org.matrix.android.sdk.api.session.room.model.RoomSummary
import org.matrix.android.sdk.api.session.room.model.SpaceChildInfo
import org.matrix.android.sdk.api.session.room.summary.RoomAggregateNotificationCount
import org.matrix.android.sdk.api.util.toMatrixItem
import java.util.Locale
import javax.inject.Inject
class SpaceSummaryController @Inject constructor(
@ -143,7 +141,7 @@ class SpaceSummaryController @Inject constructor(
listener { host.callback?.onSpaceSelected(null) }
}
val useAggregateCounts = vectorPreferences.useAggregateCounts()
val useAggregateCounts = vectorPreferences.aggregateUnreadRoomCounts()
rootSpaces
?.forEach { groupSummary ->
@ -207,7 +205,7 @@ class SpaceSummaryController @Inject constructor(
val expanded = expandedStates[childSummary.roomId] == true
val isSelected = selected is RoomGroupingMethod.BySpace && childSummary.roomId == selected.space()?.roomId
val useAggregateCounts = vectorPreferences.useAggregateCounts()
val useAggregateCounts = vectorPreferences.aggregateUnreadRoomCounts()
subSpaceSummaryItem {
avatarRenderer(host.avatarRenderer)

View File

@ -28,7 +28,6 @@ import dagger.assisted.AssistedInject
import im.vector.app.AppStateHandler
import im.vector.app.RoomGroupingMethod
import im.vector.app.core.platform.VectorViewModel
import im.vector.app.features.home.room.ScSdkPreferences
import im.vector.app.features.invite.AutoAcceptInvites
import im.vector.app.features.session.coroutineScope
import im.vector.app.features.settings.VectorPreferences
@ -63,7 +62,6 @@ import org.matrix.android.sdk.flow.flow
class SpacesListViewModel @AssistedInject constructor(@Assisted initialState: SpaceListViewState,
private val appStateHandler: AppStateHandler,
private val session: Session,
private val scSdkPreferences: ScSdkPreferences,
private val vectorPreferences: VectorPreferences,
private val autoAcceptInvites: AutoAcceptInvites
) : VectorViewModel<SpaceListViewState, SpaceListAction, SpaceListViewEvents>(initialState) {
@ -138,8 +136,7 @@ class SpacesListViewModel @AssistedInject constructor(@Assisted initialState: Sp
this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null).takeIf {
!vectorPreferences.prefSpacesShowAllRoomInHome()
} ?: ActiveSpaceFilter.None
},
scSdkPreferences
}
)
val counts = RoomAggregateNotificationCount(
totalCount.notificationCount + inviteCount,