convert rxjava to coroutines - unban actor

Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
sowjanyakch 2024-11-18 15:46:11 +01:00 committed by Marcel Hibbe
parent bdda04c21e
commit a95433c6bc
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B
6 changed files with 22 additions and 35 deletions

View File

@ -132,10 +132,10 @@ interface NcApiCoroutines {
): TalkBan
@GET
suspend fun listBans(
@Header("Authorization") authorization: String,
@Url url: String
): TalkBanOverall
suspend fun listBans(@Header("Authorization") authorization: String, @Url url: String): TalkBanOverall
@DELETE
suspend fun unbanActor(@Header("Authorization") authorization: String, @Url url: String): GenericOverall
@POST
suspend fun addConversationToFavorites(

View File

@ -63,5 +63,4 @@ interface ChatNetworkDataSource {
fun createRoom(credentials: String, url: String, map: Map<String, String>): Observable<RoomOverall>
fun setChatReadMarker(credentials: String, url: String, previousMessageId: Int): Observable<GenericOverall>
fun editChatMessage(credentials: String, url: String, text: String): Observable<ChatOverallSingleMessage>
fun unbanActor(credentials: String, url: String): Observable<GenericOverall>
}

View File

@ -178,8 +178,4 @@ class RetrofitChatNetwork(private val ncApi: NcApi) : ChatNetworkDataSource {
override fun editChatMessage(credentials: String, url: String, text: String): Observable<ChatOverallSingleMessage> {
return ncApi.editChatMessage(credentials, url, text).map { it }
}
override fun unbanActor(credentials: String, url: String): Observable<GenericOverall> {
return ncApi.unbanActor(credentials, url)
}
}

View File

@ -153,14 +153,13 @@ class ConversationInfoViewModel @Inject constructor(
fun listBans(user: User, token: String) {
val url = ApiUtils.getUrlForBans(user.baseUrl!!, token)
viewModelScope.launch{
try{
viewModelScope.launch {
try {
val listBans = conversationsRepository.listBans(user.getCredentials(), url)
_getTalkBanState.value = ListBansSuccessState(listBans)
}catch(exception:Exception){
} catch (exception: Exception) {
_getTalkBanState.value = ListBansErrorState
}
}
}
@ -195,26 +194,14 @@ class ConversationInfoViewModel @Inject constructor(
fun unbanActor(user: User, token: String, banId: Int) {
val url = ApiUtils.getUrlForUnban(user.baseUrl!!, token, banId)
chatNetworkDataSource.unbanActor(user.getCredentials(), url)
.subscribeOn(Schedulers.io())
?.observeOn(AndroidSchedulers.mainThread())
?.subscribe(object : Observer<GenericOverall> {
override fun onSubscribe(p0: Disposable) {
// unused atm
}
override fun onError(p0: Throwable) {
_getUnBanActorState.value = UnBanActorErrorState
}
override fun onComplete() {
// unused atm
}
override fun onNext(p0: GenericOverall) {
_getUnBanActorState.value = UnBanActorSuccessState
}
})
viewModelScope.launch {
try {
conversationsRepository.unbanActor(user.getCredentials(), url)
_getUnBanActorState.value = UnBanActorSuccessState
} catch (exception: Exception) {
_getUnBanActorState.value = UnBanActorErrorState
}
}
}
fun allowGuests(token: String, allow: Boolean) {

View File

@ -35,6 +35,7 @@ interface ConversationsRepository {
): TalkBan
suspend fun listBans(credentials: String, url: String): List<TalkBan>
suspend fun unbanActor(credentials: String, url: String): GenericOverall
suspend fun setPassword(password: String, token: String): GenericOverall

View File

@ -112,8 +112,12 @@ class ConversationsRepositoryImpl(
}
override suspend fun listBans(credentials: String, url: String): List<TalkBan> {
val talkBanOverall = coroutineApi.listBans(credentials, url)
return talkBanOverall.ocs?.data!!
val talkBanOverall = coroutineApi.listBans(credentials, url)
return talkBanOverall.ocs?.data!!
}
override suspend fun unbanActor(credentials: String, url: String): GenericOverall {
return coroutineApi.unbanActor(credentials, url)
}
private fun apiVersion(): Int {