Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable-20.0] Conversation creation modification #4258

Merged
merged 5 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1633,7 +1633,9 @@ class CallActivity : CallBaseActivity() {
private fun callOrJoinRoomViaWebSocket() {
if (hasExternalSignalingServer) {
webSocketClient!!.joinRoomWithRoomTokenAndSession(
roomToken!!, callSession, externalSignalingServer!!.federation
roomToken!!,
callSession,
externalSignalingServer!!.federation
)
} else {
performCall()
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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)
}
}
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
)
}
}
}
}
Expand All @@ -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,
Expand Down Expand Up @@ -549,7 +554,6 @@ fun ShowPasswordDialog(onDismiss: () -> Unit, conversationCreationViewModel: Con

AlertDialog(
containerColor = colorResource(id = R.color.dialog_background),

onDismissRequest = onDismiss,
confirmButton = {
Button(onClick = {
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,20 @@ 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

fun updateSelectedParticipants(participants: List<AutocompleteUser>) {
_selectedParticipants.value = participants
}

fun updateSelectedImageUri(uri: Uri?) {
_selectedImageUri.value = uri
}

private val _roomName = MutableStateFlow("")
val roomName: StateFlow<String> = _roomName
private val _password = MutableStateFlow("")
Expand Down Expand Up @@ -66,7 +73,6 @@ class ConversationCreationViewModel @Inject constructor(
roomType: String,
conversationName: String,
participants: Set<AutocompleteUser>,
selectedImageUri: Uri?,
onRoomCreated: (String) -> Unit
) {
val scope = when {
Expand Down Expand Up @@ -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 ?: "")
Expand Down
Loading