Skip to content

Commit 71066ca

Browse files
committed
fix(chat): wait for chatNotFound in an effect, not in composition
Lint's FlowOperatorInvokedInComposition failed lintDebug on #1763: the flow mapped stateFlow during composition, building a new flow on every recomposition. The effect now waits for the flag with first(), and reads strings from LocalResources.
1 parent c22b282 commit 71066ca

1 file changed

Lines changed: 10 additions & 14 deletions

File tree

  • apps/flipcash/features/messenger/src/main/kotlin/com/flipcash/app/messenger

‎apps/flipcash/features/messenger/src/main/kotlin/com/flipcash/app/messenger/ChatFlowScreen.kt‎

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import androidx.compose.runtime.mutableStateOf
88
import androidx.compose.runtime.remember
99
import androidx.compose.runtime.saveable.rememberSaveable
1010
import androidx.compose.runtime.setValue
11-
import androidx.compose.ui.platform.LocalContext
11+
import androidx.compose.ui.platform.LocalResources
1212
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
1313
import androidx.lifecycle.compose.collectAsStateWithLifecycle
1414
import androidx.navigation3.runtime.NavEntry
@@ -63,7 +63,7 @@ import com.getcode.navigation.scenes.ModalBottomSheetSceneStrategy
6363
import com.getcode.ui.utils.rememberKeyboardController
6464
import kotlinx.coroutines.flow.filterIsInstance
6565
import kotlinx.coroutines.flow.launchIn
66-
import kotlinx.coroutines.flow.map
66+
import kotlinx.coroutines.flow.first
6767
import kotlinx.coroutines.flow.onEach
6868

6969
@Composable
@@ -83,18 +83,14 @@ fun ChatFlowScreen(
8383
// A group link the server has no record of: say so and leave, rather than sit on an empty chat
8484
// with a composer. Other opens ignore it (see AppRoute.Messaging.Chat.isGroupLink).
8585
if (route.isGroupLink) {
86-
val resources = LocalContext.current.resources
87-
val chatNotFound by viewModel.stateFlow
88-
.map { it.chatNotFound }
89-
.collectAsStateWithLifecycle(initialValue = false)
90-
LaunchedEffect(chatNotFound) {
91-
if (chatNotFound) {
92-
BottomBarManager.showError(
93-
title = resources.getString(R.string.error_title_groupNotFound),
94-
message = resources.getString(R.string.error_description_groupNotFound),
95-
)
96-
keyboard.hideIfVisible { navigator.pop() }
97-
}
86+
val resources = LocalResources.current
87+
LaunchedEffect(viewModel) {
88+
viewModel.stateFlow.first { it.chatNotFound }
89+
BottomBarManager.showError(
90+
title = resources.getString(R.string.error_title_groupNotFound),
91+
message = resources.getString(R.string.error_description_groupNotFound),
92+
)
93+
keyboard.hideIfVisible { navigator.pop() }
9894
}
9995
}
10096

0 commit comments

Comments
 (0)