From 9a2d23c8a126a0df1f4e40a8401dbe2bdff125b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Mart=C3=ADn?= Date: Fri, 21 Aug 2026 12:07:38 +0200 Subject: [PATCH] Remove unnecessary `GlobalSearchPresenter.Factory` --- .../home/impl/roomlist/RoomListPresenter.kt | 8 ++------ .../home/impl/search/GlobalSearchPresenter.kt | 16 +++++----------- .../home/impl/roomlist/RoomListPresenterTest.kt | 9 +++------ .../impl/search/GlobalSearchPresenterTest.kt | 2 -- 4 files changed, 10 insertions(+), 25 deletions(-) diff --git a/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/roomlist/RoomListPresenter.kt b/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/roomlist/RoomListPresenter.kt index 47b02cac08..1c21177988 100644 --- a/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/roomlist/RoomListPresenter.kt +++ b/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/roomlist/RoomListPresenter.kt @@ -30,7 +30,7 @@ import io.element.android.features.announcement.api.AnnouncementService import io.element.android.features.home.impl.datasource.RoomListDataSource import io.element.android.features.home.impl.filters.RoomListFiltersState import io.element.android.features.home.impl.filters.into -import io.element.android.features.home.impl.search.GlobalSearchPresenter +import io.element.android.features.home.impl.search.GlobalSearchState import io.element.android.features.home.impl.search.RoomListSearchEvent import io.element.android.features.home.impl.search.RoomListSearchState import io.element.android.features.home.impl.spacefilters.SpaceFiltersState @@ -86,15 +86,11 @@ class RoomListPresenter( private val announcementService: AnnouncementService, private val coldStartWatcher: AnalyticsColdStartWatcher, private val spaceFiltersPresenter: Presenter, - private val globalSearchPresenterFactory: GlobalSearchPresenter.Factory, + private val globalSearchPresenter: Presenter, private val featureFlagService: FeatureFlagService, ) : Presenter { private val encryptionService = client.encryptionService - private val globalSearchPresenter by lazy { - globalSearchPresenterFactory.create(coroutineScope = client.sessionCoroutineScope) - } - @Composable override fun present(): RoomListState { val coroutineScope = rememberCoroutineScope() diff --git a/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/search/GlobalSearchPresenter.kt b/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/search/GlobalSearchPresenter.kt index 11de6e7c80..0014d70ff8 100644 --- a/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/search/GlobalSearchPresenter.kt +++ b/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/search/GlobalSearchPresenter.kt @@ -15,16 +15,16 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.produceState import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue -import dev.zacsweers.metro.Assisted -import dev.zacsweers.metro.AssistedFactory -import dev.zacsweers.metro.AssistedInject +import dev.zacsweers.metro.ContributesBinding import io.element.android.libraries.androidutils.filesize.FileSizeFormatter import io.element.android.libraries.architecture.AsyncData import io.element.android.libraries.architecture.Presenter import io.element.android.libraries.core.coroutine.CoroutineDispatchers import io.element.android.libraries.dateformatter.api.DateFormatter import io.element.android.libraries.dateformatter.api.DateFormatterMode +import io.element.android.libraries.di.SessionScope import io.element.android.libraries.eventformatter.api.RoomLatestEventFormatter import io.element.android.libraries.featureflag.api.FeatureFlagService import io.element.android.libraries.featureflag.api.FeatureFlags @@ -48,7 +48,6 @@ import io.element.android.libraries.matrix.api.timeline.item.event.isMediaConten import io.element.android.libraries.matrix.ui.components.AttachmentThumbnailType import io.element.android.libraries.matrix.ui.messages.toPlainText import kotlinx.collections.immutable.toImmutableList -import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll import kotlinx.coroutines.delay @@ -58,9 +57,8 @@ import kotlinx.coroutines.launch import kotlin.jvm.optionals.getOrElse import kotlin.time.Duration.Companion.milliseconds -@AssistedInject +@ContributesBinding(SessionScope::class) class GlobalSearchPresenter( - @Assisted private val coroutineScope: CoroutineScope, private val roomListSearchDataSourceFactory: RoomListSearchDataSource.Factory, private val messageSearchService: MessageSearchService, private val featureFlagService: FeatureFlagService, @@ -71,13 +69,9 @@ class GlobalSearchPresenter( private val coroutineDispatchers: CoroutineDispatchers, private val matrixClient: MatrixClient, ) : Presenter { - @AssistedFactory - fun interface Factory { - fun create(coroutineScope: CoroutineScope): GlobalSearchPresenter - } - @Composable override fun present(): GlobalSearchState { + val coroutineScope = rememberCoroutineScope() val isEnabled by produceState(false) { featureFlagService.isFeatureEnabledFlow(FeatureFlags.MessageSearch).collectLatest { value = it } } diff --git a/features/home/impl/src/test/kotlin/io/element/android/features/home/impl/roomlist/RoomListPresenterTest.kt b/features/home/impl/src/test/kotlin/io/element/android/features/home/impl/roomlist/RoomListPresenterTest.kt index 8cfc47fe43..470aaaa441 100644 --- a/features/home/impl/src/test/kotlin/io/element/android/features/home/impl/roomlist/RoomListPresenterTest.kt +++ b/features/home/impl/src/test/kotlin/io/element/android/features/home/impl/roomlist/RoomListPresenterTest.kt @@ -683,12 +683,9 @@ class RoomListPresenterTest { analyticsService = FakeAnalyticsService(), ), searchPresenter = searchPresenter, - globalSearchPresenterFactory = object : GlobalSearchPresenter.Factory { - override fun create(coroutineScope: CoroutineScope) = createGlobalSearchPresenter( - matrixClient = client, - coroutineScope = coroutineScope, - ) - }, + globalSearchPresenter = createGlobalSearchPresenter( + matrixClient = client, + ), filtersPresenter = filtersPresenter, spaceFiltersPresenter = spaceFiltersPresenter, analyticsService = analyticsService, diff --git a/features/home/impl/src/test/kotlin/io/element/android/features/home/impl/search/GlobalSearchPresenterTest.kt b/features/home/impl/src/test/kotlin/io/element/android/features/home/impl/search/GlobalSearchPresenterTest.kt index 7469ea4e84..3f5fe802f9 100644 --- a/features/home/impl/src/test/kotlin/io/element/android/features/home/impl/search/GlobalSearchPresenterTest.kt +++ b/features/home/impl/src/test/kotlin/io/element/android/features/home/impl/search/GlobalSearchPresenterTest.kt @@ -211,10 +211,8 @@ internal fun TestScope.createGlobalSearchPresenter( fileSizeFormatter: FileSizeFormatter = FakeFileSizeFormatter(), permalinkParser: PermalinkParser = FakePermalinkParser(), matrixClient: MatrixClient = FakeMatrixClient(), - coroutineScope: CoroutineScope = backgroundScope, ): GlobalSearchPresenter { return GlobalSearchPresenter( - coroutineScope = coroutineScope, roomListSearchDataSourceFactory = object : RoomListSearchDataSource.Factory { override fun create(coroutineScope: CoroutineScope): RoomListSearchDataSource { return RoomListSearchDataSource(