mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-25 06:25:40 +03:00
Refactor createRoom()
Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
parent
dba56ddac0
commit
cb6fdf6fe1
5 changed files with 51 additions and 52 deletions
|
@ -80,4 +80,12 @@ interface NcApiCoroutines {
|
|||
|
||||
@DELETE
|
||||
suspend fun makeRoomPrivate(@Header("Authorization") authorization: String?, @Url url: String): GenericOverall
|
||||
|
||||
@FormUrlEncoded
|
||||
@PUT
|
||||
suspend fun setPassword(
|
||||
@Header("Authorization") authorization: String?,
|
||||
@Url url: String?,
|
||||
@Field("password") password: String?
|
||||
): GenericOverall
|
||||
}
|
||||
|
|
|
@ -65,7 +65,6 @@ import com.nextcloud.talk.chat.ChatActivity
|
|||
import com.nextcloud.talk.contacts.ContactsActivityCompose
|
||||
import com.nextcloud.talk.contacts.loadImage
|
||||
import com.nextcloud.talk.models.json.autocomplete.AutocompleteUser
|
||||
import com.nextcloud.talk.models.json.conversations.ConversationEnums
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys
|
||||
import javax.inject.Inject
|
||||
|
||||
|
@ -407,15 +406,15 @@ fun ConversationOptions(icon: Int? = null, text: Int, switch: @Composable (() ->
|
|||
text = stringResource(id = text),
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
switch?.invoke()
|
||||
if (switch != null) {
|
||||
switch()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun CreateConversation(conversationCreationViewModel: ConversationCreationViewModel, context: Context) {
|
||||
val selectedParticipants by conversationCreationViewModel.selectedParticipants.collectAsState()
|
||||
val isGuestsAllowed = conversationCreationViewModel.isGuestsAllowed.value
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
|
@ -424,21 +423,16 @@ fun CreateConversation(conversationCreationViewModel: ConversationCreationViewMo
|
|||
) {
|
||||
Button(
|
||||
onClick = {
|
||||
val roomType = if (isGuestsAllowed) {
|
||||
ConversationEnums.ConversationType.ROOM_PUBLIC_CALL
|
||||
} else {
|
||||
ConversationEnums.ConversationType.ROOM_GROUP_CALL
|
||||
}
|
||||
conversationCreationViewModel.createRoomAndAddParticipants(
|
||||
roomType = roomType,
|
||||
roomType = CompanionClass.ROOM_TYPE_GROUP,
|
||||
conversationName = conversationCreationViewModel.roomName.value,
|
||||
participants = selectedParticipants.toSet()
|
||||
) {
|
||||
roomToken ->
|
||||
) { roomToken ->
|
||||
val bundle = Bundle()
|
||||
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomToken)
|
||||
val chatIntent = Intent(context, ChatActivity::class.java)
|
||||
chatIntent.putExtras(bundle)
|
||||
chatIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||
context.startActivity(chatIntent)
|
||||
}
|
||||
}
|
||||
|
@ -447,3 +441,9 @@ fun CreateConversation(conversationCreationViewModel: ConversationCreationViewMo
|
|||
}
|
||||
}
|
||||
}
|
||||
class CompanionClass {
|
||||
companion object {
|
||||
internal val TAG = ConversationCreationActivity::class.simpleName
|
||||
internal const val ROOM_TYPE_GROUP = "2"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
package com.nextcloud.talk.conversationcreation
|
||||
|
||||
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
|
||||
|
@ -18,6 +17,7 @@ interface ConversationCreationRepository {
|
|||
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
|
||||
suspend fun createRoom(roomType: ConversationEnums.ConversationType?, conversationName: String?): RoomOverall
|
||||
suspend fun createRoom(roomType: String, conversationName: String?): RoomOverall
|
||||
fun getImageUri(avatarId: String, requestBigSize: Boolean): String
|
||||
suspend fun setPassword(roomToken: String, password: String): GenericOverall
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ package com.nextcloud.talk.conversationcreation
|
|||
import com.nextcloud.talk.api.NcApiCoroutines
|
||||
import com.nextcloud.talk.data.user.model.User
|
||||
import com.nextcloud.talk.models.RetrofitBucket
|
||||
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
|
||||
|
@ -77,6 +76,23 @@ class ConversationCreationRepositoryImpl(
|
|||
return participants
|
||||
}
|
||||
|
||||
override suspend fun createRoom(roomType: String, conversationName: String?): RoomOverall {
|
||||
val retrofitBucket: RetrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(
|
||||
apiVersion,
|
||||
_currentUser.baseUrl,
|
||||
roomType,
|
||||
null,
|
||||
null,
|
||||
conversationName
|
||||
)
|
||||
val response = ncApiCoroutines.createRoom(
|
||||
credentials,
|
||||
retrofitBucket.url,
|
||||
retrofitBucket.queryMap
|
||||
)
|
||||
return response
|
||||
}
|
||||
|
||||
override fun getImageUri(avatarId: String, requestBigSize: Boolean): String {
|
||||
return ApiUtils.getUrlForAvatar(
|
||||
_currentUser.baseUrl,
|
||||
|
@ -85,36 +101,17 @@ class ConversationCreationRepositoryImpl(
|
|||
)
|
||||
}
|
||||
|
||||
override suspend fun createRoom(
|
||||
roomType: ConversationEnums.ConversationType?,
|
||||
conversationName: String?
|
||||
): RoomOverall {
|
||||
val retrofitBucket: RetrofitBucket =
|
||||
if (roomType == ConversationEnums.ConversationType.ROOM_PUBLIC_CALL) {
|
||||
ApiUtils.getRetrofitBucketForCreateRoom(
|
||||
apiVersion,
|
||||
currentUser.baseUrl!!,
|
||||
ROOM_TYPE_PUBLIC,
|
||||
null,
|
||||
null,
|
||||
conversationName
|
||||
)
|
||||
} else {
|
||||
ApiUtils.getRetrofitBucketForCreateRoom(
|
||||
apiVersion,
|
||||
currentUser.baseUrl!!,
|
||||
ROOM_TYPE_GROUP,
|
||||
null,
|
||||
null,
|
||||
conversationName
|
||||
)
|
||||
}
|
||||
val response = ncApiCoroutines.createRoom(
|
||||
override suspend fun setPassword(roomToken: String, password: String): GenericOverall {
|
||||
val result = ncApiCoroutines.setPassword(
|
||||
credentials,
|
||||
retrofitBucket.url,
|
||||
retrofitBucket.queryMap
|
||||
ApiUtils.getUrlForRoomPassword(
|
||||
apiVersion,
|
||||
_currentUser.baseUrl!!,
|
||||
roomToken
|
||||
),
|
||||
password
|
||||
)
|
||||
return response
|
||||
return result
|
||||
}
|
||||
|
||||
override suspend fun allowGuests(token: String, allow: Boolean): GenericOverall {
|
||||
|
@ -138,9 +135,4 @@ class ConversationCreationRepositoryImpl(
|
|||
|
||||
return result
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val ROOM_TYPE_PUBLIC = "3"
|
||||
private const val ROOM_TYPE_GROUP = "2"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ import androidx.lifecycle.ViewModel
|
|||
import androidx.lifecycle.viewModelScope
|
||||
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
|
||||
|
@ -101,7 +100,7 @@ class ConversationCreationViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
fun createRoomAndAddParticipants(
|
||||
roomType: ConversationEnums.ConversationType,
|
||||
roomType: String,
|
||||
conversationName: String,
|
||||
participants: Set<AutocompleteUser>,
|
||||
onRoomCreated: (String) -> Unit
|
||||
|
@ -131,9 +130,9 @@ class ConversationCreationViewModel @Inject constructor(
|
|||
addParticipantsViewState.value =
|
||||
AddParticipantsUiState.Success(participantOverall)
|
||||
}
|
||||
onRoomCreated(token)
|
||||
}
|
||||
}
|
||||
onRoomCreated(token)
|
||||
} catch (exception: Exception) {
|
||||
_allowGuestsResult.value = AllowGuestsUiState.Error(exception.message ?: "")
|
||||
}
|
||||
|
@ -153,7 +152,7 @@ class ConversationCreationViewModel @Inject constructor(
|
|||
return repository.getImageUri(avatarId, requestBigSize)
|
||||
}
|
||||
|
||||
fun createRoom(roomType: ConversationEnums.ConversationType?, conversationName: String?) {
|
||||
fun createRoom(roomType: String, conversationName: String?) {
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
val room = repository.createRoom(
|
||||
|
|
Loading…
Reference in a new issue