mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-3659 Multiplayer | Invite link without approve (#2407)
This commit is contained in:
parent
b43fff9472
commit
300709aaa2
17 changed files with 375 additions and 133 deletions
|
@ -27,6 +27,8 @@ import com.anytypeio.anytype.domain.workspace.SpaceManager
|
|||
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
|
||||
|
@ -50,6 +52,8 @@ class RequestJoinSpaceViewModel(
|
|||
val isRequestInProgress = MutableStateFlow(false)
|
||||
val showEnableNotificationDialog = MutableStateFlow(false)
|
||||
val commands = MutableSharedFlow<Command>(0)
|
||||
val showLoadingInviteProgress = MutableStateFlow(false)
|
||||
private var getSpaceInviteViewJob: Job? = null
|
||||
|
||||
init {
|
||||
Timber.i("RequestJoinSpaceViewModel, init")
|
||||
|
@ -60,7 +64,8 @@ class RequestJoinSpaceViewModel(
|
|||
val fileKey = spaceInviteResolver.parseFileKey(params.link)
|
||||
val contentId = spaceInviteResolver.parseContentId(params.link)
|
||||
if (fileKey != null && contentId != null) {
|
||||
viewModelScope.launch {
|
||||
showLoadingInviteProgress.value = true
|
||||
getSpaceInviteViewJob = viewModelScope.launch {
|
||||
getSpaceInviteView.async(
|
||||
GetSpaceInviteView.Params(
|
||||
inviteContentId = contentId,
|
||||
|
@ -68,6 +73,7 @@ class RequestJoinSpaceViewModel(
|
|||
)
|
||||
).fold(
|
||||
onSuccess = { view ->
|
||||
showLoadingInviteProgress.value = false
|
||||
val isAlreadyMember = checkIsUserSpaceMember
|
||||
.async(view.space)
|
||||
.getOrDefault(false)
|
||||
|
@ -85,6 +91,7 @@ class RequestJoinSpaceViewModel(
|
|||
}
|
||||
},
|
||||
onFailure = { e ->
|
||||
showLoadingInviteProgress.value = false
|
||||
if (e is SpaceInviteError) {
|
||||
when(e) {
|
||||
is SpaceInviteError.InvalidInvite -> {
|
||||
|
@ -117,6 +124,11 @@ class RequestJoinSpaceViewModel(
|
|||
}
|
||||
}
|
||||
|
||||
fun onCancelLoadingInviteClicked() {
|
||||
getSpaceInviteViewJob?.cancel()
|
||||
showLoadingInviteProgress.value = false
|
||||
}
|
||||
|
||||
fun onRequestToJoinClicked() {
|
||||
when(val curr = state.value) {
|
||||
is TypedViewState.Success -> {
|
||||
|
|
|
@ -23,6 +23,7 @@ import com.anytypeio.anytype.core_models.Id
|
|||
import com.anytypeio.anytype.core_models.ObjectWrapper
|
||||
import com.anytypeio.anytype.core_models.ext.isPossibleToUpgradeNumberOfSpaceMembers
|
||||
import com.anytypeio.anytype.core_models.membership.TierId
|
||||
import com.anytypeio.anytype.core_models.multiplayer.InviteType
|
||||
import com.anytypeio.anytype.core_models.multiplayer.MultiplayerError
|
||||
import com.anytypeio.anytype.core_models.multiplayer.ParticipantStatus
|
||||
import com.anytypeio.anytype.core_models.multiplayer.SpaceAccessType
|
||||
|
@ -203,7 +204,10 @@ class ShareSpaceViewModel(
|
|||
}
|
||||
}
|
||||
|
||||
private fun proceedWithGeneratingInviteLink() {
|
||||
private fun proceedWithGeneratingInviteLink(
|
||||
inviteType: InviteType = InviteType.MEMBER,
|
||||
permissions: SpaceMemberPermissions = SpaceMemberPermissions.READER
|
||||
) {
|
||||
viewModelScope.launch {
|
||||
if (spaceAccessType.value == SpaceAccessType.PRIVATE) {
|
||||
makeSpaceShareable.async(
|
||||
|
@ -212,27 +216,44 @@ class ShareSpaceViewModel(
|
|||
onSuccess = {
|
||||
analytics.sendEvent(eventName = EventsDictionary.shareSpace)
|
||||
Timber.d("Successfully made space shareable")
|
||||
generateInviteLink(
|
||||
inviteType = inviteType,
|
||||
permissions = permissions
|
||||
)
|
||||
},
|
||||
onFailure = {
|
||||
Timber.e(it, "Error while making space shareable")
|
||||
proceedWithMultiplayerError(it)
|
||||
}
|
||||
)
|
||||
}
|
||||
generateSpaceInviteLink
|
||||
.async(vmParams.space)
|
||||
.fold(
|
||||
onSuccess = { link ->
|
||||
shareLinkViewState.value = ShareLinkViewState.Shared(link = link.scheme)
|
||||
},
|
||||
onFailure = {
|
||||
Timber.e(it, "Error while generating invite link")
|
||||
proceedWithMultiplayerError(it)
|
||||
}
|
||||
} else {
|
||||
generateInviteLink(
|
||||
inviteType = inviteType,
|
||||
permissions = permissions
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun generateInviteLink(inviteType: InviteType, permissions: SpaceMemberPermissions) {
|
||||
generateSpaceInviteLink.async(
|
||||
params = GenerateSpaceInviteLink.Params(
|
||||
space = vmParams.space,
|
||||
inviteType = inviteType,
|
||||
permissions = permissions
|
||||
)
|
||||
).fold(
|
||||
onSuccess = { inviteLink ->
|
||||
shareLinkViewState.value = ShareLinkViewState.Shared(inviteLink.scheme)
|
||||
Timber.d("Successfully generated invite link")
|
||||
},
|
||||
onFailure = {
|
||||
Timber.e(it, "Error while generating invite link")
|
||||
proceedWithMultiplayerError(it)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
fun onShareInviteLinkClicked() {
|
||||
viewModelScope.launch {
|
||||
when (val value = shareLinkViewState.value) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue