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 ): TalkBan
@GET @GET
suspend fun listBans( suspend fun listBans(@Header("Authorization") authorization: String, @Url url: String): TalkBanOverall
@Header("Authorization") authorization: String,
@Url url: String @DELETE
): TalkBanOverall suspend fun unbanActor(@Header("Authorization") authorization: String, @Url url: String): GenericOverall
@POST @POST
suspend fun addConversationToFavorites( suspend fun addConversationToFavorites(

View File

@ -63,5 +63,4 @@ interface ChatNetworkDataSource {
fun createRoom(credentials: String, url: String, map: Map<String, String>): Observable<RoomOverall> fun createRoom(credentials: String, url: String, map: Map<String, String>): Observable<RoomOverall>
fun setChatReadMarker(credentials: String, url: String, previousMessageId: Int): Observable<GenericOverall> fun setChatReadMarker(credentials: String, url: String, previousMessageId: Int): Observable<GenericOverall>
fun editChatMessage(credentials: String, url: String, text: String): Observable<ChatOverallSingleMessage> 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> { override fun editChatMessage(credentials: String, url: String, text: String): Observable<ChatOverallSingleMessage> {
return ncApi.editChatMessage(credentials, url, text).map { it } 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) { fun listBans(user: User, token: String) {
val url = ApiUtils.getUrlForBans(user.baseUrl!!, token) val url = ApiUtils.getUrlForBans(user.baseUrl!!, token)
viewModelScope.launch{ viewModelScope.launch {
try{ try {
val listBans = conversationsRepository.listBans(user.getCredentials(), url) val listBans = conversationsRepository.listBans(user.getCredentials(), url)
_getTalkBanState.value = ListBansSuccessState(listBans) _getTalkBanState.value = ListBansSuccessState(listBans)
}catch(exception:Exception){ } catch (exception: Exception) {
_getTalkBanState.value = ListBansErrorState _getTalkBanState.value = ListBansErrorState
} }
} }
} }
@ -195,26 +194,14 @@ class ConversationInfoViewModel @Inject constructor(
fun unbanActor(user: User, token: String, banId: Int) { fun unbanActor(user: User, token: String, banId: Int) {
val url = ApiUtils.getUrlForUnban(user.baseUrl!!, token, banId) val url = ApiUtils.getUrlForUnban(user.baseUrl!!, token, banId)
chatNetworkDataSource.unbanActor(user.getCredentials(), url) viewModelScope.launch {
.subscribeOn(Schedulers.io()) try {
?.observeOn(AndroidSchedulers.mainThread()) conversationsRepository.unbanActor(user.getCredentials(), url)
?.subscribe(object : Observer<GenericOverall> { _getUnBanActorState.value = UnBanActorSuccessState
override fun onSubscribe(p0: Disposable) { } catch (exception: Exception) {
// unused atm _getUnBanActorState.value = UnBanActorErrorState
} }
}
override fun onError(p0: Throwable) {
_getUnBanActorState.value = UnBanActorErrorState
}
override fun onComplete() {
// unused atm
}
override fun onNext(p0: GenericOverall) {
_getUnBanActorState.value = UnBanActorSuccessState
}
})
} }
fun allowGuests(token: String, allow: Boolean) { fun allowGuests(token: String, allow: Boolean) {

View File

@ -35,6 +35,7 @@ interface ConversationsRepository {
): TalkBan ): TalkBan
suspend fun listBans(credentials: String, url: String): List<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 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> { override suspend fun listBans(credentials: String, url: String): List<TalkBan> {
val talkBanOverall = coroutineApi.listBans(credentials, url) val talkBanOverall = coroutineApi.listBans(credentials, url)
return talkBanOverall.ocs?.data!! return talkBanOverall.ocs?.data!!
}
override suspend fun unbanActor(credentials: String, url: String): GenericOverall {
return coroutineApi.unbanActor(credentials, url)
} }
private fun apiVersion(): Int { private fun apiVersion(): Int {