Merge pull request #4258 from nextcloud/backport/4250/stable-20.0

[stable-20.0] Conversation creation modification
This commit is contained in:
Marcel Hibbe 2024-09-23 16:45:24 +02:00 committed by GitHub
commit b4d8a7ee20
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() {
if (hasExternalSignalingServer) {
webSocketClient!!.joinRoomWithRoomTokenAndSession(
roomToken!!, callSession, externalSignalingServer!!.federation
roomToken!!,
callSession,
externalSignalingServer!!.federation
)
} else {
performCall()

View file

@ -3240,7 +3240,7 @@ class ChatActivity :
val lon = data["longitude"]!!
metaData =
"{\"type\":\"geo-location\",\"id\":\"geo:$lat,$lon\",\"latitude\":\"$lat\"," +
"\"longitude\":\"$lon\",\"name\":\"$name\"}"
"\"longitude\":\"$lon\",\"name\":\"$name\"}"
}
when (type) {

View file

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

View file

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