diff --git a/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt b/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt index 874df93b2..d08d2b317 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt +++ b/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt @@ -60,6 +60,14 @@ interface NcApiCoroutines { @Field("roomName") roomName: String? ): GenericOverall + @FormUrlEncoded + @PUT + suspend fun openConversation( + @Header("Authorization") authorization: String?, + @Url url: String, + @Field("scope") scope: Int + ): GenericOverall + @FormUrlEncoded @PUT suspend fun setConversationDescription( diff --git a/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationActivity.kt b/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationActivity.kt index 8b89b0dd2..c5dfdfc4b 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationActivity.kt @@ -351,14 +351,16 @@ fun RoomCreationOptions(conversationCreationViewModel: ConversationCreationViewM } ) }, - showDialog = false + showDialog = false, + conversationCreationViewModel = conversationCreationViewModel ) if (isGuestsAllowed) { ConversationOptions( icon = R.drawable.ic_lock_grey600_24px, text = R.string.nc_set_password, - showDialog = true + showDialog = true, + conversationCreationViewModel = conversationCreationViewModel ) } @@ -373,7 +375,8 @@ fun RoomCreationOptions(conversationCreationViewModel: ConversationCreationViewM } ) }, - showDialog = false + showDialog = false, + conversationCreationViewModel = conversationCreationViewModel ) if (isConversationAvailableForRegisteredUsers) { @@ -387,13 +390,21 @@ fun RoomCreationOptions(conversationCreationViewModel: ConversationCreationViewM } ) }, - showDialog = false + showDialog = false, + conversationCreationViewModel = conversationCreationViewModel ) } } @Composable -fun ConversationOptions(icon: Int? = null, text: Int, switch: @Composable (() -> Unit)? = null, showDialog: Boolean) { +fun ConversationOptions( + icon: Int? = null, + text: Int, + switch: @Composable (() -> Unit)? = null, + showDialog: Boolean, + conversationCreationViewModel: ConversationCreationViewModel +) { + var showPasswordDialog by remember { mutableStateOf(false) } Row( modifier = Modifier .fillMaxWidth() @@ -401,6 +412,7 @@ fun ConversationOptions(icon: Int? = null, text: Int, switch: @Composable (() -> .then( if (showDialog) { Modifier.clickable { + showPasswordDialog = true } } else { Modifier @@ -426,29 +438,41 @@ fun ConversationOptions(icon: Int? = null, text: Int, switch: @Composable (() -> if (switch != null) { switch() } + if (showPasswordDialog) { + ShowPasswordDialog( + onDismiss = { showPasswordDialog = false }, + conversationCreationViewModel = conversationCreationViewModel + ) + } } } @Composable -fun ShowPasswordDialog() { +fun ShowPasswordDialog(onDismiss: () -> Unit, conversationCreationViewModel: ConversationCreationViewModel) { var password by remember { mutableStateOf("") } AlertDialog( - onDismissRequest = { /*TODO*/ }, + onDismissRequest = onDismiss, confirmButton = { Button(onClick = { + conversationCreationViewModel.updatePassword(password) + onDismiss() }) { - Text(text = stringResource(id = R.string.nc_cancel)) + Text(text = "Save") } }, title = { Text(text = "Set Password") }, text = { - TextField(value = password, onValueChange = { - password = it - }) + TextField( + value = password, + onValueChange = { + password = it + }, + label = { Text(text = "Enter a password") } + ) }, dismissButton = { - Button(onClick = { /* Handle cancel */ }) { + Button(onClick = { onDismiss() }) { Text(text = stringResource(id = R.string.nc_cancel)) } } diff --git a/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationRepository.kt b/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationRepository.kt index cd3b295c9..6ebb6c350 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationRepository.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationRepository.kt @@ -16,6 +16,7 @@ interface ConversationCreationRepository { suspend fun allowGuests(token: String, allow: Boolean): GenericOverall suspend fun renameConversation(roomToken: String, roomNameNew: String?): GenericOverall suspend fun setConversationDescription(roomToken: String, description: String?): GenericOverall + suspend fun openConversation(roomToken: String, scope: Int): GenericOverall suspend fun addParticipants(conversationToken: String?, userId: String, sourceType: String): AddParticipantOverall suspend fun createRoom(roomType: String, conversationName: String?): RoomOverall fun getImageUri(avatarId: String, requestBigSize: Boolean): String diff --git a/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationRepositoryImpl.kt b/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationRepositoryImpl.kt index df2fd538c..4e00f174c 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationRepositoryImpl.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationRepositoryImpl.kt @@ -51,6 +51,18 @@ class ConversationCreationRepositoryImpl( ) } + override suspend fun openConversation(roomToken: String, scope: Int): GenericOverall { + return ncApiCoroutines.openConversation( + credentials, + ApiUtils.getUrlForOpeningConversations( + apiVersion, + _currentUser.baseUrl, + roomToken + ), + scope + ) + } + override suspend fun addParticipants( conversationToken: String?, userId: String, diff --git a/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationViewModel.kt b/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationViewModel.kt index b69fc9b71..9a097f9ab 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationViewModel.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationcreation/ConversationCreationViewModel.kt @@ -8,6 +8,7 @@ package com.nextcloud.talk.conversationcreation import android.util.Log +import androidx.compose.runtime.MutableState import androidx.compose.runtime.mutableStateOf import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope @@ -41,6 +42,7 @@ class ConversationCreationViewModel @Inject constructor( var isGuestsAllowed = mutableStateOf(false) var isConversationAvailableForRegisteredUsers = mutableStateOf(false) var openForGuestAppUsers = mutableStateOf(false) + private val scope: MutableState = mutableStateOf(null) private val addParticipantsViewState = MutableStateFlow(AddParticipantsUiState.None) val addParticipantsUiState: StateFlow = addParticipantsViewState @@ -111,6 +113,11 @@ class ConversationCreationViewModel @Inject constructor( participants: Set, onRoomCreated: (String) -> Unit ) { + val scope = when { + isConversationAvailableForRegisteredUsers.value && !openForGuestAppUsers.value -> 1 + isConversationAvailableForRegisteredUsers.value && openForGuestAppUsers.value -> 2 + else -> 0 + } viewModelScope.launch { _roomViewState.value = RoomUIState.None try { @@ -121,6 +128,10 @@ class ConversationCreationViewModel @Inject constructor( val token = conversation.token if (token != null) { try { + val conversationDescription = repository.setConversationDescription( + token, + _conversationDescription.value + ) val allowGuestsResult = repository.allowGuests(token, isGuestsAllowed.value) val statusCode: GenericMeta? = allowGuestsResult.ocs?.meta val result = (statusCode?.statusCode == STATUS_CODE_OK) @@ -138,6 +149,8 @@ class ConversationCreationViewModel @Inject constructor( } } } + val passwordResult = repository.setPassword(token, _password.value) + repository.openConversation(token, scope) onRoomCreated(token) } catch (exception: Exception) { _allowGuestsResult.value = AllowGuestsUiState.Error(exception.message ?: "") diff --git a/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.kt b/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.kt index 28d4e4ff7..c0168c413 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.kt +++ b/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.kt @@ -539,6 +539,10 @@ object ApiUtils { return getUrlForRoom(version, baseUrl, token) + "/description" } + fun getUrlForOpeningConversations(version: Int, baseUrl: String?, token: String): String { + return getUrlForRoom(version, baseUrl, token) + "/listable" + } + fun getUrlForTranslation(baseUrl: String): String { return "$baseUrl$OCS_API_VERSION/translation/translate" }