Implement renameRoom in ConversationInfoEditRepository

Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
sowjanyakch 2024-11-15 12:08:04 +01:00
parent 8e20f5b0e4
commit cedf1f09e9
No known key found for this signature in database
GPG key ID: F7AA2A8B65B50220
4 changed files with 22 additions and 21 deletions

View file

@ -8,13 +8,10 @@ package com.nextcloud.talk.conversation.repository
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 io.reactivex.Observable
interface ConversationRepository {
fun renameConversation(roomToken: String, roomNameNew: String): Observable<GenericOverall>
fun createConversation(
roomName: String,
conversationType: ConversationEnums.ConversationType?

View file

@ -11,7 +11,6 @@ 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.utils.ApiUtils
import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew
import io.reactivex.Observable
@ -24,22 +23,7 @@ class ConversationRepositoryImpl(private val ncApi: NcApi, currentUserProvider:
val currentUser: User = currentUserProvider.currentUser.blockingGet()
val credentials: String = ApiUtils.getCredentials(currentUser.username, currentUser.token)!!
override fun renameConversation(roomToken: String, roomNameNew: String): Observable<GenericOverall> {
val apiVersion = ApiUtils.getConversationApiVersion(currentUser, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V1))
return ncApi.renameRoom(
credentials,
ApiUtils.getUrlForRoom(
apiVersion,
currentUser.baseUrl!!,
roomToken
),
roomNameNew
)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.retry(API_RETRIES)
}
override fun createConversation(
roomName: String,
@ -76,6 +60,5 @@ class ConversationRepositoryImpl(private val ncApi: NcApi, currentUserProvider:
companion object {
private const val ROOM_TYPE_PUBLIC = "3"
private const val ROOM_TYPE_GROUP = "2"
const val API_RETRIES: Long = 3
}
}

View file

@ -8,6 +8,7 @@ package com.nextcloud.talk.conversationinfoedit.data
import com.nextcloud.talk.data.user.model.User
import com.nextcloud.talk.models.domain.ConversationModel
import com.nextcloud.talk.models.json.generic.GenericOverall
import io.reactivex.Observable
import java.io.File
@ -16,4 +17,6 @@ interface ConversationInfoEditRepository {
fun uploadConversationAvatar(user: User, file: File, roomToken: String): Observable<ConversationModel>
fun deleteConversationAvatar(user: User, roomToken: String): Observable<ConversationModel>
suspend fun renameConversation(roomToken: String, roomNameNew: String): GenericOverall
}

View file

@ -7,8 +7,10 @@
package com.nextcloud.talk.conversationinfoedit.data
import com.nextcloud.talk.api.NcApi
import com.nextcloud.talk.api.NcApiCoroutines
import com.nextcloud.talk.data.user.model.User
import com.nextcloud.talk.models.domain.ConversationModel
import com.nextcloud.talk.models.json.generic.GenericOverall
import com.nextcloud.talk.utils.ApiUtils
import com.nextcloud.talk.utils.Mimetype
import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew
@ -18,7 +20,9 @@ import okhttp3.MultipartBody
import okhttp3.RequestBody.Companion.asRequestBody
import java.io.File
class ConversationInfoEditRepositoryImpl(private val ncApi: NcApi, currentUserProvider: CurrentUserProviderNew) :
class ConversationInfoEditRepositoryImpl(private val ncApi: NcApi,
private val ncApiCoroutines: NcApiCoroutines,
currentUserProvider: CurrentUserProviderNew) :
ConversationInfoEditRepository {
val currentUser: User = currentUserProvider.currentUser.blockingGet()
@ -53,4 +57,18 @@ class ConversationInfoEditRepositoryImpl(private val ncApi: NcApi, currentUserPr
ApiUtils.getUrlForConversationAvatar(1, user.baseUrl!!, roomToken)
).map { ConversationModel.mapToConversationModel(it.ocs?.data!!, user) }
}
override suspend fun renameConversation(roomToken: String, newRoomName: String): GenericOverall {
val apiVersion = ApiUtils.getConversationApiVersion(currentUser, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V1))
return ncApiCoroutines.renameRoom(
credentials,
ApiUtils.getUrlForRoom(
apiVersion,
currentUser.baseUrl!!,
roomToken
),
newRoomName
)
}
}