Solved error unable to create call adapter for GenericOverall

Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
sowjanyakch 2024-08-23 23:19:50 +02:00 committed by Marcel Hibbe
parent 3db1f72981
commit dba56ddac0
No known key found for this signature in database
GPG key ID: C793F8B59F43CE7B
6 changed files with 119 additions and 66 deletions

View file

@ -54,7 +54,7 @@ interface NcApiCoroutines {
*/ */
@FormUrlEncoded @FormUrlEncoded
@PUT @PUT
fun renameRoom( suspend fun renameRoom(
@Header("Authorization") authorization: String?, @Header("Authorization") authorization: String?,
@Url url: String, @Url url: String,
@Field("roomName") roomName: String? @Field("roomName") roomName: String?
@ -62,22 +62,22 @@ interface NcApiCoroutines {
@FormUrlEncoded @FormUrlEncoded
@PUT @PUT
fun setConversationDescription( suspend fun setConversationDescription(
@Header("Authorization") authorization: String?, @Header("Authorization") authorization: String?,
@Url url: String, @Url url: String,
@Field("description") description: String? @Field("description") description: String?
): GenericOverall ): GenericOverall
@POST @POST
fun addParticipant( suspend fun addParticipant(
@Header("Authorization") authorization: String?, @Header("Authorization") authorization: String?,
@Url url: String?, @Url url: String?,
@QueryMap options: Map<String, String>? @QueryMap options: Map<String, String>?
): AddParticipantOverall ): AddParticipantOverall
@POST @POST
fun makeRoomPublic(@Header("Authorization") authorization: String?, @Url url: String?): GenericOverall suspend fun makeRoomPublic(@Header("Authorization") authorization: String?, @Url url: String): GenericOverall
@DELETE @DELETE
fun makeRoomPrivate(@Header("Authorization") authorization: String?, @Url url: String?): GenericOverall suspend fun makeRoomPrivate(@Header("Authorization") authorization: String?, @Url url: String): GenericOverall
} }

View file

@ -24,7 +24,6 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
@ -64,7 +63,6 @@ import com.nextcloud.talk.activities.BaseActivity
import com.nextcloud.talk.application.NextcloudTalkApplication import com.nextcloud.talk.application.NextcloudTalkApplication
import com.nextcloud.talk.chat.ChatActivity import com.nextcloud.talk.chat.ChatActivity
import com.nextcloud.talk.contacts.ContactsActivityCompose import com.nextcloud.talk.contacts.ContactsActivityCompose
import com.nextcloud.talk.contacts.RoomUiState
import com.nextcloud.talk.contacts.loadImage import com.nextcloud.talk.contacts.loadImage
import com.nextcloud.talk.models.json.autocomplete.AutocompleteUser import com.nextcloud.talk.models.json.autocomplete.AutocompleteUser
import com.nextcloud.talk.models.json.conversations.ConversationEnums import com.nextcloud.talk.models.json.conversations.ConversationEnums
@ -415,55 +413,37 @@ fun ConversationOptions(icon: Int? = null, text: Int, switch: @Composable (() ->
@Composable @Composable
fun CreateConversation(conversationCreationViewModel: ConversationCreationViewModel, context: Context) { fun CreateConversation(conversationCreationViewModel: ConversationCreationViewModel, context: Context) {
val roomUiState by conversationCreationViewModel.roomViewState.collectAsState() val selectedParticipants by conversationCreationViewModel.selectedParticipants.collectAsState()
val participants = conversationCreationViewModel.selectedParticipants.collectAsState().value.toSet() val isGuestsAllowed = conversationCreationViewModel.isGuestsAllowed.value
Box( Box(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(all = 16.dp) .padding(all = 16.dp),
.clickable {
},
contentAlignment = Alignment.Center contentAlignment = Alignment.Center
) { ) {
Button( Button(
onClick = { onClick = {
val roomType = if (conversationCreationViewModel.isGuestsAllowed.value) { val roomType = if (isGuestsAllowed) {
ConversationEnums.ConversationType.ROOM_PUBLIC_CALL ConversationEnums.ConversationType.ROOM_PUBLIC_CALL
} else { } else {
ConversationEnums.ConversationType.ROOM_GROUP_CALL ConversationEnums.ConversationType.ROOM_GROUP_CALL
} }
conversationCreationViewModel.createRoom( conversationCreationViewModel.createRoomAndAddParticipants(
roomType, roomType = roomType,
conversationCreationViewModel.roomName.value conversationName = conversationCreationViewModel.roomName.value,
) participants = selectedParticipants.toSet()
) {
roomToken ->
val bundle = Bundle()
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomToken)
val chatIntent = Intent(context, ChatActivity::class.java)
chatIntent.putExtras(bundle)
context.startActivity(chatIntent)
}
} }
) { ) {
Text(text = stringResource(id = R.string.create_conversation)) Text(text = stringResource(id = R.string.create_conversation))
} }
} }
when (roomUiState) {
is RoomUiState.Success -> {
val conversation = (roomUiState as RoomUiState.Success).conversation
val token = conversation?.token
if (token != null) {
conversationCreationViewModel.allowGuests(token, conversationCreationViewModel.isGuestsAllowed.value)
}
for (participant in participants) {
participant.id?.let { conversationCreationViewModel.addParticipants(token, it, participant.source!!) }
}
val bundle = Bundle()
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, token)
val chatIntent = Intent(context, ChatActivity::class.java)
chatIntent.putExtras(bundle)
chatIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
context.startActivity(chatIntent)
}
is RoomUiState.Error -> {
val errorMessage = (roomUiState as RoomUiState.Error).message
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Text(text = "Error: $errorMessage", color = Color.Red)
}
}
is RoomUiState.None -> {}
}
} }

View file

@ -14,7 +14,7 @@ import com.nextcloud.talk.models.json.participants.AddParticipantOverall
interface ConversationCreationRepository { interface ConversationCreationRepository {
fun allowGuests(token: String, allow: Boolean): ConversationCreationRepositoryImpl.AllowGuestsResult 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 addParticipants(conversationToken: String?, userId: String, sourceType: String): AddParticipantOverall suspend fun addParticipants(conversationToken: String?, userId: String, sourceType: String): AddParticipantOverall

View file

@ -14,7 +14,6 @@ import com.nextcloud.talk.models.json.conversations.ConversationEnums
import com.nextcloud.talk.models.json.conversations.RoomOverall import com.nextcloud.talk.models.json.conversations.RoomOverall
import com.nextcloud.talk.models.json.generic.GenericOverall import com.nextcloud.talk.models.json.generic.GenericOverall
import com.nextcloud.talk.models.json.participants.AddParticipantOverall import com.nextcloud.talk.models.json.participants.AddParticipantOverall
import com.nextcloud.talk.repositories.conversations.ConversationsRepositoryImpl.Companion.STATUS_CODE_OK
import com.nextcloud.talk.users.UserManager import com.nextcloud.talk.users.UserManager
import com.nextcloud.talk.utils.ApiUtils import com.nextcloud.talk.utils.ApiUtils
import com.nextcloud.talk.utils.ApiUtils.getRetrofitBucketForAddParticipant import com.nextcloud.talk.utils.ApiUtils.getRetrofitBucketForAddParticipant
@ -28,9 +27,6 @@ class ConversationCreationRepositoryImpl(
val currentUser: User = _currentUser val currentUser: User = _currentUser
val credentials = ApiUtils.getCredentials(_currentUser.username, _currentUser.token) val credentials = ApiUtils.getCredentials(_currentUser.username, _currentUser.token)
val apiVersion = ApiUtils.getConversationApiVersion(_currentUser, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V1)) val apiVersion = ApiUtils.getConversationApiVersion(_currentUser, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V1))
data class AllowGuestsResult(
val allow: Boolean
)
override suspend fun renameConversation(roomToken: String, roomNameNew: String?): GenericOverall { override suspend fun renameConversation(roomToken: String, roomNameNew: String?): GenericOverall {
return ncApiCoroutines.renameRoom( return ncApiCoroutines.renameRoom(
@ -77,7 +73,8 @@ class ConversationCreationRepositoryImpl(
userId userId
) )
} }
return ncApiCoroutines.addParticipant(credentials, retrofitBucket.url, retrofitBucket.queryMap) val participants = ncApiCoroutines.addParticipant(credentials, retrofitBucket.url, retrofitBucket.queryMap)
return participants
} }
override fun getImageUri(avatarId: String, requestBigSize: Boolean): String { override fun getImageUri(avatarId: String, requestBigSize: Boolean): String {
@ -120,14 +117,14 @@ class ConversationCreationRepositoryImpl(
return response return response
} }
override fun allowGuests(token: String, allow: Boolean): AllowGuestsResult { override suspend fun allowGuests(token: String, allow: Boolean): GenericOverall {
val url = ApiUtils.getUrlForRoomPublic( val url = ApiUtils.getUrlForRoomPublic(
apiVersion, apiVersion,
_currentUser.baseUrl!!, _currentUser.baseUrl!!,
token token
) )
val result = if (allow) { val result: GenericOverall = if (allow) {
ncApiCoroutines.makeRoomPublic( ncApiCoroutines.makeRoomPublic(
credentials, credentials,
url url
@ -139,7 +136,7 @@ class ConversationCreationRepositoryImpl(
) )
} }
return AllowGuestsResult(result.ocs!!.meta!!.statusCode == STATUS_CODE_OK && allow) return result
} }
companion object { companion object {

View file

@ -11,11 +11,11 @@ import android.util.Log
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
import com.nextcloud.talk.contacts.AddParticipantsUiState
import com.nextcloud.talk.contacts.RoomUiState
import com.nextcloud.talk.models.json.autocomplete.AutocompleteUser import com.nextcloud.talk.models.json.autocomplete.AutocompleteUser
import com.nextcloud.talk.models.json.conversations.Conversation import com.nextcloud.talk.models.json.conversations.Conversation
import com.nextcloud.talk.models.json.conversations.ConversationEnums import com.nextcloud.talk.models.json.conversations.ConversationEnums
import com.nextcloud.talk.models.json.generic.GenericMeta
import com.nextcloud.talk.repositories.conversations.ConversationsRepositoryImpl.Companion.STATUS_CODE_OK
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -26,8 +26,8 @@ class ConversationCreationViewModel @Inject constructor(
) : ViewModel() { ) : ViewModel() {
private val _selectedParticipants = MutableStateFlow<List<AutocompleteUser>>(emptyList()) private val _selectedParticipants = MutableStateFlow<List<AutocompleteUser>>(emptyList())
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)
val roomViewState: StateFlow<RoomUiState> = _roomViewState val roomViewState: StateFlow<RoomUIState> = _roomViewState
fun updateSelectedParticipants(participants: List<AutocompleteUser>) { fun updateSelectedParticipants(participants: List<AutocompleteUser>) {
_selectedParticipants.value = participants _selectedParticipants.value = participants
@ -44,6 +44,9 @@ class ConversationCreationViewModel @Inject constructor(
private val addParticipantsViewState = MutableStateFlow<AddParticipantsUiState>(AddParticipantsUiState.None) private val addParticipantsViewState = MutableStateFlow<AddParticipantsUiState>(AddParticipantsUiState.None)
val addParticipantsUiState: StateFlow<AddParticipantsUiState> = addParticipantsViewState val addParticipantsUiState: StateFlow<AddParticipantsUiState> = addParticipantsViewState
private val _allowGuestsResult = MutableStateFlow<AllowGuestsUiState>(AllowGuestsUiState.None)
val allowGuestsResult: StateFlow<AllowGuestsUiState> = _allowGuestsResult
fun updateRoomName(roomName: String) { fun updateRoomName(roomName: String) {
_roomName.value = roomName _roomName.value = roomName
} }
@ -61,6 +64,7 @@ class ConversationCreationViewModel @Inject constructor(
} }
} }
} }
fun setConversationDescription(roomToken: String) { fun setConversationDescription(roomToken: String) {
viewModelScope.launch { viewModelScope.launch {
try { try {
@ -70,11 +74,12 @@ class ConversationCreationViewModel @Inject constructor(
} }
} }
} }
fun addParticipants(conversationToken: String?, userId: String, sourceType: String) { fun addParticipants(conversationToken: String?, userId: String, sourceType: String) {
viewModelScope.launch { viewModelScope.launch {
try { try {
val participantsOverall = repository.addParticipants(conversationToken, userId, sourceType) val participantsOverall = repository.addParticipants(conversationToken, userId, sourceType)
val participants = participantsOverall.ocs?.data val participants: List<Conversation>? = participantsOverall.ocs?.data
addParticipantsViewState.value = AddParticipantsUiState.Success(participants) addParticipantsViewState.value = AddParticipantsUiState.Success(participants)
} catch (exception: Exception) { } catch (exception: Exception) {
addParticipantsViewState.value = AddParticipantsUiState.Error(exception.message ?: "") addParticipantsViewState.value = AddParticipantsUiState.Error(exception.message ?: "")
@ -82,6 +87,68 @@ class ConversationCreationViewModel @Inject constructor(
} }
} }
fun allowGuests(token: String, allow: Boolean) {
viewModelScope.launch {
try {
val response = repository.allowGuests(token, allow)
val statusCode: Int = response.ocs?.meta?.statusCode!!
val result = (statusCode == STATUS_CODE_OK)
_allowGuestsResult.value = AllowGuestsUiState.Success(result)
} catch (exception: Exception) {
_allowGuestsResult.value = AllowGuestsUiState.Error(exception.message ?: "")
}
}
}
fun createRoomAndAddParticipants(
roomType: ConversationEnums.ConversationType,
conversationName: String,
participants: Set<AutocompleteUser>,
onRoomCreated: (String) -> Unit
) {
viewModelScope.launch {
_roomViewState.value = RoomUIState.None
try {
val roomResult = repository.createRoom(roomType, conversationName)
val conversation = roomResult.ocs?.data
if (conversation != null) {
val token = conversation.token
if (token != null) {
try {
val allowGuestsResult = repository.allowGuests(token, isGuestsAllowed.value)
val statusCode: GenericMeta? = allowGuestsResult.ocs?.meta
val result = (statusCode?.statusCode == STATUS_CODE_OK)
if (result) {
_allowGuestsResult.value = AllowGuestsUiState.Success(result)
for (participant in participants) {
if (participant.id != null) {
val participantOverall = repository.addParticipants(
token,
participant.id!!,
participant.source!!
).ocs?.data
addParticipantsViewState.value =
AddParticipantsUiState.Success(participantOverall)
}
onRoomCreated(token)
}
}
} catch (exception: Exception) {
_allowGuestsResult.value = AllowGuestsUiState.Error(exception.message ?: "")
}
}
_roomViewState.value = RoomUIState.Success(conversation)
} else {
_roomViewState.value = RoomUIState.Error("Conversation is null")
}
} catch (e: Exception) {
_roomViewState.value = RoomUIState.Error(e.message ?: "Unknown error")
Log.e("ConversationCreationViewModel", "Error - ${e.message}")
}
}
}
fun getImageUri(avatarId: String, requestBigSize: Boolean): String { fun getImageUri(avatarId: String, requestBigSize: Boolean): String {
return repository.getImageUri(avatarId, requestBigSize) return repository.getImageUri(avatarId, requestBigSize)
} }
@ -95,14 +162,27 @@ class ConversationCreationViewModel @Inject constructor(
) )
val conversation: Conversation? = room.ocs?.data val conversation: Conversation? = room.ocs?.data
_roomViewState.value = RoomUiState.Success(conversation) _roomViewState.value = RoomUIState.Success(conversation)
} catch (exception: Exception) { } catch (exception: Exception) {
_roomViewState.value = RoomUiState.Error(exception.message ?: "") _roomViewState.value = RoomUIState.Error(exception.message ?: "")
} }
} }
} }
}
fun allowGuests(token: String, allow: Boolean): ConversationCreationRepositoryImpl.AllowGuestsResult { sealed class AllowGuestsUiState {
return repository.allowGuests(token, allow) data object None : AllowGuestsUiState()
} data class Success(val result: Boolean) : AllowGuestsUiState()
data class Error(val message: String) : AllowGuestsUiState()
}
sealed class RoomUIState {
data object None : RoomUIState()
data class Success(val conversation: Conversation?) : RoomUIState()
data class Error(val message: String) : RoomUIState()
}
sealed class AddParticipantsUiState() {
data object None : AddParticipantsUiState()
data class Success(val participants: List<Conversation>?) : AddParticipantsUiState()
data class Error(val message: String) : AddParticipantsUiState()
} }

View file

@ -29,8 +29,4 @@ class FakeRepositorySuccess : ContactsRepository {
override fun getImageUri(avatarId: String, requestBigSize: Boolean): String { override fun getImageUri(avatarId: String, requestBigSize: Boolean): String {
return "https://mydomain.com/index.php/avatar/$avatarId/512" return "https://mydomain.com/index.php/avatar/$avatarId/512"
} }
override fun getImageUri(avatarId: String, requestBigSize: Boolean): String {
TODO("Not yet implemented")
}
} }