Various fixes after merge

- Fix compile
- Fix counting chats marked unread
- Fix counting chats with unread messages

Change-Id: Ibf928c5380a1b7ec25f2c510b97ee4f726fe7c0d
This commit is contained in:
SpiritCroc 2021-04-13 09:47:43 +02:00
parent 0e601aa8f0
commit 811950cb18
11 changed files with 71 additions and 44 deletions

View File

@ -49,7 +49,7 @@ interface ReadService {
/**
* Mark a room as unread, or remove an existing unread marker.
*/
fun setMarkedUnread(markedUnread: Boolean, callback: MatrixCallback<Unit>)
suspend fun setMarkedUnread(markedUnread: Boolean)
/**
* Check if an event is already read, ie. your read receipt is set on a more recent event.

View File

@ -18,8 +18,11 @@ package org.matrix.android.sdk.api.session.room.summary
data class RoomAggregateNotificationCount(
val notificationCount: Int,
val highlightCount: Int
val highlightCount: Int,
val unreadCount: Int,
val markedUnreadCount: Int
) {
val totalCount = notificationCount + highlightCount
val totalCount = notificationCount + highlightCount + markedUnreadCount
val isHighlight = highlightCount > 0
val markedUnread = markedUnreadCount > 0
}

View File

@ -59,7 +59,7 @@ internal class DefaultReadService @AssistedInject constructor(
)
setReadMarkersTask.execute(taskParams)
// Automatically unset unread marker
setMarkedUnreadFlag(false, callback)
setMarkedUnreadFlag(false)
}
override suspend fun setReadReceipt(eventId: String) {
@ -72,23 +72,19 @@ internal class DefaultReadService @AssistedInject constructor(
setReadMarkersTask.execute(params)
}
override fun setMarkedUnread(markedUnread: Boolean, callback: MatrixCallback<Unit>) {
override suspend fun setMarkedUnread(markedUnread: Boolean) {
if (markedUnread) {
setMarkedUnreadFlag(true, callback)
setMarkedUnreadFlag(true)
} else {
// We want to both remove unread marker and update read receipt position,
// i.e., we want what markAsRead does
markAsRead(ReadService.MarkAsReadParams.READ_RECEIPT, callback)
markAsRead(ReadService.MarkAsReadParams.READ_RECEIPT)
}
}
private fun setMarkedUnreadFlag(markedUnread: Boolean, callback: MatrixCallback<Unit>) {
private suspend fun setMarkedUnreadFlag(markedUnread: Boolean) {
val params = SetMarkedUnreadTask.Params(roomId, markedUnread = markedUnread)
setMarkedUnreadTask
.configureWith(params) {
this.callback = callback
}
.executeBy(taskExecutor)
setMarkedUnreadTask.execute(params)
}
override fun isEventRead(eventId: String): Boolean {

View File

@ -54,9 +54,8 @@ internal class DefaultSetMarkedUnreadTask @Inject constructor(
if (isMarkedUnread(monarchy.realmConfiguration, params.roomId) != params.markedUnread) {
updateDatabase(params.roomId, params.markedUnread)
executeRequest<Unit>(globalErrorReceiver) {
isRetryable = true
apiCall = accountDataApi.setRoomAccountData(userId, params.roomId, EventType.MARKED_UNREAD, params.markedUnreadContent)
executeRequest(globalErrorReceiver, canRetry = true) {
accountDataApi.setRoomAccountData(userId, params.roomId, EventType.MARKED_UNREAD, params.markedUnreadContent)
}
}
}

View File

@ -33,6 +33,7 @@ import org.matrix.android.sdk.api.session.room.summary.RoomAggregateNotification
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
@ -152,9 +153,14 @@ 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 = roomSummariesQuery(realm, queryParams).equalTo(RoomSummaryEntityFields.HAS_UNREAD_ORIGINAL_CONTENT_MESSAGES, true).count().toInt()
val markedUnreadCount = roomSummariesQuery(realm, queryParams).equalTo(RoomSummaryEntityFields.MARKED_UNREAD, true).count().toInt()
notificationCount = RoomAggregateNotificationCount(
notifCount,
highlightCount
highlightCount,
unreadCount,
markedUnreadCount
)
}
return notificationCount!!

View File

@ -128,6 +128,7 @@ abstract class BaseEventItem<H : BaseEventItem.BaseHolder> : VectorEpoxyModel<H>
@CallSuper
open fun setBubbleLayout(holder: H, bubbleStyle: String, bubbleStyleSetting: String, reverseBubble: Boolean) {
/* TODO-SC-merge: read receipt layout alignment
val defaultDirection = holder.readReceiptsView.resources.configuration.layoutDirection;
val defaultRtl = defaultDirection == View.LAYOUT_DIRECTION_RTL
val reverseDirection = if (defaultRtl) View.LAYOUT_DIRECTION_LTR else View.LAYOUT_DIRECTION_RTL
@ -156,6 +157,7 @@ abstract class BaseEventItem<H : BaseEventItem.BaseHolder> : VectorEpoxyModel<H>
// Also set rtl to have members fill from the natural side
setFlatRtl(holder.readReceiptsView, if (dualBubbles) reverseDirection else defaultDirection, defaultDirection)
*/
}
}

View File

@ -99,12 +99,6 @@ class RoomListFragment @Inject constructor(
private val adapterInfosList = mutableListOf<SectionAdapterInfo>()
private var concatAdapter : ConcatAdapter? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
context?.let { roomListViewModel.initWithContext(it, roomListParams.displayMode) }
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
views.stateView.contentView = views.roomListView
@ -166,9 +160,11 @@ class RoomListFragment @Inject constructor(
override fun onPause() {
super.onPause()
/* TODO-SC-merge: remember expand state for priority headers
withState(roomListViewModel) {
state -> context?.let { state.persistWithContext(it, roomListParams.displayMode) }
}
*/
}
override fun showFailure(throwable: Throwable) {
@ -281,7 +277,9 @@ class RoomListFragment @Inject constructor(
section.notificationCount.observe(viewLifecycleOwner) { counts ->
sectionAdapter.updateSection(sectionAdapter.roomsSectionData.copy(
notificationCount = counts.totalCount,
isHighlighted = counts.isHighlight
isHighlighted = counts.isHighlight,
unread = counts.unreadCount,
markedUnread = counts.markedUnread
))
}
section.isExpanded.observe(viewLifecycleOwner) { _ ->

View File

@ -98,6 +98,7 @@ class RoomListViewModel @Inject constructor(
it.roomTagQueryFilter = RoomTagQueryFilter(true, null, null)
}
// TODO-SC why no low priority?
addSection(sections, R.string.bottom_action_people_x) {
it.memberships = listOf(Membership.JOIN)
it.roomCategoryFilter = RoomCategoryFilter.ONLY_DM
@ -155,19 +156,31 @@ class RoomListViewModel @Inject constructor(
it.memberships = listOf(Membership.JOIN)
it.roomCategoryFilter = RoomCategoryFilter.ONLY_WITH_NOTIFICATIONS
}
} else if (initialState.displayMode == RoomListDisplayMode.ALL) {
addSection(sections, R.string.invitations_header, true) {
it.memberships = listOf(Membership.INVITE)
}
addSection(sections, R.string.bottom_action_favourites) {
it.memberships = listOf(Membership.JOIN)
it.roomTagQueryFilter = RoomTagQueryFilter(true, null, null)
}
addSection(sections, R.string.normal_priority_header) {
it.memberships = listOf(Membership.JOIN)
it.roomTagQueryFilter = RoomTagQueryFilter(false, false, false)
}
addSection(sections, R.string.low_priority_header) {
it.memberships = listOf(Membership.JOIN)
it.roomTagQueryFilter = RoomTagQueryFilter(null, true, null)
}
addSection(sections, R.string.system_alerts_header) {
it.memberships = listOf(Membership.JOIN)
it.roomTagQueryFilter = RoomTagQueryFilter(null, null, true)
}
}
sections
}
fun initWithContext(context: Context, displayMode: RoomListDisplayMode) {
vectorPreferences = VectorPreferences(context)
setState {
// RoomListViewState.initWithContext
this.initWithContext(context, displayMode)
}
}
override fun handle(action: RoomListAction) {
when (action) {
is RoomListAction.SelectRoom -> handleSelectRoom(action)
@ -362,15 +375,16 @@ class RoomListViewModel @Inject constructor(
}
private fun handleSetMarkedUnread(action: RoomListAction.SetMarkedUnread) {
session.getRoom(action.roomId)?.setMarkedUnread(action.markedUnread, object : MatrixCallback<Unit> {
override fun onSuccess(data: Unit) {
_viewEvents.post(RoomListViewEvents.Done)
val room = session.getRoom(action.roomId)
if (room != null) {
viewModelScope.launch {
try {
room.setMarkedUnread(action.markedUnread)
} catch (failure: Exception) {
_viewEvents.post(RoomListViewEvents.Failure(failure))
}
}
override fun onFailure(failure: Throwable) {
_viewEvents.post(RoomListViewEvents.Failure(failure))
}
})
}
}
private fun handleLeaveRoom(action: RoomListAction.LeaveRoom) {

View File

@ -26,6 +26,6 @@ data class RoomsSection(
val sectionName: String,
val livePages: LiveData<PagedList<RoomSummary>>,
val isExpanded: MutableLiveData<Boolean> = MutableLiveData(true),
val notificationCount: MutableLiveData<RoomAggregateNotificationCount> = MutableLiveData(RoomAggregateNotificationCount(0, 0)),
val notificationCount: MutableLiveData<RoomAggregateNotificationCount> = MutableLiveData(RoomAggregateNotificationCount(0, 0, 0, 0)),
val notifyOfLocalEcho: Boolean = false
)

View File

@ -35,7 +35,10 @@ class SectionHeaderAdapter constructor(
val isExpanded: Boolean = true,
val notificationCount: Int = 0,
val isHighlighted: Boolean = false,
val isHidden: Boolean = true
val isHidden: Boolean = true,
// SC additions
val unread: Int = 0,
val markedUnread: Boolean = true
)
lateinit var roomsSectionData: RoomsSectionData
@ -84,7 +87,7 @@ class SectionHeaderAdapter constructor(
val expandedArrowDrawable = ContextCompat.getDrawable(binding.root.context, expandedArrowDrawableRes)?.also {
DrawableCompat.setTint(it, tintColor)
}
binding.roomCategoryUnreadCounterBadgeView.render(UnreadCounterBadgeView.State(roomsSectionData.notificationCount, roomsSectionData.isHighlighted))
binding.roomCategoryUnreadCounterBadgeView.render(UnreadCounterBadgeView.State(roomsSectionData.notificationCount, roomsSectionData.isHighlighted, roomsSectionData.unread, roomsSectionData.markedUnread))
binding.roomCategoryTitleView.setCompoundDrawablesWithIntrinsicBounds(null, null, expandedArrowDrawable, null)
}

View File

@ -45,7 +45,13 @@ sealed class ActivityOtherThemes(@StyleRes val light: Int,
object Launcher : ActivityOtherThemes(
R.style.AppTheme_Launcher,
R.style.AppTheme_Launcher
R.style.AppTheme_Launcher,
R.style.AppTheme_Launcher,
R.style.AppTheme_Launcher_SC,
R.style.AppTheme_Launcher_SC,
R.style.AppTheme_Launcher_SC,
R.style.AppTheme_Launcher_SC,
R.style.AppTheme_Launcher_SC,
)
object AttachmentsPreview : ActivityOtherThemes(