diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MergedHeaderItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MergedHeaderItemFactory.kt index 41a961dee0..08f93b23cd 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MergedHeaderItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MergedHeaderItemFactory.kt @@ -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.helper.AvatarSizeProvider 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.isRoomConfiguration 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, private val avatarRenderer: AvatarRenderer, private val avatarSizeProvider: AvatarSizeProvider, + private val roomSummaryHolder: RoomSummaryHolder, private val vectorPreferences: VectorPreferences) { private val collapsedEventIds = linkedSetOf() @@ -79,11 +81,7 @@ class MergedHeaderItemFactory @Inject constructor(private val activeSessionHolde } } - private fun isDirectRoom(roomId: String?): Boolean { - return roomId?.let { - activeSessionHolder.getSafeActiveSession()?.getRoom(roomId)?.roomSummary()?.isDirect - }.orFalse() - } + private fun isDirectRoom() = roomSummaryHolder.roomSummary?.isDirect.orFalse() private fun buildMembershipEventsMergedSummary(currentPosition: Int, items: List, @@ -108,7 +106,7 @@ class MergedHeaderItemFactory @Inject constructor(private val activeSessionHolde memberName = mergedEvent.senderInfo.disambiguatedDisplayName, localId = mergedEvent.localId, eventId = mergedEvent.root.eventId ?: "", - isDirectRoom = isDirectRoom(mergedEvent.root.roomId) + isDirectRoom = isDirectRoom() ) mergedData.add(data) } @@ -196,7 +194,7 @@ class MergedHeaderItemFactory @Inject constructor(private val activeSessionHolde memberName = senderName, localId = mergedEvent.localId, eventId = mergedEvent.root.eventId ?: "", - isDirectRoom = isDirectRoom(mergedEvent.root.roomId) + isDirectRoom = isDirectRoom() ) mergedData.add(data) } @@ -257,7 +255,7 @@ class MergedHeaderItemFactory @Inject constructor(private val activeSessionHolde memberName = mergedEvent.senderInfo.disambiguatedDisplayName, localId = mergedEvent.localId, eventId = mergedEvent.root.eventId ?: "", - isDirectRoom = isDirectRoom(mergedEvent.root.roomId) + isDirectRoom = isDirectRoom() ) mergedData.add(data) } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt index 84cb1d7817..34b4cac5b4 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt @@ -19,6 +19,7 @@ package im.vector.app.features.home.room.detail.timeline.format import im.vector.app.ActiveSessionDataSource import im.vector.app.R 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.session.events.model.Event 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, private val roomHistoryVisibilityFormatter: RoomHistoryVisibilityFormatter, + private val roomSummaryHolder: RoomSummaryHolder, private val sp: StringProvider) { 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.isDm() = roomId?.let { - activeSessionDataSource.currentValue?.orNull()?.getRoomSummary(it)?.isDirect - }.orFalse() + 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 + } + } + .orFalse() + } fun format(timelineEvent: TimelineEvent): CharSequence? { return when (val type = timelineEvent.root.getClearType()) {