convert rxjava to coroutines - list bans

Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
sowjanyakch 2024-11-18 15:31:26 +01:00 committed by Marcel Hibbe
parent 3bc3a8e3ee
commit 121d7e6907
No known key found for this signature in database
GPG key ID: C793F8B59F43CE7B
7 changed files with 23 additions and 26 deletions

View file

@ -25,7 +25,6 @@ import com.nextcloud.talk.models.json.notifications.NotificationOverall;
import com.nextcloud.talk.models.json.opengraph.OpenGraphOverall;
import com.nextcloud.talk.models.json.participants.AddParticipantOverall;
import com.nextcloud.talk.models.json.participants.ParticipantsOverall;
import com.nextcloud.talk.models.json.participants.TalkBan;
import com.nextcloud.talk.models.json.participants.TalkBanOverall;
import com.nextcloud.talk.models.json.push.PushRegistrationOverall;
import com.nextcloud.talk.models.json.reactions.ReactionsOverall;

View file

@ -12,6 +12,8 @@ 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.models.json.participants.TalkBan
import com.nextcloud.talk.models.json.participants.TalkBanOverall
import io.reactivex.Observable
import okhttp3.MultipartBody
import okhttp3.RequestBody
import retrofit2.http.Body
@ -130,6 +132,12 @@ interface NcApiCoroutines {
@Field("internalNote") internalNote: String
): TalkBan
@GET
suspend fun listBans(
@Header("Authorization") authorization: String,
@Url url: String
): TalkBanOverall
@POST
suspend fun addConversationToFavorites(
@Header("Authorization") authorization: String,

View file

@ -64,6 +64,5 @@ 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 listBans(credentials: String, url: String): Observable<List<TalkBan>>
fun unbanActor(credentials: String, url: String): Observable<GenericOverall>
}

View file

@ -14,7 +14,6 @@ import com.nextcloud.talk.models.json.chat.ChatOverallSingleMessage
import com.nextcloud.talk.models.json.conversations.RoomOverall
import com.nextcloud.talk.models.json.conversations.RoomsOverall
import com.nextcloud.talk.models.json.generic.GenericOverall
import com.nextcloud.talk.models.json.participants.TalkBan
import com.nextcloud.talk.models.json.reminder.Reminder
import com.nextcloud.talk.utils.ApiUtils
import io.reactivex.Observable
@ -180,10 +179,6 @@ class RetrofitChatNetwork(private val ncApi: NcApi) : ChatNetworkDataSource {
return ncApi.editChatMessage(credentials, url, text).map { it }
}
override fun listBans(credentials: String, url: String): Observable<List<TalkBan>> {
return ncApi.listBans(credentials, url).map { it.ocs?.data }
}
override fun unbanActor(credentials: String, url: String): Observable<GenericOverall> {
return ncApi.unbanActor(credentials, url)
}

View file

@ -153,26 +153,15 @@ class ConversationInfoViewModel @Inject constructor(
fun listBans(user: User, token: String) {
val url = ApiUtils.getUrlForBans(user.baseUrl!!, token)
chatNetworkDataSource.listBans(user.getCredentials(), url)
.subscribeOn(Schedulers.io())
?.observeOn(AndroidSchedulers.mainThread())
?.subscribe(object : Observer<List<TalkBan>> {
override fun onSubscribe(p0: Disposable) {
// unused atm
}
viewModelScope.launch{
try{
val listBans = conversationsRepository.listBans(user.getCredentials(), url)
_getTalkBanState.value = ListBansSuccessState(listBans)
}catch(exception:Exception){
_getTalkBanState.value = ListBansErrorState
}
override fun onError(e: Throwable) {
_getTalkBanState.value = ListBansErrorState
}
override fun onComplete() {
// unused atm
}
override fun onNext(talkBans: List<TalkBan>) {
_getTalkBanState.value = ListBansSuccessState(talkBans)
}
})
}
}
fun banActor(user: User, token: String, actorType: String, actorId: String, internalNote: String) {

View file

@ -34,6 +34,8 @@ interface ConversationsRepository {
internalNote: String
): TalkBan
suspend fun listBans(credentials: String, url: String): List<TalkBan>
suspend fun setPassword(password: String, token: String): GenericOverall
suspend fun setConversationReadOnly(roomToken: String, state: Int): GenericOverall

View file

@ -111,6 +111,11 @@ class ConversationsRepositoryImpl(
return coroutineApi.banActor(credentials, url, actorType, actorId, internalNote)
}
override suspend fun listBans(credentials: String, url: String): List<TalkBan> {
val talkBanOverall = coroutineApi.listBans(credentials, url)
return talkBanOverall.ocs?.data!!
}
private fun apiVersion(): Int {
return ApiUtils.getConversationApiVersion(user, intArrayOf(ApiUtils.API_V4))
}