mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-19 19:49:33 +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.conversations.RoomOverall
|
||||||
import com.nextcloud.talk.models.json.generic.GenericOverall
|
import com.nextcloud.talk.models.json.generic.GenericOverall
|
||||||
import com.nextcloud.talk.models.json.participants.AddParticipantOverall
|
import com.nextcloud.talk.models.json.participants.AddParticipantOverall
|
||||||
|
import com.nextcloud.talk.models.json.participants.TalkBan
|
||||||
import okhttp3.MultipartBody
|
import okhttp3.MultipartBody
|
||||||
import okhttp3.RequestBody
|
import okhttp3.RequestBody
|
||||||
import retrofit2.http.Body
|
import retrofit2.http.Body
|
||||||
@ -119,6 +120,16 @@ interface NcApiCoroutines {
|
|||||||
@DELETE
|
@DELETE
|
||||||
suspend fun unarchiveConversation(@Header("Authorization") authorization: String, @Url url: String): GenericOverall
|
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
|
@POST
|
||||||
suspend fun addConversationToFavorites(
|
suspend fun addConversationToFavorites(
|
||||||
@Header("Authorization") authorization: String,
|
@Header("Authorization") authorization: String,
|
||||||
|
@ -65,13 +65,5 @@ interface ChatNetworkDataSource {
|
|||||||
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 listBans(credentials: String, url: String): Observable<List<TalkBan>>
|
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>
|
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 }
|
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> {
|
override fun unbanActor(credentials: String, url: String): Observable<GenericOverall> {
|
||||||
return ncApi.unbanActor(credentials, url)
|
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) {
|
fun banActor(user: User, token: String, actorType: String, actorId: String, internalNote: String) {
|
||||||
val url = ApiUtils.getUrlForBans(user.baseUrl!!, token)
|
val url = ApiUtils.getUrlForBans(user.baseUrl!!, token)
|
||||||
chatNetworkDataSource.banActor(user.getCredentials(), url, actorType, actorId, internalNote)
|
viewModelScope.launch {
|
||||||
.subscribeOn(Schedulers.io())
|
try {
|
||||||
?.observeOn(AndroidSchedulers.mainThread())
|
val talkBan = conversationsRepository.banActor(
|
||||||
?.subscribe(object : Observer<TalkBan> {
|
user.getCredentials(),
|
||||||
override fun onSubscribe(p0: Disposable) {
|
url,
|
||||||
// unused atm
|
actorType,
|
||||||
}
|
actorId,
|
||||||
|
internalNote
|
||||||
override fun onError(e: Throwable) {
|
)
|
||||||
_getBanActorState.value = BanActorErrorState
|
_getBanActorState.value = BanActorSuccessState(talkBan)
|
||||||
}
|
} catch (exception: Exception) {
|
||||||
|
_getBanActorState.value = BanActorErrorState
|
||||||
override fun onComplete() {
|
}
|
||||||
// unused atm
|
}
|
||||||
}
|
|
||||||
|
|
||||||
override fun onNext(talkBan: TalkBan) {
|
|
||||||
_getBanActorState.value = BanActorSuccessState(talkBan)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setConversationReadOnly(roomToken: String, state: Int) {
|
fun setConversationReadOnly(roomToken: String, state: Int) {
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
package com.nextcloud.talk.repositories.conversations
|
package com.nextcloud.talk.repositories.conversations
|
||||||
|
|
||||||
import com.nextcloud.talk.models.json.generic.GenericOverall
|
import com.nextcloud.talk.models.json.generic.GenericOverall
|
||||||
|
import com.nextcloud.talk.models.json.participants.TalkBan
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
|
|
||||||
interface ConversationsRepository {
|
interface ConversationsRepository {
|
||||||
@ -23,6 +24,16 @@ interface ConversationsRepository {
|
|||||||
|
|
||||||
suspend fun unarchiveConversation(credentials: String, url: String): GenericOverall
|
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 setPassword(password: String, token: String): GenericOverall
|
||||||
|
|
||||||
suspend fun setConversationReadOnly(roomToken: String, state: Int): 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.api.NcApiCoroutines
|
||||||
import com.nextcloud.talk.data.user.model.User
|
import com.nextcloud.talk.data.user.model.User
|
||||||
import com.nextcloud.talk.models.json.generic.GenericOverall
|
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.repositories.conversations.ConversationsRepository.ResendInvitationsResult
|
||||||
import com.nextcloud.talk.utils.ApiUtils
|
import com.nextcloud.talk.utils.ApiUtils
|
||||||
import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew
|
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 {
|
private fun apiVersion(): Int {
|
||||||
return ApiUtils.getConversationApiVersion(user, intArrayOf(ApiUtils.API_V4))
|
return ApiUtils.getConversationApiVersion(user, intArrayOf(ApiUtils.API_V4))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user