cleaning rendering of state event in timeline
This commit is contained in:
parent
ca58a04f57
commit
240ce6873b
|
@ -44,7 +44,7 @@ class EncryptionItemFactory @Inject constructor(
|
||||||
if (!event.root.isStateEvent()) {
|
if (!event.root.isStateEvent()) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
val algorithm = event.root.getClearContent().toModel<EncryptionEventContent>()?.algorithm
|
val algorithm = event.root.content.toModel<EncryptionEventContent>()?.algorithm
|
||||||
val informationData = informationDataFactory.create(params)
|
val informationData = informationDataFactory.create(params)
|
||||||
val attributes = messageItemAttributesFactory.create(null, informationData, params.callback)
|
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<*>? {
|
fun create(params: TimelineItemFactoryParams): VectorEpoxyModel<*>? {
|
||||||
val event = params.event
|
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 predecessorId = createRoomContent.predecessor?.roomId ?: return defaultRendering(params)
|
||||||
val roomLink = session.permalinkService().createRoomPermalink(predecessorId) ?: return null
|
val roomLink = session.permalinkService().createRoomPermalink(predecessorId) ?: return null
|
||||||
val text = span {
|
val text = span {
|
||||||
|
|
|
@ -45,11 +45,11 @@ class TimelineItemFactory @Inject constructor(private val messageItemFactory: Me
|
||||||
if (!timelineEventVisibilityHelper.shouldShowEvent(event, params.highlightedEventId)) {
|
if (!timelineEventVisibilityHelper.shouldShowEvent(event, params.highlightedEventId)) {
|
||||||
return buildEmptyItem(event, params.prevEvent, params.highlightedEventId)
|
return buildEmptyItem(event, params.prevEvent, params.highlightedEventId)
|
||||||
}
|
}
|
||||||
when (event.root.getClearType()) {
|
|
||||||
// Message itemsX
|
// Manage state event differently, to check validity
|
||||||
EventType.STICKER,
|
if (event.root.isStateEvent()) {
|
||||||
EventType.POLL_START,
|
// state event are not e2e
|
||||||
EventType.MESSAGE -> messageItemFactory.create(params)
|
when (event.root.type) {
|
||||||
EventType.STATE_ROOM_TOMBSTONE,
|
EventType.STATE_ROOM_TOMBSTONE,
|
||||||
EventType.STATE_ROOM_NAME,
|
EventType.STATE_ROOM_NAME,
|
||||||
EventType.STATE_ROOM_TOPIC,
|
EventType.STATE_ROOM_TOPIC,
|
||||||
|
@ -61,8 +61,31 @@ class TimelineItemFactory @Inject constructor(private val messageItemFactory: Me
|
||||||
EventType.STATE_ROOM_HISTORY_VISIBILITY,
|
EventType.STATE_ROOM_HISTORY_VISIBILITY,
|
||||||
EventType.STATE_ROOM_SERVER_ACL,
|
EventType.STATE_ROOM_SERVER_ACL,
|
||||||
EventType.STATE_ROOM_GUEST_ACCESS,
|
EventType.STATE_ROOM_GUEST_ACCESS,
|
||||||
EventType.REDACTION,
|
|
||||||
EventType.STATE_ROOM_ALIASES,
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} 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_ACCEPT,
|
||||||
EventType.KEY_VERIFICATION_START,
|
EventType.KEY_VERIFICATION_START,
|
||||||
EventType.KEY_VERIFICATION_KEY,
|
EventType.KEY_VERIFICATION_KEY,
|
||||||
|
@ -73,16 +96,8 @@ class TimelineItemFactory @Inject constructor(private val messageItemFactory: Me
|
||||||
EventType.CALL_SELECT_ANSWER,
|
EventType.CALL_SELECT_ANSWER,
|
||||||
EventType.CALL_NEGOTIATE,
|
EventType.CALL_NEGOTIATE,
|
||||||
EventType.REACTION,
|
EventType.REACTION,
|
||||||
EventType.STATE_SPACE_CHILD,
|
|
||||||
EventType.STATE_SPACE_PARENT,
|
|
||||||
EventType.STATE_ROOM_POWER_LEVELS,
|
|
||||||
EventType.POLL_RESPONSE,
|
EventType.POLL_RESPONSE,
|
||||||
EventType.POLL_END -> noticeItemFactory.create(params)
|
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
|
// Calls
|
||||||
EventType.CALL_INVITE,
|
EventType.CALL_INVITE,
|
||||||
EventType.CALL_HANGUP,
|
EventType.CALL_HANGUP,
|
||||||
|
@ -108,6 +123,7 @@ class TimelineItemFactory @Inject constructor(private val messageItemFactory: Me
|
||||||
defaultItemFactory.create(params)
|
defaultItemFactory.create(params)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (throwable: Throwable) {
|
} catch (throwable: Throwable) {
|
||||||
Timber.e(throwable, "failed to create message item")
|
Timber.e(throwable, "failed to create message item")
|
||||||
defaultItemFactory.create(params, throwable)
|
defaultItemFactory.create(params, throwable)
|
||||||
|
|
|
@ -41,7 +41,7 @@ class WidgetItemFactory @Inject constructor(
|
||||||
|
|
||||||
fun create(params: TimelineItemFactoryParams): VectorEpoxyModel<*>? {
|
fun create(params: TimelineItemFactoryParams): VectorEpoxyModel<*>? {
|
||||||
val event = params.event
|
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()
|
val previousWidgetContent: WidgetContent? = event.root.resolvedPrevContent().toModel()
|
||||||
|
|
||||||
return when (WidgetType.fromString(widgetContent.type ?: previousWidgetContent?.type ?: "")) {
|
return when (WidgetType.fromString(widgetContent.type ?: previousWidgetContent?.type ?: "")) {
|
||||||
|
|
|
@ -114,7 +114,7 @@ class NoticeEventFormatter @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun formatRoomPowerLevels(event: Event, disambiguatedDisplayName: String): CharSequence? {
|
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 previousPowerLevelsContent: PowerLevelsContent = event.resolvedPrevContent().toModel() ?: return null
|
||||||
val userIds = HashSet<String>()
|
val userIds = HashSet<String>()
|
||||||
userIds.addAll(powerLevelsContent.users.orEmpty().keys)
|
userIds.addAll(powerLevelsContent.users.orEmpty().keys)
|
||||||
|
@ -142,7 +142,7 @@ class NoticeEventFormatter @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun formatWidgetEvent(event: Event, disambiguatedDisplayName: String): CharSequence? {
|
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()
|
val previousWidgetContent: WidgetContent? = event.resolvedPrevContent().toModel()
|
||||||
return if (widgetContent.isActive()) {
|
return if (widgetContent.isActive()) {
|
||||||
val widgetName = widgetContent.getHumanName()
|
val widgetName = widgetContent.getHumanName()
|
||||||
|
@ -198,7 +198,7 @@ class NoticeEventFormatter @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun formatRoomCreateEvent(event: Event, isDm: Boolean): CharSequence? {
|
private fun formatRoomCreateEvent(event: Event, isDm: Boolean): CharSequence? {
|
||||||
return event.getClearContent().toModel<RoomCreateContent>()
|
return event.content.toModel<RoomCreateContent>()
|
||||||
?.takeIf { it.creator.isNullOrBlank().not() }
|
?.takeIf { it.creator.isNullOrBlank().not() }
|
||||||
?.let {
|
?.let {
|
||||||
if (event.isSentByCurrentUser()) {
|
if (event.isSentByCurrentUser()) {
|
||||||
|
@ -210,7 +210,7 @@ class NoticeEventFormatter @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun formatRoomNameEvent(event: Event, senderName: String?): CharSequence? {
|
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()) {
|
return if (content.name.isNullOrBlank()) {
|
||||||
if (event.isSentByCurrentUser()) {
|
if (event.isSentByCurrentUser()) {
|
||||||
sp.getString(R.string.notice_room_name_removed_by_you)
|
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? {
|
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()) {
|
return if (content.topic.isNullOrEmpty()) {
|
||||||
if (event.isSentByCurrentUser()) {
|
if (event.isSentByCurrentUser()) {
|
||||||
sp.getString(R.string.notice_room_topic_removed_by_you)
|
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? {
|
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()) {
|
return if (content.avatarUrl.isNullOrEmpty()) {
|
||||||
if (event.isSentByCurrentUser()) {
|
if (event.isSentByCurrentUser()) {
|
||||||
sp.getString(R.string.notice_room_avatar_removed_by_you)
|
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? {
|
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)
|
val historyVisibilitySuffix = roomHistoryVisibilityFormatter.getNoticeSuffix(historyVisibility)
|
||||||
return if (event.isSentByCurrentUser()) {
|
return if (event.isSentByCurrentUser()) {
|
||||||
|
@ -282,7 +282,7 @@ class NoticeEventFormatter @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun formatRoomThirdPartyInvite(event: Event, senderName: String?, isDm: Boolean): CharSequence? {
|
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>()
|
val prevContent = event.resolvedPrevContent()?.toModel<RoomThirdPartyInviteContent>()
|
||||||
|
|
||||||
return when {
|
return when {
|
||||||
|
@ -363,7 +363,7 @@ class NoticeEventFormatter @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun formatRoomMemberEvent(event: Event, senderName: String?, isDm: Boolean): String? {
|
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 prevEventContent: RoomMemberContent? = event.resolvedPrevContent().toModel()
|
||||||
val isMembershipEvent = prevEventContent?.membership != eventContent?.membership ||
|
val isMembershipEvent = prevEventContent?.membership != eventContent?.membership ||
|
||||||
eventContent?.membership == Membership.LEAVE
|
eventContent?.membership == Membership.LEAVE
|
||||||
|
@ -375,7 +375,7 @@ class NoticeEventFormatter @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun formatRoomAliasesEvent(event: Event, senderName: String?): String? {
|
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 prevEventContent: RoomAliasesContent? = event.resolvedPrevContent()?.toModel()
|
||||||
|
|
||||||
val addedAliases = eventContent?.aliases.orEmpty() - prevEventContent?.aliases.orEmpty()
|
val addedAliases = eventContent?.aliases.orEmpty() - prevEventContent?.aliases.orEmpty()
|
||||||
|
@ -408,7 +408,7 @@ class NoticeEventFormatter @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun formatRoomServerAclEvent(event: Event, senderName: String?): String? {
|
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>()
|
val prevEventContent = event.resolvedPrevContent()?.toModel<RoomServerAclContent>()
|
||||||
|
|
||||||
return buildString {
|
return buildString {
|
||||||
|
@ -481,7 +481,7 @@ class NoticeEventFormatter @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun formatRoomCanonicalAliasEvent(event: Event, senderName: String?): String? {
|
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 prevContent: RoomCanonicalAliasContent? = event.resolvedPrevContent().toModel()
|
||||||
val canonicalAlias = eventContent?.canonicalAlias?.takeIf { it.isNotEmpty() }
|
val canonicalAlias = eventContent?.canonicalAlias?.takeIf { it.isNotEmpty() }
|
||||||
val prevCanonicalAlias = prevContent?.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? {
|
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) {
|
return when (eventContent?.guestAccess) {
|
||||||
GuestAccess.CanJoin ->
|
GuestAccess.CanJoin ->
|
||||||
if (event.isSentByCurrentUser()) {
|
if (event.isSentByCurrentUser()) {
|
||||||
|
@ -815,7 +815,7 @@ class NoticeEventFormatter @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun formatJoinRulesEvent(event: Event, senderName: String?, isDm: Boolean): CharSequence? {
|
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) {
|
return when (content.joinRules) {
|
||||||
RoomJoinRules.INVITE ->
|
RoomJoinRules.INVITE ->
|
||||||
if (event.isSentByCurrentUser()) {
|
if (event.isSentByCurrentUser()) {
|
||||||
|
|
Loading…
Reference in New Issue