mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-22 13:05:31 +03:00
Solved error unable to create call adapter for GenericOverall
Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
parent
3db1f72981
commit
dba56ddac0
6 changed files with 119 additions and 66 deletions
|
@ -54,7 +54,7 @@ interface NcApiCoroutines {
|
|||
*/
|
||||
@FormUrlEncoded
|
||||
@PUT
|
||||
fun renameRoom(
|
||||
suspend fun renameRoom(
|
||||
@Header("Authorization") authorization: String?,
|
||||
@Url url: String,
|
||||
@Field("roomName") roomName: String?
|
||||
|
@ -62,22 +62,22 @@ interface NcApiCoroutines {
|
|||
|
||||
@FormUrlEncoded
|
||||
@PUT
|
||||
fun setConversationDescription(
|
||||
suspend fun setConversationDescription(
|
||||
@Header("Authorization") authorization: String?,
|
||||
@Url url: String,
|
||||
@Field("description") description: String?
|
||||
): GenericOverall
|
||||
|
||||
@POST
|
||||
fun addParticipant(
|
||||
suspend fun addParticipant(
|
||||
@Header("Authorization") authorization: String?,
|
||||
@Url url: String?,
|
||||
@QueryMap options: Map<String, String>?
|
||||
): AddParticipantOverall
|
||||
|
||||
@POST
|
||||
fun makeRoomPublic(@Header("Authorization") authorization: String?, @Url url: String?): GenericOverall
|
||||
suspend fun makeRoomPublic(@Header("Authorization") authorization: String?, @Url url: String): GenericOverall
|
||||
|
||||
@DELETE
|
||||
fun makeRoomPrivate(@Header("Authorization") authorization: String?, @Url url: String?): GenericOverall
|
||||
suspend fun makeRoomPrivate(@Header("Authorization") authorization: String?, @Url url: String): GenericOverall
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ import androidx.compose.foundation.layout.Column
|
|||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
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.chat.ChatActivity
|
||||
import com.nextcloud.talk.contacts.ContactsActivityCompose
|
||||
import com.nextcloud.talk.contacts.RoomUiState
|
||||
import com.nextcloud.talk.contacts.loadImage
|
||||
import com.nextcloud.talk.models.json.autocomplete.AutocompleteUser
|
||||
import com.nextcloud.talk.models.json.conversations.ConversationEnums
|
||||
|
@ -415,55 +413,37 @@ fun ConversationOptions(icon: Int? = null, text: Int, switch: @Composable (() ->
|
|||
|
||||
@Composable
|
||||
fun CreateConversation(conversationCreationViewModel: ConversationCreationViewModel, context: Context) {
|
||||
val roomUiState by conversationCreationViewModel.roomViewState.collectAsState()
|
||||
val participants = conversationCreationViewModel.selectedParticipants.collectAsState().value.toSet()
|
||||
val selectedParticipants by conversationCreationViewModel.selectedParticipants.collectAsState()
|
||||
val isGuestsAllowed = conversationCreationViewModel.isGuestsAllowed.value
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(all = 16.dp)
|
||||
.clickable {
|
||||
},
|
||||
.padding(all = 16.dp),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Button(
|
||||
onClick = {
|
||||
val roomType = if (conversationCreationViewModel.isGuestsAllowed.value) {
|
||||
val roomType = if (isGuestsAllowed) {
|
||||
ConversationEnums.ConversationType.ROOM_PUBLIC_CALL
|
||||
} else {
|
||||
ConversationEnums.ConversationType.ROOM_GROUP_CALL
|
||||
}
|
||||
conversationCreationViewModel.createRoom(
|
||||
roomType,
|
||||
conversationCreationViewModel.roomName.value
|
||||
)
|
||||
conversationCreationViewModel.createRoomAndAddParticipants(
|
||||
roomType = roomType,
|
||||
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))
|
||||
}
|
||||
}
|
||||
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 -> {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import com.nextcloud.talk.models.json.participants.AddParticipantOverall
|
|||
|
||||
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 setConversationDescription(roomToken: String, description: String?): GenericOverall
|
||||
suspend fun addParticipants(conversationToken: String?, userId: String, sourceType: String): AddParticipantOverall
|
||||
|
|
|
@ -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.generic.GenericOverall
|
||||
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.utils.ApiUtils
|
||||
import com.nextcloud.talk.utils.ApiUtils.getRetrofitBucketForAddParticipant
|
||||
|
@ -28,9 +27,6 @@ class ConversationCreationRepositoryImpl(
|
|||
val currentUser: User = _currentUser
|
||||
val credentials = ApiUtils.getCredentials(_currentUser.username, _currentUser.token)
|
||||
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 {
|
||||
return ncApiCoroutines.renameRoom(
|
||||
|
@ -77,7 +73,8 @@ class ConversationCreationRepositoryImpl(
|
|||
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 {
|
||||
|
@ -120,14 +117,14 @@ class ConversationCreationRepositoryImpl(
|
|||
return response
|
||||
}
|
||||
|
||||
override fun allowGuests(token: String, allow: Boolean): AllowGuestsResult {
|
||||
override suspend fun allowGuests(token: String, allow: Boolean): GenericOverall {
|
||||
val url = ApiUtils.getUrlForRoomPublic(
|
||||
apiVersion,
|
||||
_currentUser.baseUrl!!,
|
||||
token
|
||||
)
|
||||
|
||||
val result = if (allow) {
|
||||
val result: GenericOverall = if (allow) {
|
||||
ncApiCoroutines.makeRoomPublic(
|
||||
credentials,
|
||||
url
|
||||
|
@ -139,7 +136,7 @@ class ConversationCreationRepositoryImpl(
|
|||
)
|
||||
}
|
||||
|
||||
return AllowGuestsResult(result.ocs!!.meta!!.statusCode == STATUS_CODE_OK && allow)
|
||||
return result
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
|
|
@ -11,11 +11,11 @@ import android.util.Log
|
|||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.lifecycle.ViewModel
|
||||
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.conversations.Conversation
|
||||
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.StateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
|
@ -26,8 +26,8 @@ class ConversationCreationViewModel @Inject constructor(
|
|||
) : ViewModel() {
|
||||
private val _selectedParticipants = MutableStateFlow<List<AutocompleteUser>>(emptyList())
|
||||
val selectedParticipants: StateFlow<List<AutocompleteUser>> = _selectedParticipants
|
||||
private val _roomViewState = MutableStateFlow<RoomUiState>(RoomUiState.None)
|
||||
val roomViewState: StateFlow<RoomUiState> = _roomViewState
|
||||
private val _roomViewState = MutableStateFlow<RoomUIState>(RoomUIState.None)
|
||||
val roomViewState: StateFlow<RoomUIState> = _roomViewState
|
||||
|
||||
fun updateSelectedParticipants(participants: List<AutocompleteUser>) {
|
||||
_selectedParticipants.value = participants
|
||||
|
@ -44,6 +44,9 @@ class ConversationCreationViewModel @Inject constructor(
|
|||
private val addParticipantsViewState = MutableStateFlow<AddParticipantsUiState>(AddParticipantsUiState.None)
|
||||
val addParticipantsUiState: StateFlow<AddParticipantsUiState> = addParticipantsViewState
|
||||
|
||||
private val _allowGuestsResult = MutableStateFlow<AllowGuestsUiState>(AllowGuestsUiState.None)
|
||||
val allowGuestsResult: StateFlow<AllowGuestsUiState> = _allowGuestsResult
|
||||
|
||||
fun updateRoomName(roomName: String) {
|
||||
_roomName.value = roomName
|
||||
}
|
||||
|
@ -61,6 +64,7 @@ class ConversationCreationViewModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun setConversationDescription(roomToken: String) {
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
|
@ -70,11 +74,12 @@ class ConversationCreationViewModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun addParticipants(conversationToken: String?, userId: String, sourceType: String) {
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
val participantsOverall = repository.addParticipants(conversationToken, userId, sourceType)
|
||||
val participants = participantsOverall.ocs?.data
|
||||
val participants: List<Conversation>? = participantsOverall.ocs?.data
|
||||
addParticipantsViewState.value = AddParticipantsUiState.Success(participants)
|
||||
} catch (exception: Exception) {
|
||||
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 {
|
||||
return repository.getImageUri(avatarId, requestBigSize)
|
||||
}
|
||||
|
@ -95,14 +162,27 @@ class ConversationCreationViewModel @Inject constructor(
|
|||
)
|
||||
|
||||
val conversation: Conversation? = room.ocs?.data
|
||||
_roomViewState.value = RoomUiState.Success(conversation)
|
||||
_roomViewState.value = RoomUIState.Success(conversation)
|
||||
} catch (exception: Exception) {
|
||||
_roomViewState.value = RoomUiState.Error(exception.message ?: "")
|
||||
_roomViewState.value = RoomUIState.Error(exception.message ?: "")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun allowGuests(token: String, allow: Boolean): ConversationCreationRepositoryImpl.AllowGuestsResult {
|
||||
return repository.allowGuests(token, allow)
|
||||
}
|
||||
}
|
||||
sealed class AllowGuestsUiState {
|
||||
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()
|
||||
}
|
||||
|
|
|
@ -29,8 +29,4 @@ class FakeRepositorySuccess : ContactsRepository {
|
|||
override fun getImageUri(avatarId: String, requestBigSize: Boolean): String {
|
||||
return "https://mydomain.com/index.php/avatar/$avatarId/512"
|
||||
}
|
||||
|
||||
override fun getImageUri(avatarId: String, requestBigSize: Boolean): String {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue