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,7 +34,11 @@ 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 -> {
if (isMine) {
false
} else {
when (content) {
is TimelineItemImageContent, is TimelineItemImageContent,
is TimelineItemVideoContent, is TimelineItemVideoContent,
is TimelineItemStickerContent -> true is TimelineItemStickerContent -> true
@@ -55,6 +59,8 @@ fun TimelineItem.mustBeProtected(): Boolean {
TimelineItemUnknownContent, TimelineItemUnknownContent,
is TimelineItemVoiceContent -> false is TimelineItemVoiceContent -> false
} }
}
}
is TimelineItem.Virtual -> false is TimelineItem.Virtual -> false
is TimelineItem.GroupedEvents -> false is TimelineItem.GroupedEvents -> false
} }
@@ -16,10 +16,14 @@ 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) {
false
} else {
when (protectionState) {
is ProtectionState.RenderAll -> false is ProtectionState.RenderAll -> false
is ProtectionState.RenderOnly -> eventId !in protectionState.eventIds is ProtectionState.RenderOnly -> eventId !in protectionState.eventIds
} }
}
} }
@Immutable @Immutable
@@ -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()
}
} }