mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 01:55:04 +08:00
Timeline: set empty item as fallback item
This commit is contained in:
parent
28c837a47f
commit
9cc2cf8360
@ -32,14 +32,14 @@ class RoomHistoryVisibilityItemFactory(private val stringProvider: StringProvide
|
||||
|
||||
fun create(event: TimelineEvent): NoticeItem? {
|
||||
val roomMember = event.roomMember ?: return null
|
||||
val noticeText = buildRoomMemberNotice(event.root, roomMember) ?: return null
|
||||
val noticeText = buildNoticeText(event.root, roomMember) ?: return null
|
||||
return NoticeItem_()
|
||||
.noticeText(noticeText)
|
||||
.avatarUrl(roomMember.avatarUrl)
|
||||
.memberName(roomMember.displayName)
|
||||
}
|
||||
|
||||
private fun buildRoomMemberNotice(event: Event, roomMember: RoomMember): CharSequence? {
|
||||
private fun buildNoticeText(event: Event, roomMember: RoomMember): CharSequence? {
|
||||
val content = event.content.toModel<RoomHistoryVisibilityContent>() ?: return null
|
||||
val formattedVisibility = when (content.historyVisibility) {
|
||||
RoomHistoryVisibility.SHARED -> stringProvider.getString(R.string.notice_room_visibility_shared)
|
||||
|
@ -74,7 +74,7 @@ class TimelineEventController(private val roomId: String,
|
||||
val nextDate = nextEvent?.root?.localDateTime()
|
||||
val addDaySeparator = date.toLocalDate() != nextDate?.toLocalDate()
|
||||
|
||||
timelineItemFactory.create(event, nextEvent, callback)?.also {
|
||||
timelineItemFactory.create(event, nextEvent, callback).also {
|
||||
it.id(event.localId)
|
||||
it.setOnVisibilityStateChanged(TimelineEventVisibilityStateChangedListener(callback, event, currentPosition))
|
||||
epoxyModels.add(it)
|
||||
|
@ -31,29 +31,32 @@ class TimelineItemFactory(private val messageItemFactory: MessageItemFactory,
|
||||
|
||||
fun create(event: TimelineEvent,
|
||||
nextEvent: TimelineEvent?,
|
||||
callback: TimelineEventController.Callback?): RiotEpoxyModel<*>? {
|
||||
callback: TimelineEventController.Callback?): RiotEpoxyModel<*> {
|
||||
|
||||
return try {
|
||||
val computedModel = try {
|
||||
when (event.root.type) {
|
||||
EventType.MESSAGE -> messageItemFactory.create(event, nextEvent, callback)
|
||||
EventType.STATE_ROOM_NAME -> roomNameItemFactory.create(event)
|
||||
EventType.STATE_ROOM_TOPIC -> roomTopicItemFactory.create(event)
|
||||
EventType.STATE_ROOM_MEMBER -> roomMemberItemFactory.create(event)
|
||||
EventType.STATE_HISTORY_VISIBILITY -> roomHistoryVisibilityItemFactory.create(event)
|
||||
|
||||
EventType.CALL_INVITE,
|
||||
EventType.CALL_HANGUP,
|
||||
EventType.CALL_ANSWER -> callItemFactory.create(event)
|
||||
EventType.STATE_ROOM_CREATE,
|
||||
EventType.STATE_ROOM_POWER_LEVELS,
|
||||
EventType.STATE_ROOM_JOIN_RULES,
|
||||
EventType.STATE_ROOM_GUEST_ACCESS,
|
||||
EventType.CALL_CANDIDATES,
|
||||
EventType.REDACTION -> EmptyItem_()
|
||||
else -> defaultItemFactory.create(event)
|
||||
|
||||
EventType.ENCRYPTED,
|
||||
EventType.ENCRYPTION,
|
||||
EventType.STATE_ROOM_THIRD_PARTY_INVITE,
|
||||
EventType.STICKER,
|
||||
EventType.STATE_ROOM_CREATE -> defaultItemFactory.create(event)
|
||||
|
||||
else -> null
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
defaultItemFactory.create(event, e)
|
||||
}
|
||||
return computedModel ?: EmptyItem_()
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user