mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 02:05:06 +08:00
Use RoomSummaryHolder if available
This commit is contained in:
parent
f58829130a
commit
c5459cdde4
@ -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<Long>()
|
||||
@ -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<TimelineEvent>,
|
||||
@ -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)
|
||||
}
|
||||
|
@ -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()) {
|
||||
|
Loading…
Reference in New Issue
Block a user