Use RoomSummaryHolder if available

This commit is contained in:
Benoit Marty 2020-09-30 12:39:36 +02:00
parent f58829130a
commit c5459cdde4
2 changed files with 18 additions and 11 deletions

View File

@ -22,6 +22,7 @@ import im.vector.app.features.home.AvatarRenderer
import im.vector.app.features.home.room.detail.timeline.TimelineEventController import im.vector.app.features.home.room.detail.timeline.TimelineEventController
import im.vector.app.features.home.room.detail.timeline.helper.AvatarSizeProvider import im.vector.app.features.home.room.detail.timeline.helper.AvatarSizeProvider
import im.vector.app.features.home.room.detail.timeline.helper.MergedTimelineEventVisibilityStateChangedListener import im.vector.app.features.home.room.detail.timeline.helper.MergedTimelineEventVisibilityStateChangedListener
import im.vector.app.features.home.room.detail.timeline.helper.RoomSummaryHolder
import im.vector.app.features.home.room.detail.timeline.helper.canBeMerged import im.vector.app.features.home.room.detail.timeline.helper.canBeMerged
import im.vector.app.features.home.room.detail.timeline.helper.isRoomConfiguration import im.vector.app.features.home.room.detail.timeline.helper.isRoomConfiguration
import im.vector.app.features.home.room.detail.timeline.helper.prevSameTypeEvents import im.vector.app.features.home.room.detail.timeline.helper.prevSameTypeEvents
@ -46,6 +47,7 @@ import javax.inject.Inject
class MergedHeaderItemFactory @Inject constructor(private val activeSessionHolder: ActiveSessionHolder, class MergedHeaderItemFactory @Inject constructor(private val activeSessionHolder: ActiveSessionHolder,
private val avatarRenderer: AvatarRenderer, private val avatarRenderer: AvatarRenderer,
private val avatarSizeProvider: AvatarSizeProvider, private val avatarSizeProvider: AvatarSizeProvider,
private val roomSummaryHolder: RoomSummaryHolder,
private val vectorPreferences: VectorPreferences) { private val vectorPreferences: VectorPreferences) {
private val collapsedEventIds = linkedSetOf<Long>() private val collapsedEventIds = linkedSetOf<Long>()
@ -79,11 +81,7 @@ class MergedHeaderItemFactory @Inject constructor(private val activeSessionHolde
} }
} }
private fun isDirectRoom(roomId: String?): Boolean { private fun isDirectRoom() = roomSummaryHolder.roomSummary?.isDirect.orFalse()
return roomId?.let {
activeSessionHolder.getSafeActiveSession()?.getRoom(roomId)?.roomSummary()?.isDirect
}.orFalse()
}
private fun buildMembershipEventsMergedSummary(currentPosition: Int, private fun buildMembershipEventsMergedSummary(currentPosition: Int,
items: List<TimelineEvent>, items: List<TimelineEvent>,
@ -108,7 +106,7 @@ class MergedHeaderItemFactory @Inject constructor(private val activeSessionHolde
memberName = mergedEvent.senderInfo.disambiguatedDisplayName, memberName = mergedEvent.senderInfo.disambiguatedDisplayName,
localId = mergedEvent.localId, localId = mergedEvent.localId,
eventId = mergedEvent.root.eventId ?: "", eventId = mergedEvent.root.eventId ?: "",
isDirectRoom = isDirectRoom(mergedEvent.root.roomId) isDirectRoom = isDirectRoom()
) )
mergedData.add(data) mergedData.add(data)
} }
@ -196,7 +194,7 @@ class MergedHeaderItemFactory @Inject constructor(private val activeSessionHolde
memberName = senderName, memberName = senderName,
localId = mergedEvent.localId, localId = mergedEvent.localId,
eventId = mergedEvent.root.eventId ?: "", eventId = mergedEvent.root.eventId ?: "",
isDirectRoom = isDirectRoom(mergedEvent.root.roomId) isDirectRoom = isDirectRoom()
) )
mergedData.add(data) mergedData.add(data)
} }
@ -257,7 +255,7 @@ class MergedHeaderItemFactory @Inject constructor(private val activeSessionHolde
memberName = mergedEvent.senderInfo.disambiguatedDisplayName, memberName = mergedEvent.senderInfo.disambiguatedDisplayName,
localId = mergedEvent.localId, localId = mergedEvent.localId,
eventId = mergedEvent.root.eventId ?: "", eventId = mergedEvent.root.eventId ?: "",
isDirectRoom = isDirectRoom(mergedEvent.root.roomId) isDirectRoom = isDirectRoom()
) )
mergedData.add(data) mergedData.add(data)
} }

View File

@ -19,6 +19,7 @@ package im.vector.app.features.home.room.detail.timeline.format
import im.vector.app.ActiveSessionDataSource import im.vector.app.ActiveSessionDataSource
import im.vector.app.R import im.vector.app.R
import im.vector.app.core.resources.StringProvider import im.vector.app.core.resources.StringProvider
import im.vector.app.features.home.room.detail.timeline.helper.RoomSummaryHolder
import org.matrix.android.sdk.api.extensions.orFalse import org.matrix.android.sdk.api.extensions.orFalse
import org.matrix.android.sdk.api.session.events.model.Event import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.events.model.EventType
@ -49,6 +50,7 @@ import javax.inject.Inject
class NoticeEventFormatter @Inject constructor(private val activeSessionDataSource: ActiveSessionDataSource, class NoticeEventFormatter @Inject constructor(private val activeSessionDataSource: ActiveSessionDataSource,
private val roomHistoryVisibilityFormatter: RoomHistoryVisibilityFormatter, private val roomHistoryVisibilityFormatter: RoomHistoryVisibilityFormatter,
private val roomSummaryHolder: RoomSummaryHolder,
private val sp: StringProvider) { private val sp: StringProvider) {
private val currentUserId: String? private val currentUserId: String?
@ -56,9 +58,16 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour
private fun Event.isSentByCurrentUser() = senderId != null && senderId == currentUserId private fun Event.isSentByCurrentUser() = senderId != null && senderId == currentUserId
private fun Event.isDm() = roomId?.let { private fun Event.isDm(): Boolean {
return roomSummaryHolder.roomSummary?.isDirect
?: run {
// RoomSummaryHolder does not have any RoomSummary (not in the timeline)
roomId?.let {
activeSessionDataSource.currentValue?.orNull()?.getRoomSummary(it)?.isDirect activeSessionDataSource.currentValue?.orNull()?.getRoomSummary(it)?.isDirect
}.orFalse() }
}
.orFalse()
}
fun format(timelineEvent: TimelineEvent): CharSequence? { fun format(timelineEvent: TimelineEvent): CharSequence? {
return when (val type = timelineEvent.root.getClearType()) { return when (val type = timelineEvent.root.getClearType()) {