Skip to content

DROID-3659 Multiplayer | Support link without approve, fixes #2445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ class RequestJoinSpaceFragment : BaseBottomSheetComposeFragment() {
JoinSpaceWithoutApproveScreen(
isLoading = isLoading,
onRequestJoinSpaceClicked = vm::onRequestToJoinClicked,
onCancelClicked = {
vm.onCancelJoinSpaceRequestClicked()
dismiss()
},
spaceName = spaceName,
createdByName = createdByName
)
Expand All @@ -155,6 +159,10 @@ class RequestJoinSpaceFragment : BaseBottomSheetComposeFragment() {
onRequestJoinSpaceClicked = vm::onRequestToJoinClicked,
spaceName = spaceName,
createdByName = createdByName,
onCancelClicked = {
vm.onCancelJoinSpaceRequestClicked()
dismiss()
}
)
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.anytypeio.anytype.core_ui.views.Title2
@Composable
fun JoinSpaceScreen(
onRequestJoinSpaceClicked: () -> Unit,
onCancelClicked: () -> Unit,
spaceName: String,
createdByName: String,
isLoading: Boolean = false
Expand Down Expand Up @@ -87,7 +88,16 @@ fun JoinSpaceScreen(
loading = isLoading
)
}
Spacer(modifier = Modifier.height(20.dp))
Spacer(modifier = Modifier.height(8.dp))
ButtonSecondary(
onClick = throttledClick(
onClick = { onCancelClicked() }
),
text = stringResource(R.string.cancel),
modifier = Modifier.fillMaxWidth(),
size = ButtonSize.Large,
)
Spacer(modifier = Modifier.height(10.dp))
Text(
text = stringResource(R.string.multiplayer_request_to_join_explanation),
style = Caption1Regular,
Expand All @@ -102,6 +112,7 @@ fun JoinSpaceScreen(
@Composable
fun JoinSpaceWithoutApproveScreen(
onRequestJoinSpaceClicked: () -> Unit,
onCancelClicked: () -> Unit,
spaceName: String,
createdByName: String,
isLoading: Boolean = false
Expand Down Expand Up @@ -162,7 +173,7 @@ fun JoinSpaceWithoutApproveScreen(
Spacer(modifier = Modifier.height(8.dp))
ButtonSecondary(
onClick = throttledClick(
onClick = { onRequestJoinSpaceClicked() }
onClick = { onCancelClicked() }
),
text = stringResource(R.string.cancel),
modifier = Modifier.fillMaxWidth(),
Expand All @@ -172,6 +183,63 @@ fun JoinSpaceWithoutApproveScreen(
}
}

@Composable
fun JoinSpaceRequestSentScreen(
onDoneClicked: () -> Unit,
onManageSpaces: () -> Unit
) {
Column(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp)
) {
Dragger(
modifier = Modifier
.align(Alignment.CenterHorizontally)
.padding(vertical = 6.dp)
)
Spacer(modifier = Modifier.height(16.dp))
Text(
text = stringResource(R.string.multiplayer_request_to_join_sent_title,),
style = HeadlineHeading,
color = colorResource(id = R.color.text_primary),
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp),
textAlign = TextAlign.Center
)
Spacer(modifier = Modifier.height(8.dp))
Text(
text = stringResource(R.string.multiplayer_request_to_join_sent_description,),
style = Title2,
color = colorResource(id = R.color.text_primary),
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp),
textAlign = TextAlign.Center
)
Spacer(modifier = Modifier.height(19.dp))
ButtonPrimaryLoading(
onClick = throttledClick(
onClick = { }
),
size = ButtonSize.Large,
text = stringResource(R.string.done),
modifierButton = Modifier.fillMaxWidth(),
)
Spacer(modifier = Modifier.height(8.dp))
ButtonSecondary(
onClick = throttledClick(
onClick = { }
),
text = stringResource(R.string.multiplayer_request_to_join_btn_manage_spaces),
modifier = Modifier.fillMaxWidth(),
size = ButtonSize.Large,
)
Spacer(modifier = Modifier.height(16.dp))
}
}

@Composable
fun JoiningLoadingState(
onCancelLoadingInviteClicked: () -> Unit
Expand Down Expand Up @@ -227,7 +295,8 @@ fun JoinSpaceScreenPreview() {
JoinSpaceScreen(
onRequestJoinSpaceClicked = {},
spaceName = "Anytype Android App",
createdByName = "Konstantin"
createdByName = "Konstantin",
onCancelClicked = {}
)
}

Expand All @@ -237,7 +306,8 @@ fun JoinSpaceScreenPreviewWithEmptyNames() {
JoinSpaceScreen(
onRequestJoinSpaceClicked = {},
spaceName = "",
createdByName = ""
createdByName = "",
onCancelClicked = {}
)
}

Expand All @@ -247,6 +317,7 @@ fun JoinSpaceScreenPreviewWithoutApprove() {
JoinSpaceWithoutApproveScreen(
onRequestJoinSpaceClicked = {},
spaceName = "",
createdByName = ""
createdByName = "",
onCancelClicked = {}
)
}
3 changes: 3 additions & 0 deletions localization/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1361,6 +1361,9 @@
<string name="multiplayer_request_to_join_without_approve_title">Join %1$s</string>
<string name="multiplayer_request_to_join_without_approve_desc">You\'ve been invited to join %1$s, created by %2$s</string>
<string name="multiplayer_request_to_join_without_approve_button">Join Space</string>
<string name="multiplayer_request_to_join_sent_title">Request sent</string>
<string name="multiplayer_request_to_join_sent_description">You will receive a notification when the space owner will approve your request.</string>
<string name="multiplayer_request_to_join_btn_manage_spaces">Manage spaces</string>

<string name="multiplayer_request_to_join_loading_text"> Hang tight β€” we’re setting things up for you. This should only take a moment.</string>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import com.anytypeio.anytype.presentation.common.BaseViewModel
import com.anytypeio.anytype.presentation.common.TypedViewState
import javax.inject.Inject
import kotlinx.coroutines.Job
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.launch
Expand All @@ -54,6 +53,7 @@ class RequestJoinSpaceViewModel(
val commands = MutableSharedFlow<Command>(0)
val showLoadingInviteProgress = MutableStateFlow(false)
private var getSpaceInviteViewJob: Job? = null
private var joinSpaceRequestJob: Job? = null

init {
Timber.i("RequestJoinSpaceViewModel, init")
Expand Down Expand Up @@ -132,7 +132,8 @@ class RequestJoinSpaceViewModel(
fun onRequestToJoinClicked() {
when(val curr = state.value) {
is TypedViewState.Success -> {
viewModelScope.launch {
joinSpaceRequestJob?.cancel()
joinSpaceRequestJob = viewModelScope.launch {
val fileKey = spaceInviteResolver.parseFileKey(params.link)
val contentId = spaceInviteResolver.parseContentId(params.link)
if (contentId != null && fileKey != null) {
Expand All @@ -156,10 +157,14 @@ class RequestJoinSpaceViewModel(
onSuccess = {
analytics.sendEvent(eventName = screenRequestSent)
if (notificator.areNotificationsEnabled) {
commands.emit(Command.Toast.RequestSent)
if (!curr.data.withoutApprove) {
commands.emit(Command.Toast.RequestSent)
}
commands.emit(Command.Dismiss)
} else {
commands.emit(Command.Toast.RequestSent)
if (!curr.data.withoutApprove) {
commands.emit(Command.Toast.RequestSent)
}
showEnableNotificationDialog.value = true
}
}
Expand All @@ -173,6 +178,11 @@ class RequestJoinSpaceViewModel(
}
}

fun onCancelJoinSpaceRequestClicked() {
joinSpaceRequestJob?.cancel()
isRequestInProgress.value = false
}

fun onOpenSpaceClicked(space: SpaceId) {
viewModelScope.launch {
val curr = spaceManager.get()
Expand Down