Update unread counter handling

Change-Id: I2f5738b822b4161d18de28074385c5664f3d1f98
This commit is contained in:
SpiritCroc 2021-09-22 17:37:17 +02:00
parent 45746dfbbf
commit cc13146f81
11 changed files with 21 additions and 29 deletions

View File

@ -131,14 +131,6 @@ data class RoomSummary(
}
}
fun scUnreadCount(preferenceProvider: RoomSummaryPreferenceProvider?): Int {
return if (preferenceProvider?.shouldShowUnimportantCounterBadge() == true) {
safeUnreadCount
} else {
0
}
}
fun scNotificationCountWithManualUnread(): Int {
return when {
notificationCount > 0 -> {
@ -164,7 +156,6 @@ data class RoomSummary(
// 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

View File

@ -52,6 +52,7 @@ import org.matrix.android.sdk.internal.di.SessionDatabase
import org.matrix.android.sdk.internal.query.process
import org.matrix.android.sdk.internal.util.fetchCopyMap
import javax.inject.Inject
import kotlin.math.max
internal class RoomSummaryDataSource @Inject constructor(@SessionDatabase private val monarchy: Monarchy,
private val roomSummaryMapper: RoomSummaryMapper) {
@ -230,8 +231,12 @@ internal class RoomSummaryDataSource @Inject constructor(@SessionDatabase privat
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 = if (preferenceProvider.shouldShowUnimportantCounterBadge()) roomSummariesQuery(realm, queryParams).equalTo(preferenceProvider.getUnreadRoomSummaryField(false), true).count().toInt() else 0
val unreadCount = max(
// 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()
)
val markedUnreadCount = roomSummariesQuery(realm, queryParams).equalTo(RoomSummaryEntityFields.MARKED_UNREAD, true).count().toInt()
notificationCount = RoomAggregateNotificationCount(
notifCount,

View File

@ -41,10 +41,6 @@ class UserPreferencesProvider @Inject constructor(private val vectorPreferences:
vectorPreferences.neverShowLongClickOnRoomHelpAgain()
}
fun shouldShowUnimportantCounterBadge(): Boolean {
return vectorPreferences.shouldShowUnimportantCounterBadge()
}
fun shouldShowJoinLeaves(): Boolean {
return vectorPreferences.showJoinLeaveMessages()
}

View File

@ -12,8 +12,4 @@ 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

@ -57,6 +57,7 @@ abstract class RoomSummaryItem : VectorEpoxyModel<RoomSummaryItem.Holder>() {
@EpoxyAttribute var unreadNotificationCount: Int = 0
@EpoxyAttribute var hasUnreadMessage: Boolean = false
@EpoxyAttribute var markedUnread: Boolean = false
@EpoxyAttribute var unreadCount: Int = 0
@EpoxyAttribute var hasDraft: Boolean = false
@EpoxyAttribute var showHighlighted: Boolean = false
@EpoxyAttribute var hasFailedSending: Boolean = false
@ -74,8 +75,7 @@ abstract class RoomSummaryItem : VectorEpoxyModel<RoomSummaryItem.Holder>() {
holder.titleView.text = matrixItem.getBestName()
holder.lastEventTimeView.text = lastEventTime
holder.lastEventView.text = lastFormattedEvent
// SC-TODO: once we count unimportant unread messages, pass that as counter - for now, unreadIndentIndicator is enough, so pass 0 to the badge instead
holder.unreadCounterBadgeView.render(UnreadCounterBadgeView.State(unreadNotificationCount, showHighlighted, 0, markedUnread))
holder.unreadCounterBadgeView.render(UnreadCounterBadgeView.State(unreadNotificationCount, showHighlighted, unreadCount, markedUnread))
holder.unreadIndentIndicator.isVisible = hasUnreadMessage
holder.draftView.isVisible = hasDraft
avatarRenderer.render(matrixItem, holder.avatarImageView)

View File

@ -137,6 +137,7 @@ class RoomSummaryItemFactory @Inject constructor(private val displayableEventFor
.unreadNotificationCount(unreadCount)
.hasUnreadMessage(roomSummary.scIsUnread(scSdkPreferences))
.markedUnread(roomSummary.markedUnread)
.unreadCount(roomSummary.unreadCount ?: 0)
.hasDraft(roomSummary.userDrafts.isNotEmpty())
.itemLongClickListener { _ ->
onLongClick?.invoke(roomSummary) ?: false

View File

@ -20,6 +20,7 @@ import android.util.AttributeSet
import android.view.View
import com.google.android.material.textview.MaterialTextView
import im.vector.app.R
import im.vector.app.features.settings.VectorPreferences
class UnreadCounterBadgeView : MaterialTextView {
@ -29,8 +30,10 @@ class UnreadCounterBadgeView : MaterialTextView {
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
var vectorPreferences: VectorPreferences = VectorPreferences(context)
fun render(state: State) {
if (state.count == 0 && state.unread == 0 && !state.markedUnread) {
if (state.count == 0 && !state.markedUnread && (state.unread == 0 || !vectorPreferences.shouldShowUnimportantCounterBadge())) {
visibility = View.INVISIBLE
} else {
visibility = View.VISIBLE

View File

@ -196,7 +196,7 @@ class VectorPreferences @Inject constructor(private val context: Context) {
private const val SETTINGS_ROOM_UNREAD_KIND = "SETTINGS_ROOM_UNREAD_KIND"
private const val SETTINGS_ROOM_UNREAD_KIND_DM = "SETTINGS_ROOM_UNREAD_KIND_DM"
private const val SETTINGS_ROOM_UNREAD_KIND_GROUP = "SETTINGS_ROOM_UNREAD_KIND_GROUP"
private const val SETTINGS_UNIMPORTANT_COUNTER_BADGE = "SETTINGS_UNIMPORTANT_COUNTER_BADGE"
const val SETTINGS_UNIMPORTANT_COUNTER_BADGE = "SETTINGS_UNIMPORTANT_COUNTER_BADGE"
private const val SETTINGS_SIMPLIFIED_MODE = "SETTINGS_SIMPLIFIED_MODE"
private const val SETTINGS_LABS_ALLOW_MARK_UNREAD = "SETTINGS_LABS_ALLOW_MARK_UNREAD"
const val SETTINGS_ALLOW_URL_PREVIEW_IN_ENCRYPTED_ROOM_KEY = "SETTINGS_ALLOW_URL_PREVIEW_IN_ENCRYPTED_ROOM_KEY"

View File

@ -170,7 +170,7 @@ class SpaceSummaryController @Inject constructor(
UnreadCounterBadgeView.State(
groupSummary.notificationCount,
groupSummary.highlightCount > 0,
groupSummary.scUnreadCount(host.scSdkPreferences),
groupSummary.safeUnreadCount,
groupSummary.markedUnread
)
)
@ -219,7 +219,7 @@ class SpaceSummaryController @Inject constructor(
UnreadCounterBadgeView.State(
childSummary.notificationCount,
childSummary.highlightCount > 0,
childSummary.scUnreadCount(host.scSdkPreferences),
childSummary.safeUnreadCount,
childSummary.markedUnread
)
)

View File

@ -44,8 +44,8 @@
<string name="bubble_time_location_top">Top</string>
<string name="bubble_time_location_bottom">Bottom</string>
<string name="settings_unimportant_counter_badge">Count unimportant chat events</string>
<string name="settings_unimportant_counter_badge_summary">Include chats without notifications in the category unread counter</string>
<string name="settings_unimportant_counter_badge_v2">Count muted messages</string>
<string name="settings_unimportant_counter_badge_summary_v2">Show counts for muted messages in the chat overview</string>
<string name="labs_mark_rooms_unread">Mark chats as unread</string>
<string name="labs_mark_rooms_unread_summary">Allow marking chats as unread. Other Matrix clients might not support this yet.</string>

View File

@ -99,8 +99,8 @@
<im.vector.app.core.preference.VectorSwitchPreference
android:defaultValue="true"
android:key="SETTINGS_UNIMPORTANT_COUNTER_BADGE"
android:summary="@string/settings_unimportant_counter_badge_summary"
android:title="@string/settings_unimportant_counter_badge" />
android:summary="@string/settings_unimportant_counter_badge_summary_v2"
android:title="@string/settings_unimportant_counter_badge_v2" />
</im.vector.app.core.preference.VectorPreferenceCategory>