Do not hide own media (#6898)
This commit is contained in:
+1
-1
@@ -550,7 +550,7 @@ class MessagesPresenter(
|
||||
val replyToDetails = loadReplyDetails(targetEvent.eventId).map(permalinkParser)
|
||||
val composerMode = MessageComposerMode.Reply(
|
||||
replyToDetails = replyToDetails,
|
||||
hideImage = timelineProtectionState.hideMediaContent(targetEvent.eventId),
|
||||
hideImage = timelineProtectionState.hideMediaContent(targetEvent.eventId, targetEvent.isMine),
|
||||
)
|
||||
composerState.eventSink(
|
||||
MessageComposerEvent.SetMode(composerMode)
|
||||
|
||||
+1
-1
@@ -284,7 +284,7 @@ private fun TimelineItemEventContentViewWrapper(
|
||||
} else {
|
||||
TimelineItemEventContentView(
|
||||
content = event.content,
|
||||
hideMediaContent = timelineProtectionState.hideMediaContent(event.eventId),
|
||||
hideMediaContent = timelineProtectionState.hideMediaContent(event.eventId, event.isMine),
|
||||
onShowContentClick = { timelineProtectionState.eventSink(TimelineProtectionEvent.ShowContent(event.eventId)) },
|
||||
onLinkClick = onLinkClick,
|
||||
onLinkLongClick = onLinkLongClick,
|
||||
|
||||
+2
-2
@@ -63,7 +63,7 @@ fun TimelineItemGroupedEventsRow(
|
||||
{ event, contentModifier, onContentLayoutChange ->
|
||||
TimelineItemEventContentView(
|
||||
content = event.content,
|
||||
hideMediaContent = timelineProtectionState.hideMediaContent(event.eventId),
|
||||
hideMediaContent = timelineProtectionState.hideMediaContent(event.eventId, event.isMine),
|
||||
onShowContentClick = { timelineProtectionState.eventSink(TimelineProtectionEvent.ShowContent(event.eventId)) },
|
||||
onLinkClick = onLinkClick,
|
||||
onLinkLongClick = onLinkLongClick,
|
||||
@@ -136,7 +136,7 @@ private fun TimelineItemGroupedEventsRowContent(
|
||||
{ event, contentModifier, onContentLayoutChange ->
|
||||
TimelineItemEventContentView(
|
||||
content = event.content,
|
||||
hideMediaContent = timelineProtectionState.hideMediaContent(event.eventId),
|
||||
hideMediaContent = timelineProtectionState.hideMediaContent(event.eventId, event.isMine),
|
||||
onShowContentClick = { timelineProtectionState.eventSink(TimelineProtectionEvent.ShowContent(event.eventId)) },
|
||||
onLinkClick = onLinkClick,
|
||||
onLinkLongClick = onLinkLongClick,
|
||||
|
||||
+1
-1
@@ -78,7 +78,7 @@ internal fun TimelineItemRow(
|
||||
{ event, contentModifier, onContentLayoutChange ->
|
||||
TimelineItemEventContentView(
|
||||
content = event.content,
|
||||
hideMediaContent = timelineProtectionState.hideMediaContent(event.eventId),
|
||||
hideMediaContent = timelineProtectionState.hideMediaContent(event.eventId, event.isMine),
|
||||
onShowContentClick = { timelineProtectionState.eventSink(TimelineProtectionEvent.ShowContent(event.eventId)) },
|
||||
onContentClick = { onContentClick(event) },
|
||||
onLongClick = { onLongClick(event) },
|
||||
|
||||
+26
-20
@@ -34,26 +34,32 @@ import io.element.android.features.messages.impl.timeline.model.event.TimelineIt
|
||||
*/
|
||||
fun TimelineItem.mustBeProtected(): Boolean {
|
||||
return when (this) {
|
||||
is TimelineItem.Event -> when (content) {
|
||||
is TimelineItemImageContent,
|
||||
is TimelineItemVideoContent,
|
||||
is TimelineItemStickerContent -> true
|
||||
is TimelineItemAudioContent,
|
||||
is TimelineItemRtcNotificationContent,
|
||||
is TimelineItemEncryptedContent,
|
||||
is TimelineItemFileContent,
|
||||
TimelineItemLegacyCallInviteContent,
|
||||
is TimelineItemLocationContent,
|
||||
is TimelineItemPollContent,
|
||||
TimelineItemRedactedContent,
|
||||
is TimelineItemProfileChangeContent,
|
||||
is TimelineItemRoomMembershipContent,
|
||||
is TimelineItemStateEventContent,
|
||||
is TimelineItemEmoteContent,
|
||||
is TimelineItemNoticeContent,
|
||||
is TimelineItemTextContent,
|
||||
TimelineItemUnknownContent,
|
||||
is TimelineItemVoiceContent -> false
|
||||
is TimelineItem.Event -> {
|
||||
if (isMine) {
|
||||
false
|
||||
} else {
|
||||
when (content) {
|
||||
is TimelineItemImageContent,
|
||||
is TimelineItemVideoContent,
|
||||
is TimelineItemStickerContent -> true
|
||||
is TimelineItemAudioContent,
|
||||
is TimelineItemRtcNotificationContent,
|
||||
is TimelineItemEncryptedContent,
|
||||
is TimelineItemFileContent,
|
||||
TimelineItemLegacyCallInviteContent,
|
||||
is TimelineItemLocationContent,
|
||||
is TimelineItemPollContent,
|
||||
TimelineItemRedactedContent,
|
||||
is TimelineItemProfileChangeContent,
|
||||
is TimelineItemRoomMembershipContent,
|
||||
is TimelineItemStateEventContent,
|
||||
is TimelineItemEmoteContent,
|
||||
is TimelineItemNoticeContent,
|
||||
is TimelineItemTextContent,
|
||||
TimelineItemUnknownContent,
|
||||
is TimelineItemVoiceContent -> false
|
||||
}
|
||||
}
|
||||
}
|
||||
is TimelineItem.Virtual -> false
|
||||
is TimelineItem.GroupedEvents -> false
|
||||
|
||||
+7
-3
@@ -16,9 +16,13 @@ data class TimelineProtectionState(
|
||||
val protectionState: ProtectionState,
|
||||
val eventSink: (TimelineProtectionEvent) -> Unit,
|
||||
) {
|
||||
fun hideMediaContent(eventId: EventId?) = when (protectionState) {
|
||||
is ProtectionState.RenderAll -> false
|
||||
is ProtectionState.RenderOnly -> eventId !in protectionState.eventIds
|
||||
fun hideMediaContent(eventId: EventId?, isMine: Boolean = false) = if (isMine) {
|
||||
false
|
||||
} else {
|
||||
when (protectionState) {
|
||||
is ProtectionState.RenderAll -> false
|
||||
is ProtectionState.RenderOnly -> eventId !in protectionState.eventIds
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+15
@@ -42,4 +42,19 @@ class TimelineProtectionStateTest {
|
||||
assertThat(sut.hideMediaContent(AN_EVENT_ID)).isFalse()
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user