|
@@ -7,12 +7,13 @@
|
|
|
|
|
|
package com.nextcloud.talk.conversationcreation
|
|
|
|
|
|
+import android.net.Uri
|
|
|
import android.util.Log
|
|
|
import androidx.compose.runtime.mutableStateOf
|
|
|
+import androidx.core.net.toFile
|
|
|
import androidx.lifecycle.ViewModel
|
|
|
import androidx.lifecycle.viewModelScope
|
|
|
import com.nextcloud.talk.data.user.model.User
|
|
|
-import com.nextcloud.talk.models.domain.ConversationModel
|
|
|
import com.nextcloud.talk.models.json.autocomplete.AutocompleteUser
|
|
|
import com.nextcloud.talk.models.json.conversations.Conversation
|
|
|
import com.nextcloud.talk.models.json.generic.GenericMeta
|
|
@@ -21,7 +22,6 @@ import com.nextcloud.talk.users.UserManager
|
|
|
import kotlinx.coroutines.flow.MutableStateFlow
|
|
|
import kotlinx.coroutines.flow.StateFlow
|
|
|
import kotlinx.coroutines.launch
|
|
|
-import java.io.File
|
|
|
import javax.inject.Inject
|
|
|
|
|
|
class ConversationCreationViewModel @Inject constructor(
|
|
@@ -32,12 +32,6 @@ class ConversationCreationViewModel @Inject constructor(
|
|
|
val selectedParticipants: StateFlow<List<AutocompleteUser>> = _selectedParticipants
|
|
|
private val roomViewState = MutableStateFlow<RoomUIState>(RoomUIState.None)
|
|
|
|
|
|
- private val _uploadState = MutableStateFlow<UploadAvatarState>(UploadAvatarState.Loading)
|
|
|
- val uploadState: StateFlow<UploadAvatarState> = _uploadState
|
|
|
-
|
|
|
- private val _deleteState = MutableStateFlow<DeleteAvatarState>(DeleteAvatarState.Loading)
|
|
|
- val deleteState: StateFlow<DeleteAvatarState> = _deleteState
|
|
|
-
|
|
|
private val _currentUser = userManager.currentUser.blockingGet()
|
|
|
val currentUser: User = _currentUser
|
|
|
|
|
@@ -72,6 +66,7 @@ class ConversationCreationViewModel @Inject constructor(
|
|
|
roomType: String,
|
|
|
conversationName: String,
|
|
|
participants: Set<AutocompleteUser>,
|
|
|
+ selectedImageUri: Uri?,
|
|
|
onRoomCreated: (String) -> Unit
|
|
|
) {
|
|
|
val scope = when {
|
|
@@ -114,6 +109,9 @@ class ConversationCreationViewModel @Inject constructor(
|
|
|
repository.setPassword(token, _password.value)
|
|
|
}
|
|
|
repository.openConversation(token, scope)
|
|
|
+ if(selectedImageUri!= null){
|
|
|
+ repository.uploadConversationAvatar(selectedImageUri.toFile(), token)
|
|
|
+ }
|
|
|
onRoomCreated(token)
|
|
|
} catch (exception: Exception) {
|
|
|
allowGuestsResult.value = AllowGuestsUiState.Error(exception.message ?: "")
|
|
@@ -130,28 +128,6 @@ class ConversationCreationViewModel @Inject constructor(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- fun uploadConversationAvatar(file: File, roomToken: String) {
|
|
|
- viewModelScope.launch {
|
|
|
- try {
|
|
|
- val response = repository.uploadConversationAvatar(file, roomToken)
|
|
|
- _uploadState.value = UploadAvatarState.Success(response)
|
|
|
- } catch (e: Exception) {
|
|
|
- _uploadState.value = UploadAvatarState.Error(e)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- fun deleteConversationAvatar(roomToken: String) {
|
|
|
- viewModelScope.launch {
|
|
|
- try {
|
|
|
- val result = repository.deleteConversationAvatar(roomToken)
|
|
|
- _deleteState.value = DeleteAvatarState.Success(result)
|
|
|
- } catch (e: Exception) {
|
|
|
- _deleteState.value = DeleteAvatarState.Error(e)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
fun getImageUri(avatarId: String, requestBigSize: Boolean): String {
|
|
|
return repository.getImageUri(avatarId, requestBigSize)
|
|
|
}
|
|
@@ -191,14 +167,3 @@ sealed class AddParticipantsUiState {
|
|
|
data class Error(val message: String) : AddParticipantsUiState()
|
|
|
}
|
|
|
|
|
|
-sealed class UploadAvatarState {
|
|
|
- object Loading : UploadAvatarState()
|
|
|
- data class Success(val roomOverall: ConversationModel) : UploadAvatarState()
|
|
|
- data class Error(val exception: Exception) : UploadAvatarState()
|
|
|
-}
|
|
|
-
|
|
|
-sealed class DeleteAvatarState {
|
|
|
- object Loading : DeleteAvatarState()
|
|
|
- data class Success(val roomOverall: ConversationModel) : DeleteAvatarState()
|
|
|
- data class Error(val exception: Exception) : DeleteAvatarState()
|
|
|
-}
|