diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/EncryptionItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/EncryptionItemFactory.kt index 1d30136f27..14d9cce28a 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/EncryptionItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/EncryptionItemFactory.kt @@ -44,7 +44,7 @@ class EncryptionItemFactory @Inject constructor( if (!event.root.isStateEvent()) { return null } - val algorithm = event.root.getClearContent().toModel()?.algorithm + val algorithm = event.root.content.toModel()?.algorithm val informationData = informationDataFactory.create(params) val attributes = messageItemAttributesFactory.create(null, informationData, params.callback) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/RoomCreateItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/RoomCreateItemFactory.kt index 382962f98d..523fb8e682 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/RoomCreateItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/RoomCreateItemFactory.kt @@ -34,7 +34,7 @@ class RoomCreateItemFactory @Inject constructor(private val stringProvider: Stri fun create(params: TimelineItemFactoryParams): VectorEpoxyModel<*>? { val event = params.event - val createRoomContent = event.root.getClearContent().toModel() ?: return null + val createRoomContent = event.root.content.toModel() ?: return null val predecessorId = createRoomContent.predecessor?.roomId ?: return defaultRendering(params) val roomLink = session.permalinkService().createRoomPermalink(predecessorId) ?: return null val text = span { diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/TimelineItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/TimelineItemFactory.kt index c6b128315f..4af3c69aa3 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/TimelineItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/TimelineItemFactory.kt @@ -45,67 +45,83 @@ class TimelineItemFactory @Inject constructor(private val messageItemFactory: Me if (!timelineEventVisibilityHelper.shouldShowEvent(event, params.highlightedEventId)) { return buildEmptyItem(event, params.prevEvent, params.highlightedEventId) } - when (event.root.getClearType()) { - // Message itemsX - EventType.STICKER, - EventType.POLL_START, - EventType.MESSAGE -> messageItemFactory.create(params) - EventType.STATE_ROOM_TOMBSTONE, - EventType.STATE_ROOM_NAME, - EventType.STATE_ROOM_TOPIC, - EventType.STATE_ROOM_AVATAR, - EventType.STATE_ROOM_MEMBER, - EventType.STATE_ROOM_THIRD_PARTY_INVITE, - EventType.STATE_ROOM_CANONICAL_ALIAS, - EventType.STATE_ROOM_JOIN_RULES, - EventType.STATE_ROOM_HISTORY_VISIBILITY, - EventType.STATE_ROOM_SERVER_ACL, - EventType.STATE_ROOM_GUEST_ACCESS, - EventType.REDACTION, - EventType.STATE_ROOM_ALIASES, - EventType.KEY_VERIFICATION_ACCEPT, - EventType.KEY_VERIFICATION_START, - EventType.KEY_VERIFICATION_KEY, - EventType.KEY_VERIFICATION_READY, - EventType.KEY_VERIFICATION_MAC, - EventType.CALL_CANDIDATES, - EventType.CALL_REPLACES, - EventType.CALL_SELECT_ANSWER, - EventType.CALL_NEGOTIATE, - EventType.REACTION, - EventType.STATE_SPACE_CHILD, - EventType.STATE_SPACE_PARENT, - EventType.STATE_ROOM_POWER_LEVELS, - EventType.POLL_RESPONSE, - EventType.POLL_END -> noticeItemFactory.create(params) - EventType.STATE_ROOM_WIDGET_LEGACY, - EventType.STATE_ROOM_WIDGET -> widgetItemFactory.create(params) - EventType.STATE_ROOM_ENCRYPTION -> encryptionItemFactory.create(params) - // State room create - EventType.STATE_ROOM_CREATE -> roomCreateItemFactory.create(params) - // Calls - EventType.CALL_INVITE, - EventType.CALL_HANGUP, - EventType.CALL_REJECT, - EventType.CALL_ANSWER -> callItemFactory.create(params) - // Crypto - EventType.ENCRYPTED -> { - if (event.root.isRedacted()) { - // Redacted event, let the MessageItemFactory handle it - messageItemFactory.create(params) - } else { - encryptedItemFactory.create(params) + + // Manage state event differently, to check validity + if (event.root.isStateEvent()) { + // state event are not e2e + when (event.root.type) { + EventType.STATE_ROOM_TOMBSTONE, + EventType.STATE_ROOM_NAME, + EventType.STATE_ROOM_TOPIC, + EventType.STATE_ROOM_AVATAR, + EventType.STATE_ROOM_MEMBER, + EventType.STATE_ROOM_THIRD_PARTY_INVITE, + EventType.STATE_ROOM_CANONICAL_ALIAS, + EventType.STATE_ROOM_JOIN_RULES, + EventType.STATE_ROOM_HISTORY_VISIBILITY, + EventType.STATE_ROOM_SERVER_ACL, + EventType.STATE_ROOM_GUEST_ACCESS, + EventType.STATE_ROOM_ALIASES, + EventType.STATE_SPACE_CHILD, + EventType.STATE_SPACE_PARENT, + EventType.STATE_ROOM_POWER_LEVELS -> { + noticeItemFactory.create(params) + } + EventType.STATE_ROOM_WIDGET_LEGACY, + EventType.STATE_ROOM_WIDGET -> widgetItemFactory.create(params) + EventType.STATE_ROOM_ENCRYPTION -> encryptionItemFactory.create(params) + // State room create + EventType.STATE_ROOM_CREATE -> roomCreateItemFactory.create(params) + // Unhandled state event types + else -> { + // Should only happen when shouldShowHiddenEvents() settings is ON + Timber.v("State event type ${event.root.type} not handled") + defaultItemFactory.create(params) } } - EventType.KEY_VERIFICATION_CANCEL, - EventType.KEY_VERIFICATION_DONE -> { - verificationConclusionItemFactory.create(params) - } - // Unhandled event types - else -> { - // Should only happen when shouldShowHiddenEvents() settings is ON - Timber.v("Type ${event.root.getClearType()} not handled") - defaultItemFactory.create(params) + } else { + when (event.root.getClearType()) { + // Message itemsX + EventType.STICKER, + EventType.POLL_START, + EventType.MESSAGE -> messageItemFactory.create(params) + EventType.REDACTION, + EventType.KEY_VERIFICATION_ACCEPT, + EventType.KEY_VERIFICATION_START, + EventType.KEY_VERIFICATION_KEY, + EventType.KEY_VERIFICATION_READY, + EventType.KEY_VERIFICATION_MAC, + EventType.CALL_CANDIDATES, + EventType.CALL_REPLACES, + EventType.CALL_SELECT_ANSWER, + EventType.CALL_NEGOTIATE, + EventType.REACTION, + EventType.POLL_RESPONSE, + EventType.POLL_END -> noticeItemFactory.create(params) + // Calls + EventType.CALL_INVITE, + EventType.CALL_HANGUP, + EventType.CALL_REJECT, + EventType.CALL_ANSWER -> callItemFactory.create(params) + // Crypto + EventType.ENCRYPTED -> { + if (event.root.isRedacted()) { + // Redacted event, let the MessageItemFactory handle it + messageItemFactory.create(params) + } else { + encryptedItemFactory.create(params) + } + } + EventType.KEY_VERIFICATION_CANCEL, + EventType.KEY_VERIFICATION_DONE -> { + verificationConclusionItemFactory.create(params) + } + // Unhandled event types + else -> { + // Should only happen when shouldShowHiddenEvents() settings is ON + Timber.v("Type ${event.root.getClearType()} not handled") + defaultItemFactory.create(params) + } } } } catch (throwable: Throwable) { diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/WidgetItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/WidgetItemFactory.kt index 52f72810c9..a08383315c 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/WidgetItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/WidgetItemFactory.kt @@ -41,7 +41,7 @@ class WidgetItemFactory @Inject constructor( fun create(params: TimelineItemFactoryParams): VectorEpoxyModel<*>? { val event = params.event - val widgetContent: WidgetContent = event.root.getClearContent().toModel() ?: return null + val widgetContent: WidgetContent = event.root.content.toModel() ?: return null val previousWidgetContent: WidgetContent? = event.root.resolvedPrevContent().toModel() return when (WidgetType.fromString(widgetContent.type ?: previousWidgetContent?.type ?: "")) { 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 3dc46c9d70..d39b8aec5e 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 @@ -114,7 +114,7 @@ class NoticeEventFormatter @Inject constructor( } private fun formatRoomPowerLevels(event: Event, disambiguatedDisplayName: String): CharSequence? { - val powerLevelsContent: PowerLevelsContent = event.getClearContent().toModel() ?: return null + val powerLevelsContent: PowerLevelsContent = event.content.toModel() ?: return null val previousPowerLevelsContent: PowerLevelsContent = event.resolvedPrevContent().toModel() ?: return null val userIds = HashSet() userIds.addAll(powerLevelsContent.users.orEmpty().keys) @@ -142,7 +142,7 @@ class NoticeEventFormatter @Inject constructor( } private fun formatWidgetEvent(event: Event, disambiguatedDisplayName: String): CharSequence? { - val widgetContent: WidgetContent = event.getClearContent().toModel() ?: return null + val widgetContent: WidgetContent = event.content.toModel() ?: return null val previousWidgetContent: WidgetContent? = event.resolvedPrevContent().toModel() return if (widgetContent.isActive()) { val widgetName = widgetContent.getHumanName() @@ -198,7 +198,7 @@ class NoticeEventFormatter @Inject constructor( } private fun formatRoomCreateEvent(event: Event, isDm: Boolean): CharSequence? { - return event.getClearContent().toModel() + return event.content.toModel() ?.takeIf { it.creator.isNullOrBlank().not() } ?.let { if (event.isSentByCurrentUser()) { @@ -210,7 +210,7 @@ class NoticeEventFormatter @Inject constructor( } private fun formatRoomNameEvent(event: Event, senderName: String?): CharSequence? { - val content = event.getClearContent().toModel() ?: return null + val content = event.content.toModel() ?: return null return if (content.name.isNullOrBlank()) { if (event.isSentByCurrentUser()) { sp.getString(R.string.notice_room_name_removed_by_you) @@ -235,7 +235,7 @@ class NoticeEventFormatter @Inject constructor( } private fun formatRoomTopicEvent(event: Event, senderName: String?): CharSequence? { - val content = event.getClearContent().toModel() ?: return null + val content = event.content.toModel() ?: return null return if (content.topic.isNullOrEmpty()) { if (event.isSentByCurrentUser()) { sp.getString(R.string.notice_room_topic_removed_by_you) @@ -252,7 +252,7 @@ class NoticeEventFormatter @Inject constructor( } private fun formatRoomAvatarEvent(event: Event, senderName: String?): CharSequence? { - val content = event.getClearContent().toModel() ?: return null + val content = event.content.toModel() ?: return null return if (content.avatarUrl.isNullOrEmpty()) { if (event.isSentByCurrentUser()) { sp.getString(R.string.notice_room_avatar_removed_by_you) @@ -269,7 +269,7 @@ class NoticeEventFormatter @Inject constructor( } private fun formatRoomHistoryVisibilityEvent(event: Event, senderName: String?, isDm: Boolean): CharSequence? { - val historyVisibility = event.getClearContent().toModel()?.historyVisibility ?: return null + val historyVisibility = event.content.toModel()?.historyVisibility ?: return null val historyVisibilitySuffix = roomHistoryVisibilityFormatter.getNoticeSuffix(historyVisibility) return if (event.isSentByCurrentUser()) { @@ -282,7 +282,7 @@ class NoticeEventFormatter @Inject constructor( } private fun formatRoomThirdPartyInvite(event: Event, senderName: String?, isDm: Boolean): CharSequence? { - val content = event.getClearContent().toModel() + val content = event.content.toModel() val prevContent = event.resolvedPrevContent()?.toModel() return when { @@ -363,7 +363,7 @@ class NoticeEventFormatter @Inject constructor( } private fun formatRoomMemberEvent(event: Event, senderName: String?, isDm: Boolean): String? { - val eventContent: RoomMemberContent? = event.getClearContent().toModel() + val eventContent: RoomMemberContent? = event.content.toModel() val prevEventContent: RoomMemberContent? = event.resolvedPrevContent().toModel() val isMembershipEvent = prevEventContent?.membership != eventContent?.membership || eventContent?.membership == Membership.LEAVE @@ -375,7 +375,7 @@ class NoticeEventFormatter @Inject constructor( } private fun formatRoomAliasesEvent(event: Event, senderName: String?): String? { - val eventContent: RoomAliasesContent? = event.getClearContent().toModel() + val eventContent: RoomAliasesContent? = event.content.toModel() val prevEventContent: RoomAliasesContent? = event.resolvedPrevContent()?.toModel() val addedAliases = eventContent?.aliases.orEmpty() - prevEventContent?.aliases.orEmpty() @@ -408,7 +408,7 @@ class NoticeEventFormatter @Inject constructor( } private fun formatRoomServerAclEvent(event: Event, senderName: String?): String? { - val eventContent = event.getClearContent().toModel() ?: return null + val eventContent = event.content.toModel() ?: return null val prevEventContent = event.resolvedPrevContent()?.toModel() return buildString { @@ -481,7 +481,7 @@ class NoticeEventFormatter @Inject constructor( } private fun formatRoomCanonicalAliasEvent(event: Event, senderName: String?): String? { - val eventContent: RoomCanonicalAliasContent? = event.getClearContent().toModel() + val eventContent: RoomCanonicalAliasContent? = event.content.toModel() val prevContent: RoomCanonicalAliasContent? = event.resolvedPrevContent().toModel() val canonicalAlias = eventContent?.canonicalAlias?.takeIf { it.isNotEmpty() } val prevCanonicalAlias = prevContent?.canonicalAlias?.takeIf { it.isNotEmpty() } @@ -551,7 +551,7 @@ class NoticeEventFormatter @Inject constructor( } private fun formatRoomGuestAccessEvent(event: Event, senderName: String?, isDm: Boolean): String? { - val eventContent: RoomGuestAccessContent? = event.getClearContent().toModel() + val eventContent: RoomGuestAccessContent? = event.content.toModel() return when (eventContent?.guestAccess) { GuestAccess.CanJoin -> if (event.isSentByCurrentUser()) { @@ -815,7 +815,7 @@ class NoticeEventFormatter @Inject constructor( } private fun formatJoinRulesEvent(event: Event, senderName: String?, isDm: Boolean): CharSequence? { - val content = event.getClearContent().toModel() ?: return null + val content = event.content.toModel() ?: return null return when (content.joinRules) { RoomJoinRules.INVITE -> if (event.isSentByCurrentUser()) {