mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-19 03:29:28 +01:00
convert rxjava to coroutines - ban actor
Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
parent
8fa3c7bf05
commit
7ae39bfcd2
@ -11,6 +11,7 @@ import com.nextcloud.talk.models.json.autocomplete.AutocompleteOverall
|
||||
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 okhttp3.MultipartBody
|
||||
import okhttp3.RequestBody
|
||||
import retrofit2.http.Body
|
||||
@ -119,6 +120,16 @@ interface NcApiCoroutines {
|
||||
@DELETE
|
||||
suspend fun unarchiveConversation(@Header("Authorization") authorization: String, @Url url: String): GenericOverall
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST
|
||||
suspend fun banActor(
|
||||
@Header("Authorization") authorization: String,
|
||||
@Url url: String,
|
||||
@Field("actorType") actorType: String,
|
||||
@Field("actorId") actorId: String,
|
||||
@Field("internalNote") internalNote: String
|
||||
): TalkBan
|
||||
|
||||
@POST
|
||||
suspend fun addConversationToFavorites(
|
||||
@Header("Authorization") authorization: String,
|
||||
|
@ -65,13 +65,5 @@ interface ChatNetworkDataSource {
|
||||
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 banActor(
|
||||
credentials: String,
|
||||
url: String,
|
||||
actorType: String,
|
||||
actorId: String,
|
||||
internalNote: String
|
||||
): Observable<TalkBan>
|
||||
|
||||
fun unbanActor(credentials: String, url: String): Observable<GenericOverall>
|
||||
}
|
||||
|
@ -184,16 +184,6 @@ class RetrofitChatNetwork(private val ncApi: NcApi) : ChatNetworkDataSource {
|
||||
return ncApi.listBans(credentials, url).map { it.ocs?.data }
|
||||
}
|
||||
|
||||
override fun banActor(
|
||||
credentials: String,
|
||||
url: String,
|
||||
actorType: String,
|
||||
actorId: String,
|
||||
internalNote: String
|
||||
): Observable<TalkBan> {
|
||||
return ncApi.banActor(credentials, url, actorType, actorId, internalNote)
|
||||
}
|
||||
|
||||
override fun unbanActor(credentials: String, url: String): Observable<GenericOverall> {
|
||||
return ncApi.unbanActor(credentials, url)
|
||||
}
|
||||
|
@ -177,26 +177,20 @@ class ConversationInfoViewModel @Inject constructor(
|
||||
|
||||
fun banActor(user: User, token: String, actorType: String, actorId: String, internalNote: String) {
|
||||
val url = ApiUtils.getUrlForBans(user.baseUrl!!, token)
|
||||
chatNetworkDataSource.banActor(user.getCredentials(), url, actorType, actorId, internalNote)
|
||||
.subscribeOn(Schedulers.io())
|
||||
?.observeOn(AndroidSchedulers.mainThread())
|
||||
?.subscribe(object : Observer<TalkBan> {
|
||||
override fun onSubscribe(p0: Disposable) {
|
||||
// unused atm
|
||||
}
|
||||
|
||||
override fun onError(e: Throwable) {
|
||||
_getBanActorState.value = BanActorErrorState
|
||||
}
|
||||
|
||||
override fun onComplete() {
|
||||
// unused atm
|
||||
}
|
||||
|
||||
override fun onNext(talkBan: TalkBan) {
|
||||
_getBanActorState.value = BanActorSuccessState(talkBan)
|
||||
}
|
||||
})
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
val talkBan = conversationsRepository.banActor(
|
||||
user.getCredentials(),
|
||||
url,
|
||||
actorType,
|
||||
actorId,
|
||||
internalNote
|
||||
)
|
||||
_getBanActorState.value = BanActorSuccessState(talkBan)
|
||||
} catch (exception: Exception) {
|
||||
_getBanActorState.value = BanActorErrorState
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun setConversationReadOnly(roomToken: String, state: Int) {
|
||||
|
@ -8,6 +8,7 @@
|
||||
package com.nextcloud.talk.repositories.conversations
|
||||
|
||||
import com.nextcloud.talk.models.json.generic.GenericOverall
|
||||
import com.nextcloud.talk.models.json.participants.TalkBan
|
||||
import io.reactivex.Observable
|
||||
|
||||
interface ConversationsRepository {
|
||||
@ -23,6 +24,16 @@ interface ConversationsRepository {
|
||||
|
||||
suspend fun unarchiveConversation(credentials: String, url: String): GenericOverall
|
||||
|
||||
fun setConversationReadOnly(credentials: String, url: String, state: Int): Observable<GenericOverall>
|
||||
|
||||
suspend fun banActor(
|
||||
credentials: String,
|
||||
url: String,
|
||||
actorType: String,
|
||||
actorId: String,
|
||||
internalNote: String
|
||||
): TalkBan
|
||||
|
||||
suspend fun setPassword(password: String, token: String): GenericOverall
|
||||
|
||||
suspend fun setConversationReadOnly(roomToken: String, state: Int): GenericOverall
|
||||
|
@ -11,6 +11,7 @@ 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.json.generic.GenericOverall
|
||||
import com.nextcloud.talk.models.json.participants.TalkBan
|
||||
import com.nextcloud.talk.repositories.conversations.ConversationsRepository.ResendInvitationsResult
|
||||
import com.nextcloud.talk.utils.ApiUtils
|
||||
import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew
|
||||
@ -100,6 +101,16 @@ class ConversationsRepositoryImpl(
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun banActor(
|
||||
credentials: String,
|
||||
url: String,
|
||||
actorType: String,
|
||||
actorId: String,
|
||||
internalNote: String
|
||||
): TalkBan {
|
||||
return coroutineApi.banActor(credentials, url, actorType, actorId, internalNote)
|
||||
}
|
||||
|
||||
private fun apiVersion(): Int {
|
||||
return ApiUtils.getConversationApiVersion(user, intArrayOf(ApiUtils.API_V4))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user