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?
|
@Field("roomName") roomName: String?
|
||||||
): GenericOverall
|
): GenericOverall
|
||||||
|
|
||||||
|
@FormUrlEncoded
|
||||||
|
@PUT
|
||||||
|
suspend fun openConversation(
|
||||||
|
@Header("Authorization") authorization: String?,
|
||||||
|
@Url url: String,
|
||||||
|
@Field("scope") scope: Int
|
||||||
|
): GenericOverall
|
||||||
|
|
||||||
@FormUrlEncoded
|
@FormUrlEncoded
|
||||||
@PUT
|
@PUT
|
||||||
suspend fun setConversationDescription(
|
suspend fun setConversationDescription(
|
||||||
|
|
|
@ -351,14 +351,16 @@ fun RoomCreationOptions(conversationCreationViewModel: ConversationCreationViewM
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
showDialog = false
|
showDialog = false,
|
||||||
|
conversationCreationViewModel = conversationCreationViewModel
|
||||||
)
|
)
|
||||||
|
|
||||||
if (isGuestsAllowed) {
|
if (isGuestsAllowed) {
|
||||||
ConversationOptions(
|
ConversationOptions(
|
||||||
icon = R.drawable.ic_lock_grey600_24px,
|
icon = R.drawable.ic_lock_grey600_24px,
|
||||||
text = R.string.nc_set_password,
|
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) {
|
if (isConversationAvailableForRegisteredUsers) {
|
||||||
|
@ -387,13 +390,21 @@ fun RoomCreationOptions(conversationCreationViewModel: ConversationCreationViewM
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
showDialog = false
|
showDialog = false,
|
||||||
|
conversationCreationViewModel = conversationCreationViewModel
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@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(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
|
@ -401,6 +412,7 @@ fun ConversationOptions(icon: Int? = null, text: Int, switch: @Composable (() ->
|
||||||
.then(
|
.then(
|
||||||
if (showDialog) {
|
if (showDialog) {
|
||||||
Modifier.clickable {
|
Modifier.clickable {
|
||||||
|
showPasswordDialog = true
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Modifier
|
Modifier
|
||||||
|
@ -426,29 +438,41 @@ fun ConversationOptions(icon: Int? = null, text: Int, switch: @Composable (() ->
|
||||||
if (switch != null) {
|
if (switch != null) {
|
||||||
switch()
|
switch()
|
||||||
}
|
}
|
||||||
|
if (showPasswordDialog) {
|
||||||
|
ShowPasswordDialog(
|
||||||
|
onDismiss = { showPasswordDialog = false },
|
||||||
|
conversationCreationViewModel = conversationCreationViewModel
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ShowPasswordDialog() {
|
fun ShowPasswordDialog(onDismiss: () -> Unit, conversationCreationViewModel: ConversationCreationViewModel) {
|
||||||
var password by remember { mutableStateOf("") }
|
var password by remember { mutableStateOf("") }
|
||||||
|
|
||||||
AlertDialog(
|
AlertDialog(
|
||||||
onDismissRequest = { /*TODO*/ },
|
onDismissRequest = onDismiss,
|
||||||
confirmButton = {
|
confirmButton = {
|
||||||
Button(onClick = {
|
Button(onClick = {
|
||||||
|
conversationCreationViewModel.updatePassword(password)
|
||||||
|
onDismiss()
|
||||||
}) {
|
}) {
|
||||||
Text(text = stringResource(id = R.string.nc_cancel))
|
Text(text = "Save")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
title = { Text(text = "Set Password") },
|
title = { Text(text = "Set Password") },
|
||||||
text = {
|
text = {
|
||||||
TextField(value = password, onValueChange = {
|
TextField(
|
||||||
|
value = password,
|
||||||
|
onValueChange = {
|
||||||
password = it
|
password = it
|
||||||
})
|
},
|
||||||
|
label = { Text(text = "Enter a password") }
|
||||||
|
)
|
||||||
},
|
},
|
||||||
dismissButton = {
|
dismissButton = {
|
||||||
Button(onClick = { /* Handle cancel */ }) {
|
Button(onClick = { onDismiss() }) {
|
||||||
Text(text = stringResource(id = R.string.nc_cancel))
|
Text(text = stringResource(id = R.string.nc_cancel))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ interface ConversationCreationRepository {
|
||||||
suspend fun allowGuests(token: String, allow: Boolean): GenericOverall
|
suspend fun allowGuests(token: String, allow: Boolean): GenericOverall
|
||||||
suspend fun renameConversation(roomToken: String, roomNameNew: String?): GenericOverall
|
suspend fun renameConversation(roomToken: String, roomNameNew: String?): GenericOverall
|
||||||
suspend fun setConversationDescription(roomToken: String, description: 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 addParticipants(conversationToken: String?, userId: String, sourceType: String): AddParticipantOverall
|
||||||
suspend fun createRoom(roomType: String, conversationName: String?): RoomOverall
|
suspend fun createRoom(roomType: String, conversationName: String?): RoomOverall
|
||||||
fun getImageUri(avatarId: String, requestBigSize: Boolean): String
|
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(
|
override suspend fun addParticipants(
|
||||||
conversationToken: String?,
|
conversationToken: String?,
|
||||||
userId: String,
|
userId: String,
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
package com.nextcloud.talk.conversationcreation
|
package com.nextcloud.talk.conversationcreation
|
||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import androidx.compose.runtime.MutableState
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
|
@ -41,6 +42,7 @@ class ConversationCreationViewModel @Inject constructor(
|
||||||
var isGuestsAllowed = mutableStateOf(false)
|
var isGuestsAllowed = mutableStateOf(false)
|
||||||
var isConversationAvailableForRegisteredUsers = mutableStateOf(false)
|
var isConversationAvailableForRegisteredUsers = mutableStateOf(false)
|
||||||
var openForGuestAppUsers = mutableStateOf(false)
|
var openForGuestAppUsers = mutableStateOf(false)
|
||||||
|
private val scope: MutableState<Int?> = mutableStateOf(null)
|
||||||
|
|
||||||
private val addParticipantsViewState = MutableStateFlow<AddParticipantsUiState>(AddParticipantsUiState.None)
|
private val addParticipantsViewState = MutableStateFlow<AddParticipantsUiState>(AddParticipantsUiState.None)
|
||||||
val addParticipantsUiState: StateFlow<AddParticipantsUiState> = addParticipantsViewState
|
val addParticipantsUiState: StateFlow<AddParticipantsUiState> = addParticipantsViewState
|
||||||
|
@ -111,6 +113,11 @@ class ConversationCreationViewModel @Inject constructor(
|
||||||
participants: Set<AutocompleteUser>,
|
participants: Set<AutocompleteUser>,
|
||||||
onRoomCreated: (String) -> Unit
|
onRoomCreated: (String) -> Unit
|
||||||
) {
|
) {
|
||||||
|
val scope = when {
|
||||||
|
isConversationAvailableForRegisteredUsers.value && !openForGuestAppUsers.value -> 1
|
||||||
|
isConversationAvailableForRegisteredUsers.value && openForGuestAppUsers.value -> 2
|
||||||
|
else -> 0
|
||||||
|
}
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
_roomViewState.value = RoomUIState.None
|
_roomViewState.value = RoomUIState.None
|
||||||
try {
|
try {
|
||||||
|
@ -121,6 +128,10 @@ class ConversationCreationViewModel @Inject constructor(
|
||||||
val token = conversation.token
|
val token = conversation.token
|
||||||
if (token != null) {
|
if (token != null) {
|
||||||
try {
|
try {
|
||||||
|
val conversationDescription = repository.setConversationDescription(
|
||||||
|
token,
|
||||||
|
_conversationDescription.value
|
||||||
|
)
|
||||||
val allowGuestsResult = repository.allowGuests(token, isGuestsAllowed.value)
|
val allowGuestsResult = repository.allowGuests(token, isGuestsAllowed.value)
|
||||||
val statusCode: GenericMeta? = allowGuestsResult.ocs?.meta
|
val statusCode: GenericMeta? = allowGuestsResult.ocs?.meta
|
||||||
val result = (statusCode?.statusCode == STATUS_CODE_OK)
|
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)
|
onRoomCreated(token)
|
||||||
} catch (exception: Exception) {
|
} catch (exception: Exception) {
|
||||||
_allowGuestsResult.value = AllowGuestsUiState.Error(exception.message ?: "")
|
_allowGuestsResult.value = AllowGuestsUiState.Error(exception.message ?: "")
|
||||||
|
|
|
@ -539,6 +539,10 @@ object ApiUtils {
|
||||||
return getUrlForRoom(version, baseUrl, token) + "/description"
|
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 {
|
fun getUrlForTranslation(baseUrl: String): String {
|
||||||
return "$baseUrl$OCS_API_VERSION/translation/translate"
|
return "$baseUrl$OCS_API_VERSION/translation/translate"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue