Skip to content

Commit

Permalink
Rename hideContent to hideMediaContent
Browse files Browse the repository at this point in the history
  • Loading branch information
bmarty committed Oct 4, 2024
1 parent 6ee0dd3 commit 0bb2fee
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ class MessagesPresenter @AssistedInject constructor(
val replyToDetails = loadReplyDetails(targetEvent.eventId).map(permalinkParser)
val composerMode = MessageComposerMode.Reply(
replyToDetails = replyToDetails,
hideImage = timelineProtectionState.hideContent(targetEvent.eventId),
hideImage = timelineProtectionState.hideMediaContent(targetEvent.eventId),
)
composerState.eventSink(
MessageComposerEvents.SetMode(composerMode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ private fun TimelineItemEventContentViewWrapper(
} else {
TimelineItemEventContentView(
content = event.content,
hideContent = timelineProtectionState.hideContent(event.eventId),
hideMediaContent = timelineProtectionState.hideMediaContent(event.eventId),
onShowClick = { timelineProtectionState.eventSink(TimelineProtectionEvent.ShowContent(event.eventId)) },
onLinkClick = onLinkClick,
eventSink = { },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ fun TimelineItemEventRow(
eventContentView: @Composable (Modifier, (ContentAvoidingLayoutData) -> Unit) -> Unit = { contentModifier, onContentLayoutChange ->
TimelineItemEventContentView(
content = event.content,
hideContent = timelineProtectionState.hideContent(event.eventId),
hideMediaContent = timelineProtectionState.hideMediaContent(event.eventId),
onShowClick = { timelineProtectionState.eventSink(TimelineProtectionEvent.ShowContent(event.eventId)) },
onLinkClick = onLinkClick,
eventSink = eventSink,
Expand Down Expand Up @@ -569,7 +569,7 @@ private fun MessageEventBubbleContent(
.clickable(onClick = inReplyToClick)
InReplyToView(
inReplyTo = inReplyTo,
hideImage = timelineProtectionState.hideContent(inReplyTo.eventId()),
hideImage = timelineProtectionState.hideMediaContent(inReplyTo.eventId()),
modifier = inReplyToModifier,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fun TimelineItemGroupedEventsRow(
{ event, contentModifier, onContentLayoutChange ->
TimelineItemEventContentView(
content = event.content,
hideContent = timelineProtectionState.hideContent(event.eventId),
hideMediaContent = timelineProtectionState.hideMediaContent(event.eventId),
onShowClick = { timelineProtectionState.eventSink(TimelineProtectionEvent.ShowContent(event.eventId)) },
onLinkClick = onLinkClick,
eventSink = eventSink,
Expand Down Expand Up @@ -120,7 +120,7 @@ private fun TimelineItemGroupedEventsRowContent(
{ event, contentModifier, onContentLayoutChange ->
TimelineItemEventContentView(
content = event.content,
hideContent = timelineProtectionState.hideContent(event.eventId),
hideMediaContent = timelineProtectionState.hideMediaContent(event.eventId),
onShowClick = { timelineProtectionState.eventSink(TimelineProtectionEvent.ShowContent(event.eventId)) },
onLinkClick = onLinkClick,
eventSink = eventSink,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ internal fun TimelineItemRow(
{ event, contentModifier, onContentLayoutChange ->
TimelineItemEventContentView(
content = event.content,
hideContent = timelineProtectionState.hideContent(event.eventId),
hideMediaContent = timelineProtectionState.hideMediaContent(event.eventId),
onShowClick = { timelineProtectionState.eventSink(TimelineProtectionEvent.ShowContent(event.eventId)) },
onLinkClick = onLinkClick,
eventSink = eventSink,
Expand Down Expand Up @@ -118,7 +118,7 @@ internal fun TimelineItemRow(
timelineProtectionState = timelineProtectionState,
isLastOutgoingMessage = isLastOutgoingMessage,
isHighlighted = timelineItem.isEvent(focusedEventId),
onClick = if (timelineProtectionState.hideContent(timelineItem.eventId) && timelineItem.mustBeProtected()) {
onClick = if (timelineProtectionState.hideMediaContent(timelineItem.eventId) && timelineItem.mustBeProtected()) {
{}
} else {
{ onClick(timelineItem) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fun TimelineItemStateEventRow(
TimelineItemEventContentView(
content = event.content,
onLinkClick = {},
hideContent = false,
hideMediaContent = false,
onShowClick = {},
eventSink = eventSink,
modifier = Modifier.defaultTimelineContentPadding()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import io.element.android.libraries.architecture.Presenter
@Composable
fun TimelineItemEventContentView(
content: TimelineItemEventContent,
hideContent: Boolean,
hideMediaContent: Boolean,
onShowClick: () -> Unit,
onLinkClick: (url: String) -> Unit,
eventSink: (TimelineEvents.EventFromTimelineItem) -> Unit,
Expand Down Expand Up @@ -71,20 +71,20 @@ fun TimelineItemEventContentView(
)
is TimelineItemImageContent -> TimelineItemImageView(
content = content,
hideContent = hideContent,
hideMediaContent = hideMediaContent,
onShowClick = onShowClick,
onContentLayoutChange = onContentLayoutChange,
modifier = modifier,
)
is TimelineItemStickerContent -> TimelineItemStickerView(
content = content,
hideContent = hideContent,
hideMediaContent = hideMediaContent,
onShowClick = onShowClick,
modifier = modifier,
)
is TimelineItemVideoContent -> TimelineItemVideoView(
content = content,
hideContent = hideContent,
hideMediaContent = hideMediaContent,
onShowClick = onShowClick,
onContentLayoutChange = onContentLayoutChange,
modifier = modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import io.element.android.wysiwyg.compose.EditorStyledText
@Composable
fun TimelineItemImageView(
content: TimelineItemImageContent,
hideContent: Boolean,
hideMediaContent: Boolean,
onShowClick: () -> Unit,
onContentLayoutChange: (ContentAvoidingLayoutData) -> Unit,
modifier: Modifier = Modifier,
Expand All @@ -80,7 +80,7 @@ fun TimelineItemImageView(
aspectRatio = content.aspectRatio,
) {
ProtectedView(
hideContent = hideContent,
hideContent = hideMediaContent,
onShowClick = onShowClick,
) {
var isLoaded by remember { mutableStateOf(false) }
Expand Down Expand Up @@ -133,18 +133,18 @@ fun TimelineItemImageView(
internal fun TimelineItemImageViewPreview(@PreviewParameter(TimelineItemImageContentProvider::class) content: TimelineItemImageContent) = ElementPreview {
TimelineItemImageView(
content = content,
hideContent = false,
hideMediaContent = false,
onShowClick = {},
onContentLayoutChange = {},
)
}

@PreviewsDayNight
@Composable
internal fun TimelineItemImageViewHideContentPreview() = ElementPreview {
internal fun TimelineItemImageViewHideMediaContentPreview() = ElementPreview {
TimelineItemImageView(
content = aTimelineItemImageContent(),
hideContent = true,
hideMediaContent = true,
onShowClick = {},
onContentLayoutChange = {},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private const val STICKER_SIZE_IN_DP = 128
@Composable
fun TimelineItemStickerView(
content: TimelineItemStickerContent,
hideContent: Boolean,
hideMediaContent: Boolean,
onShowClick: () -> Unit,
modifier: Modifier = Modifier,
) {
Expand All @@ -54,7 +54,7 @@ fun TimelineItemStickerView(
maxHeight = STICKER_SIZE_IN_DP,
) {
ProtectedView(
hideContent = hideContent,
hideContent = hideMediaContent,
onShowClick = onShowClick,
) {
var isLoaded by remember { mutableStateOf(false) }
Expand Down Expand Up @@ -84,7 +84,7 @@ fun TimelineItemStickerView(
internal fun TimelineItemStickerViewPreview(@PreviewParameter(TimelineItemStickerContentProvider::class) content: TimelineItemStickerContent) = ElementPreview {
TimelineItemStickerView(
content = content,
hideContent = false,
hideMediaContent = false,
onShowClick = {},
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import io.element.android.wysiwyg.compose.EditorStyledText
@Composable
fun TimelineItemVideoView(
content: TimelineItemVideoContent,
hideContent: Boolean,
hideMediaContent: Boolean,
onShowClick: () -> Unit,
onContentLayoutChange: (ContentAvoidingLayoutData) -> Unit,
modifier: Modifier = Modifier,
Expand All @@ -87,7 +87,7 @@ fun TimelineItemVideoView(
contentAlignment = Alignment.Center,
) {
ProtectedView(
hideContent = hideContent,
hideContent = hideMediaContent,
onShowClick = onShowClick,
) {
var isLoaded by remember { mutableStateOf(false) }
Expand Down Expand Up @@ -151,18 +151,18 @@ fun TimelineItemVideoView(
internal fun TimelineItemVideoViewPreview(@PreviewParameter(TimelineItemVideoContentProvider::class) content: TimelineItemVideoContent) = ElementPreview {
TimelineItemVideoView(
content = content,
hideContent = false,
hideMediaContent = false,
onShowClick = {},
onContentLayoutChange = {},
)
}

@PreviewsDayNight
@Composable
internal fun TimelineItemVideoViewHideContentPreview() = ElementPreview {
internal fun TimelineItemVideoViewHideMediaContentPreview() = ElementPreview {
TimelineItemVideoView(
content = aTimelineItemVideoContent(),
hideContent = true,
hideMediaContent = true,
onShowClick = {},
onContentLayoutChange = {},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ class TimelineProtectionPresenter @Inject constructor(
) : Presenter<TimelineProtectionState> {
@Composable
override fun present(): TimelineProtectionState {
val hideContent by appPreferencesStore.doesHideImagesAndVideosFlow().collectAsState(initial = false)
val hideMediaContent by appPreferencesStore.doesHideImagesAndVideosFlow().collectAsState(initial = false)
var allowedEvents by remember { mutableStateOf<Set<EventId>>(setOf()) }
val protectionState by remember(hideContent) {
val protectionState by remember(hideMediaContent) {
derivedStateOf {
if (hideContent) {
if (hideMediaContent) {
ProtectionState.RenderOnly(eventIds = allowedEvents.toImmutableSet())
} else {
ProtectionState.RenderAll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ data class TimelineProtectionState(
val protectionState: ProtectionState,
val eventSink: (TimelineProtectionEvent) -> Unit,
) {
fun hideContent(eventId: EventId?) = when (protectionState) {
fun hideMediaContent(eventId: EventId?) = when (protectionState) {
is ProtectionState.RenderAll -> false
is ProtectionState.RenderOnly -> eventId !in protectionState.eventIds
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,30 @@ import org.junit.Test

class TimelineProtectionStateTest {
@Test
fun `when protectionState is RenderAll, hideContent always return null`() {
fun `when protectionState is RenderAll, hideMediaContent always return null`() {
val sut = aTimelineProtectionState(
protectionState = ProtectionState.RenderAll
)
assertThat(sut.hideContent(null)).isFalse()
assertThat(sut.hideContent(AN_EVENT_ID)).isFalse()
assertThat(sut.hideMediaContent(null)).isFalse()
assertThat(sut.hideMediaContent(AN_EVENT_ID)).isFalse()
}

@Test
fun `when protectionState is RenderOnly with empty set, hideContent always return true`() {
fun `when protectionState is RenderOnly with empty set, hideMediaContent always return true`() {
val sut = aTimelineProtectionState(
protectionState = ProtectionState.RenderOnly(persistentSetOf())
)
assertThat(sut.hideContent(null)).isTrue()
assertThat(sut.hideContent(AN_EVENT_ID)).isTrue()
assertThat(sut.hideMediaContent(null)).isTrue()
assertThat(sut.hideMediaContent(AN_EVENT_ID)).isTrue()
}

@Test
fun `when protectionState is RenderOnly with an Event, hideContent can return true or false`() {
fun `when protectionState is RenderOnly with an Event, hideMediaContent can return true or false`() {
val sut = aTimelineProtectionState(
protectionState = ProtectionState.RenderOnly(persistentSetOf(AN_EVENT_ID))
)
assertThat(sut.hideContent(null)).isTrue()
assertThat(sut.hideContent(AN_EVENT_ID)).isFalse()
assertThat(sut.hideContent(AN_EVENT_ID_2)).isTrue()
assertThat(sut.hideMediaContent(null)).isTrue()
assertThat(sut.hideMediaContent(AN_EVENT_ID)).isFalse()
assertThat(sut.hideMediaContent(AN_EVENT_ID_2)).isTrue()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ class KonsistPreviewTest {
"TimelineItemEventRowWithReplyPreview",
"TimelineItemGroupedEventsRowContentCollapsePreview",
"TimelineItemGroupedEventsRowContentExpandedPreview",
"TimelineItemImageViewHideContentPreview",
"TimelineItemVideoViewHideContentPreview",
"TimelineItemImageViewHideMediaContentPreview",
"TimelineItemVideoViewHideMediaContentPreview",
"TimelineItemVoiceViewUnifiedPreview",
"TimelineVideoWithCaptionRowPreview",
"TimelineViewMessageShieldPreview",
Expand Down

0 comments on commit 0bb2fee

Please sign in to comment.