Merge pull request #4250 from nextcloud/conversation_creation_modification

Conversation creation modification
This commit is contained in:
Marcel Hibbe 2024-09-23 16:44:59 +02:00 committed by GitHub
commit 3b09da75a7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 34 additions and 29 deletions

View file

@ -1633,7 +1633,9 @@ class CallActivity : CallBaseActivity() {
private fun callOrJoinRoomViaWebSocket() { private fun callOrJoinRoomViaWebSocket() {
if (hasExternalSignalingServer) { if (hasExternalSignalingServer) {
webSocketClient!!.joinRoomWithRoomTokenAndSession( webSocketClient!!.joinRoomWithRoomTokenAndSession(
roomToken!!, callSession, externalSignalingServer!!.federation roomToken!!,
callSession,
externalSignalingServer!!.federation
) )
} else { } else {
performCall() performCall()

View file

@ -138,14 +138,14 @@ fun ConversationCreationScreen(
context: Context, context: Context,
pickImage: PickImage pickImage: PickImage
) { ) {
var selectedImageUri by remember { mutableStateOf<Uri?>(null) } val selectedImageUri = conversationCreationViewModel.selectedImageUri.collectAsState().value
val imagePickerLauncher = rememberLauncherForActivityResult( val imagePickerLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.StartActivityForResult() contract = ActivityResultContracts.StartActivityForResult()
) { result -> ) { result ->
if (result.resultCode == Activity.RESULT_OK) { if (result.resultCode == Activity.RESULT_OK) {
pickImage.onImagePickerResult(result.data) { uri -> pickImage.onImagePickerResult(result.data) { uri ->
selectedImageUri = uri conversationCreationViewModel.updateSelectedImageUri(uri)
} }
} }
} }
@ -205,17 +205,18 @@ fun ConversationCreationScreen(
DefaultUserAvatar(selectedImageUri) DefaultUserAvatar(selectedImageUri)
UploadAvatar( UploadAvatar(
pickImage = pickImage, pickImage = pickImage,
onImageSelected = { uri -> selectedImageUri = uri }, onImageSelected = { uri -> conversationCreationViewModel.updateSelectedImageUri(uri) },
imagePickerLauncher = imagePickerLauncher, imagePickerLauncher = imagePickerLauncher,
remoteFilePickerLauncher = remoteFilePickerLauncher, remoteFilePickerLauncher = remoteFilePickerLauncher,
cameraLauncher = cameraLauncher, cameraLauncher = cameraLauncher,
onDeleteImage = { selectedImageUri = null } onDeleteImage = { conversationCreationViewModel.updateSelectedImageUri(null) },
selectedImageUri = selectedImageUri
) )
ConversationNameAndDescription(conversationCreationViewModel) ConversationNameAndDescription(conversationCreationViewModel)
AddParticipants(launcher, context, conversationCreationViewModel) AddParticipants(launcher, context, conversationCreationViewModel)
RoomCreationOptions(conversationCreationViewModel) RoomCreationOptions(conversationCreationViewModel)
CreateConversation(conversationCreationViewModel, context, selectedImageUri) CreateConversation(conversationCreationViewModel, context)
} }
} }
) )
@ -258,7 +259,8 @@ fun UploadAvatar(
imagePickerLauncher: ManagedActivityResultLauncher<Intent, ActivityResult>, imagePickerLauncher: ManagedActivityResultLauncher<Intent, ActivityResult>,
remoteFilePickerLauncher: ManagedActivityResultLauncher<Intent, ActivityResult>, remoteFilePickerLauncher: ManagedActivityResultLauncher<Intent, ActivityResult>,
cameraLauncher: ManagedActivityResultLauncher<Intent, ActivityResult>, cameraLauncher: ManagedActivityResultLauncher<Intent, ActivityResult>,
onDeleteImage: () -> Unit onDeleteImage: () -> Unit,
selectedImageUri: Uri?
) { ) {
Row( Row(
modifier = Modifier modifier = Modifier
@ -299,6 +301,7 @@ fun UploadAvatar(
) )
} }
if (selectedImageUri != null) {
IconButton(onClick = { IconButton(onClick = {
onDeleteImage() onDeleteImage()
}) { }) {
@ -310,6 +313,7 @@ fun UploadAvatar(
} }
} }
} }
}
@Composable @Composable
fun ConversationNameAndDescription(conversationCreationViewModel: ConversationCreationViewModel) { fun ConversationNameAndDescription(conversationCreationViewModel: ConversationCreationViewModel) {
@ -323,7 +327,8 @@ fun ConversationNameAndDescription(conversationCreationViewModel: ConversationCr
label = { Text(text = stringResource(id = R.string.nc_call_name)) }, label = { Text(text = stringResource(id = R.string.nc_call_name)) },
modifier = Modifier modifier = Modifier
.padding(start = 16.dp, end = 16.dp) .padding(start = 16.dp, end = 16.dp)
.fillMaxWidth() .fillMaxWidth(),
singleLine = true
) )
OutlinedTextField( OutlinedTextField(
value = conversationDescription.value, value = conversationDescription.value,
@ -549,7 +554,6 @@ fun ShowPasswordDialog(onDismiss: () -> Unit, conversationCreationViewModel: Con
AlertDialog( AlertDialog(
containerColor = colorResource(id = R.color.dialog_background), containerColor = colorResource(id = R.color.dialog_background),
onDismissRequest = onDismiss, onDismissRequest = onDismiss,
confirmButton = { confirmButton = {
Button(onClick = { Button(onClick = {
@ -578,11 +582,7 @@ fun ShowPasswordDialog(onDismiss: () -> Unit, conversationCreationViewModel: Con
} }
@Composable @Composable
fun CreateConversation( fun CreateConversation(conversationCreationViewModel: ConversationCreationViewModel, context: Context) {
conversationCreationViewModel: ConversationCreationViewModel,
context: Context,
selectedImageUri: Uri?
) {
val selectedParticipants by conversationCreationViewModel.selectedParticipants.collectAsState() val selectedParticipants by conversationCreationViewModel.selectedParticipants.collectAsState()
Box( Box(
modifier = Modifier modifier = Modifier
@ -595,8 +595,7 @@ fun CreateConversation(
conversationCreationViewModel.createRoomAndAddParticipants( conversationCreationViewModel.createRoomAndAddParticipants(
roomType = CompanionClass.ROOM_TYPE_GROUP, roomType = CompanionClass.ROOM_TYPE_GROUP,
conversationName = conversationCreationViewModel.roomName.value, conversationName = conversationCreationViewModel.roomName.value,
participants = selectedParticipants.toSet(), participants = selectedParticipants.toSet()
selectedImageUri = selectedImageUri
) { roomToken -> ) { roomToken ->
val bundle = Bundle() val bundle = Bundle()
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomToken) bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomToken)

View file

@ -32,6 +32,9 @@ class ConversationCreationViewModel @Inject constructor(
val selectedParticipants: StateFlow<List<AutocompleteUser>> = _selectedParticipants val selectedParticipants: StateFlow<List<AutocompleteUser>> = _selectedParticipants
private val roomViewState = MutableStateFlow<RoomUIState>(RoomUIState.None) private val roomViewState = MutableStateFlow<RoomUIState>(RoomUIState.None)
private val _selectedImageUri = MutableStateFlow<Uri?>(null)
val selectedImageUri: StateFlow<Uri?> = _selectedImageUri
private val _currentUser = userManager.currentUser.blockingGet() private val _currentUser = userManager.currentUser.blockingGet()
val currentUser: User = _currentUser val currentUser: User = _currentUser
@ -39,6 +42,10 @@ class ConversationCreationViewModel @Inject constructor(
_selectedParticipants.value = participants _selectedParticipants.value = participants
} }
fun updateSelectedImageUri(uri: Uri?) {
_selectedImageUri.value = uri
}
private val _roomName = MutableStateFlow("") private val _roomName = MutableStateFlow("")
val roomName: StateFlow<String> = _roomName val roomName: StateFlow<String> = _roomName
private val _password = MutableStateFlow("") private val _password = MutableStateFlow("")
@ -66,7 +73,6 @@ class ConversationCreationViewModel @Inject constructor(
roomType: String, roomType: String,
conversationName: String, conversationName: String,
participants: Set<AutocompleteUser>, participants: Set<AutocompleteUser>,
selectedImageUri: Uri?,
onRoomCreated: (String) -> Unit onRoomCreated: (String) -> Unit
) { ) {
val scope = when { val scope = when {
@ -109,9 +115,7 @@ class ConversationCreationViewModel @Inject constructor(
repository.setPassword(token, _password.value) repository.setPassword(token, _password.value)
} }
repository.openConversation(token, scope) repository.openConversation(token, scope)
if (selectedImageUri != null) { selectedImageUri.value?.let { repository.uploadConversationAvatar(it.toFile(), token) }
repository.uploadConversationAvatar(selectedImageUri.toFile(), token)
}
onRoomCreated(token) onRoomCreated(token)
} catch (exception: Exception) { } catch (exception: Exception) {
allowGuestsResult.value = AllowGuestsUiState.Error(exception.message ?: "") allowGuestsResult.value = AllowGuestsUiState.Error(exception.message ?: "")