mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-22 04:55:29 +03:00
convert rxjava to coroutines - list bans
Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
parent
3bc3a8e3ee
commit
121d7e6907
7 changed files with 23 additions and 26 deletions
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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>
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue