Do not hide own media (#6898)

This commit is contained in:
bxdxnn
2026-05-29 10:18:12 +03:00
committed by GitHub
parent b796436be6
commit e0cda170a9
7 changed files with 53 additions and 28 deletions
@@ -550,7 +550,7 @@ class MessagesPresenter(
val replyToDetails = loadReplyDetails(targetEvent.eventId).map(permalinkParser) val replyToDetails = loadReplyDetails(targetEvent.eventId).map(permalinkParser)
val composerMode = MessageComposerMode.Reply( val composerMode = MessageComposerMode.Reply(
replyToDetails = replyToDetails, replyToDetails = replyToDetails,
hideImage = timelineProtectionState.hideMediaContent(targetEvent.eventId), hideImage = timelineProtectionState.hideMediaContent(targetEvent.eventId, targetEvent.isMine),
) )
composerState.eventSink( composerState.eventSink(
MessageComposerEvent.SetMode(composerMode) MessageComposerEvent.SetMode(composerMode)
@@ -284,7 +284,7 @@ private fun TimelineItemEventContentViewWrapper(
} else { } else {
TimelineItemEventContentView( TimelineItemEventContentView(
content = event.content, content = event.content,
hideMediaContent = timelineProtectionState.hideMediaContent(event.eventId), hideMediaContent = timelineProtectionState.hideMediaContent(event.eventId, event.isMine),
onShowContentClick = { timelineProtectionState.eventSink(TimelineProtectionEvent.ShowContent(event.eventId)) }, onShowContentClick = { timelineProtectionState.eventSink(TimelineProtectionEvent.ShowContent(event.eventId)) },
onLinkClick = onLinkClick, onLinkClick = onLinkClick,
onLinkLongClick = onLinkLongClick, onLinkLongClick = onLinkLongClick,
@@ -63,7 +63,7 @@ fun TimelineItemGroupedEventsRow(
{ event, contentModifier, onContentLayoutChange -> { event, contentModifier, onContentLayoutChange ->
TimelineItemEventContentView( TimelineItemEventContentView(
content = event.content, content = event.content,
hideMediaContent = timelineProtectionState.hideMediaContent(event.eventId), hideMediaContent = timelineProtectionState.hideMediaContent(event.eventId, event.isMine),
onShowContentClick = { timelineProtectionState.eventSink(TimelineProtectionEvent.ShowContent(event.eventId)) }, onShowContentClick = { timelineProtectionState.eventSink(TimelineProtectionEvent.ShowContent(event.eventId)) },
onLinkClick = onLinkClick, onLinkClick = onLinkClick,
onLinkLongClick = onLinkLongClick, onLinkLongClick = onLinkLongClick,
@@ -136,7 +136,7 @@ private fun TimelineItemGroupedEventsRowContent(
{ event, contentModifier, onContentLayoutChange -> { event, contentModifier, onContentLayoutChange ->
TimelineItemEventContentView( TimelineItemEventContentView(
content = event.content, content = event.content,
hideMediaContent = timelineProtectionState.hideMediaContent(event.eventId), hideMediaContent = timelineProtectionState.hideMediaContent(event.eventId, event.isMine),
onShowContentClick = { timelineProtectionState.eventSink(TimelineProtectionEvent.ShowContent(event.eventId)) }, onShowContentClick = { timelineProtectionState.eventSink(TimelineProtectionEvent.ShowContent(event.eventId)) },
onLinkClick = onLinkClick, onLinkClick = onLinkClick,
onLinkLongClick = onLinkLongClick, onLinkLongClick = onLinkLongClick,
@@ -78,7 +78,7 @@ internal fun TimelineItemRow(
{ event, contentModifier, onContentLayoutChange -> { event, contentModifier, onContentLayoutChange ->
TimelineItemEventContentView( TimelineItemEventContentView(
content = event.content, content = event.content,
hideMediaContent = timelineProtectionState.hideMediaContent(event.eventId), hideMediaContent = timelineProtectionState.hideMediaContent(event.eventId, event.isMine),
onShowContentClick = { timelineProtectionState.eventSink(TimelineProtectionEvent.ShowContent(event.eventId)) }, onShowContentClick = { timelineProtectionState.eventSink(TimelineProtectionEvent.ShowContent(event.eventId)) },
onContentClick = { onContentClick(event) }, onContentClick = { onContentClick(event) },
onLongClick = { onLongClick(event) }, onLongClick = { onLongClick(event) },
@@ -34,26 +34,32 @@ import io.element.android.features.messages.impl.timeline.model.event.TimelineIt
*/ */
fun TimelineItem.mustBeProtected(): Boolean { fun TimelineItem.mustBeProtected(): Boolean {
return when (this) { return when (this) {
is TimelineItem.Event -> when (content) { is TimelineItem.Event -> {
is TimelineItemImageContent, if (isMine) {
is TimelineItemVideoContent, false
is TimelineItemStickerContent -> true } else {
is TimelineItemAudioContent, when (content) {
is TimelineItemRtcNotificationContent, is TimelineItemImageContent,
is TimelineItemEncryptedContent, is TimelineItemVideoContent,
is TimelineItemFileContent, is TimelineItemStickerContent -> true
TimelineItemLegacyCallInviteContent, is TimelineItemAudioContent,
is TimelineItemLocationContent, is TimelineItemRtcNotificationContent,
is TimelineItemPollContent, is TimelineItemEncryptedContent,
TimelineItemRedactedContent, is TimelineItemFileContent,
is TimelineItemProfileChangeContent, TimelineItemLegacyCallInviteContent,
is TimelineItemRoomMembershipContent, is TimelineItemLocationContent,
is TimelineItemStateEventContent, is TimelineItemPollContent,
is TimelineItemEmoteContent, TimelineItemRedactedContent,
is TimelineItemNoticeContent, is TimelineItemProfileChangeContent,
is TimelineItemTextContent, is TimelineItemRoomMembershipContent,
TimelineItemUnknownContent, is TimelineItemStateEventContent,
is TimelineItemVoiceContent -> false is TimelineItemEmoteContent,
is TimelineItemNoticeContent,
is TimelineItemTextContent,
TimelineItemUnknownContent,
is TimelineItemVoiceContent -> false
}
}
} }
is TimelineItem.Virtual -> false is TimelineItem.Virtual -> false
is TimelineItem.GroupedEvents -> false is TimelineItem.GroupedEvents -> false
@@ -16,9 +16,13 @@ data class TimelineProtectionState(
val protectionState: ProtectionState, val protectionState: ProtectionState,
val eventSink: (TimelineProtectionEvent) -> Unit, val eventSink: (TimelineProtectionEvent) -> Unit,
) { ) {
fun hideMediaContent(eventId: EventId?) = when (protectionState) { fun hideMediaContent(eventId: EventId?, isMine: Boolean = false) = if (isMine) {
is ProtectionState.RenderAll -> false false
is ProtectionState.RenderOnly -> eventId !in protectionState.eventIds } else {
when (protectionState) {
is ProtectionState.RenderAll -> false
is ProtectionState.RenderOnly -> eventId !in protectionState.eventIds
}
} }
} }
@@ -42,4 +42,19 @@ class TimelineProtectionStateTest {
assertThat(sut.hideMediaContent(AN_EVENT_ID)).isFalse() assertThat(sut.hideMediaContent(AN_EVENT_ID)).isFalse()
assertThat(sut.hideMediaContent(AN_EVENT_ID_2)).isTrue() assertThat(sut.hideMediaContent(AN_EVENT_ID_2)).isTrue()
} }
@Test
fun `when isMine is true, hideMediaContent always returns false regardless of state`() {
val sutRenderAll = aTimelineProtectionState(
protectionState = ProtectionState.RenderAll
)
assertThat(sutRenderAll.hideMediaContent(null, isMine = true)).isFalse()
assertThat(sutRenderAll.hideMediaContent(AN_EVENT_ID, isMine = true)).isFalse()
val sutRenderOnly = aTimelineProtectionState(
protectionState = ProtectionState.RenderOnly(persistentSetOf())
)
assertThat(sutRenderOnly.hideMediaContent(null, isMine = true)).isFalse()
assertThat(sutRenderOnly.hideMediaContent(AN_EVENT_ID, isMine = true)).isFalse()
}
} }