mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-29 01:48:53 +03:00
make conversation available for registered users and guest app users
Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
parent
1187b41e51
commit
5f3d73efce
6 changed files with 74 additions and 12 deletions
|
@ -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(
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<Int?> = mutableStateOf(null)
|
||||
|
||||
private val addParticipantsViewState = MutableStateFlow<AddParticipantsUiState>(AddParticipantsUiState.None)
|
||||
val addParticipantsUiState: StateFlow<AddParticipantsUiState> = addParticipantsViewState
|
||||
|
@ -111,6 +113,11 @@ class ConversationCreationViewModel @Inject constructor(
|
|||
participants: Set<AutocompleteUser>,
|
||||
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 ?: "")
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue