mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-15 01:35:07 +08:00
Merge pull request #4747 from vector-im/feature/bca/clean_state_in_tl
cleaning rendering of state event in timeline
This commit is contained in:
commit
2ddc7f04b3
@ -44,7 +44,7 @@ class EncryptionItemFactory @Inject constructor(
|
||||
if (!event.root.isStateEvent()) {
|
||||
return null
|
||||
}
|
||||
val algorithm = event.root.getClearContent().toModel<EncryptionEventContent>()?.algorithm
|
||||
val algorithm = event.root.content.toModel<EncryptionEventContent>()?.algorithm
|
||||
val informationData = informationDataFactory.create(params)
|
||||
val attributes = messageItemAttributesFactory.create(null, informationData, params.callback)
|
||||
|
||||
|
@ -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<RoomCreateContent>() ?: return null
|
||||
val createRoomContent = event.root.content.toModel<RoomCreateContent>() ?: return null
|
||||
val predecessorId = createRoomContent.predecessor?.roomId ?: return defaultRendering(params)
|
||||
val roomLink = session.permalinkService().createRoomPermalink(predecessorId) ?: return null
|
||||
val text = span {
|
||||
|
@ -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) {
|
||||
|
@ -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 ?: "")) {
|
||||
|
@ -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<String>()
|
||||
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<RoomCreateContent>()
|
||||
return event.content.toModel<RoomCreateContent>()
|
||||
?.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<RoomNameContent>() ?: return null
|
||||
val content = event.content.toModel<RoomNameContent>() ?: 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<RoomTopicContent>() ?: return null
|
||||
val content = event.content.toModel<RoomTopicContent>() ?: 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<RoomAvatarContent>() ?: return null
|
||||
val content = event.content.toModel<RoomAvatarContent>() ?: 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<RoomHistoryVisibilityContent>()?.historyVisibility ?: return null
|
||||
val historyVisibility = event.content.toModel<RoomHistoryVisibilityContent>()?.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<RoomThirdPartyInviteContent>()
|
||||
val content = event.content.toModel<RoomThirdPartyInviteContent>()
|
||||
val prevContent = event.resolvedPrevContent()?.toModel<RoomThirdPartyInviteContent>()
|
||||
|
||||
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<RoomServerAclContent>() ?: return null
|
||||
val eventContent = event.content.toModel<RoomServerAclContent>() ?: return null
|
||||
val prevEventContent = event.resolvedPrevContent()?.toModel<RoomServerAclContent>()
|
||||
|
||||
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<RoomJoinRulesContent>() ?: return null
|
||||
val content = event.content.toModel<RoomJoinRulesContent>() ?: return null
|
||||
return when (content.joinRules) {
|
||||
RoomJoinRules.INVITE ->
|
||||
if (event.isSentByCurrentUser()) {
|
||||
|
Loading…
Reference in New Issue
Block a user