fix: an admin's refused leave is shown, not thrown out of the view model (member-admin-promotion, Phase 10a)
leaveGroup called the repository inside viewModelScope.launch and caught nothing, so "An admin cannot leave; hand over admin first" escaped the coroutine: never shown, and on Android a crash. It now goes to an onFailed callback the screen reports through the notifier, as disbandGroup does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8088efd732
commit
2ed83c55ab
4 files changed
+106
-12
No files matched your search
@@ -106,6 +106,7 @@
|
||||
<string name="key_recovery">Key recovery</string>
|
||||
<string name="learn_more">Learn more</string>
|
||||
<string name="leave_group">Leave group</string>
|
||||
<string name="couldn_t_leave_the_group">Couldn't leave the group</string>
|
||||
<string name="remove_from_group">Remove from group</string>
|
||||
<string name="disband_group">Disband group</string>
|
||||
<string name="group_disbanded">This group was disbanded. Nothing more can be sent into it, and nobody can rejoin.</string>
|
||||
|
||||
+4
-1
@@ -81,6 +81,7 @@ import mobi.giza.compose.ui.view.model.ChatRoomDetailViewModel
|
||||
import mobi.giza.compose.ui.view.state.ChatRoomDetailUIState
|
||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import mobi.giza.compose.ui.theme.spacing
|
||||
import mobi.giza.compose.resources.couldn_t_leave_the_group
|
||||
import mobi.giza.compose.resources.run_by_members
|
||||
import mobi.giza.compose.resources.parent_group
|
||||
import mobi.giza.compose.resources.a_subgroup
|
||||
@@ -183,6 +184,7 @@ fun ChatRoomDetailScreen(
|
||||
// composable, and a lambda passed to onClick is not.
|
||||
val notify = rememberNotifier(rememberCoroutineScope())
|
||||
val removalRequested = stringResource(Res.string.member_removal_requested)
|
||||
val couldNotLeave = stringResource(Res.string.couldn_t_leave_the_group)
|
||||
val rotationRequested = stringResource(Res.string.share_rotation_requested)
|
||||
val sharesActionSent = stringResource(Res.string.shares_action_sent)
|
||||
|
||||
@@ -810,7 +812,8 @@ fun ChatRoomDetailScreen(
|
||||
onClick = {
|
||||
chatRoomDetailViewModel.leaveGroup(
|
||||
localChatRoom = chatRoomDetailUIState.localChatRoom,
|
||||
onPopBackToRoute = onPopBackToRoute
|
||||
onPopBackToRoute = onPopBackToRoute,
|
||||
onFailed = { failure -> notify(failure ?: couldNotLeave) },
|
||||
)
|
||||
}
|
||||
) {
|
||||
|
||||
+25
-11
@@ -194,23 +194,37 @@ class ChatRoomDetailViewModel(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Leaves the group, then leaves the screen. A refusal -- an admin, who has to
|
||||
* hand over admin first -- goes to [onFailed] in the words the refusal used, and
|
||||
* the screen stays. It used to escape the coroutine, which nobody saw and which
|
||||
* on Android is a crash. See docs/member-admin-promotion.md, Phase 10.
|
||||
*/
|
||||
fun leaveGroup(
|
||||
localChatRoom: LocalChatRoom,
|
||||
onPopBackToRoute: (Route) -> Unit
|
||||
onPopBackToRoute: (Route) -> Unit,
|
||||
onFailed: (String?) -> Unit = {},
|
||||
) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
chatRepository.leaveChatRoom(
|
||||
localChatRoom,
|
||||
onCompletion = {
|
||||
viewModelScope.launch(Dispatchers.Main) {
|
||||
onPopBackToRoute.invoke(
|
||||
HomeRoute(
|
||||
activeUserPublicKey = activeUserPublicKey,
|
||||
val failure = runCatching {
|
||||
chatRepository.leaveChatRoom(
|
||||
localChatRoom,
|
||||
onCompletion = {
|
||||
viewModelScope.launch(Dispatchers.Main) {
|
||||
onPopBackToRoute.invoke(
|
||||
HomeRoute(
|
||||
activeUserPublicKey = activeUserPublicKey,
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
}.exceptionOrNull()
|
||||
if (failure is CancellationException) throw failure
|
||||
if (failure != null) {
|
||||
logger.w(throwable = failure) { "Couldn't leave $chatRoomId" }
|
||||
viewModelScope.launch(Dispatchers.Main) { onFailed(failure.message) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user