From 7ae39bfcd22dcb2f1119769a3fcf5c24ccfdad66 Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Mon, 18 Nov 2024 15:13:01 +0100 Subject: [PATCH 1/8] convert rxjava to coroutines - ban actor Signed-off-by: sowjanyakch --- .../com/nextcloud/talk/api/NcApiCoroutines.kt | 11 ++++++ .../data/network/ChatNetworkDataSource.kt | 8 ----- .../chat/data/network/RetrofitChatNetwork.kt | 10 ------ .../viewmodel/ConversationInfoViewModel.kt | 34 ++++++++----------- .../conversations/ConversationsRepository.kt | 11 ++++++ .../ConversationsRepositoryImpl.kt | 11 ++++++ 6 files changed, 47 insertions(+), 38 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt b/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt index 1970d2eeda..0b5d51b628 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt +++ b/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt @@ -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, diff --git a/app/src/main/java/com/nextcloud/talk/chat/data/network/ChatNetworkDataSource.kt b/app/src/main/java/com/nextcloud/talk/chat/data/network/ChatNetworkDataSource.kt index f182929174..ded1c81660 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/data/network/ChatNetworkDataSource.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/data/network/ChatNetworkDataSource.kt @@ -65,13 +65,5 @@ interface ChatNetworkDataSource { fun setChatReadMarker(credentials: String, url: String, previousMessageId: Int): Observable fun editChatMessage(credentials: String, url: String, text: String): Observable fun listBans(credentials: String, url: String): Observable> - fun banActor( - credentials: String, - url: String, - actorType: String, - actorId: String, - internalNote: String - ): Observable - fun unbanActor(credentials: String, url: String): Observable } diff --git a/app/src/main/java/com/nextcloud/talk/chat/data/network/RetrofitChatNetwork.kt b/app/src/main/java/com/nextcloud/talk/chat/data/network/RetrofitChatNetwork.kt index 774a6d423f..b5057bd7a2 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/data/network/RetrofitChatNetwork.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/data/network/RetrofitChatNetwork.kt @@ -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 { - return ncApi.banActor(credentials, url, actorType, actorId, internalNote) - } - override fun unbanActor(credentials: String, url: String): Observable { return ncApi.unbanActor(credentials, url) } diff --git a/app/src/main/java/com/nextcloud/talk/conversationinfo/viewmodel/ConversationInfoViewModel.kt b/app/src/main/java/com/nextcloud/talk/conversationinfo/viewmodel/ConversationInfoViewModel.kt index b6b4ef2885..1e86d166c6 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfo/viewmodel/ConversationInfoViewModel.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfo/viewmodel/ConversationInfoViewModel.kt @@ -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 { - 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) { diff --git a/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepository.kt b/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepository.kt index 75d373dd69..c9397280c0 100644 --- a/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepository.kt +++ b/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepository.kt @@ -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 + + 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 diff --git a/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepositoryImpl.kt b/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepositoryImpl.kt index 2d7fa0609e..1766f9a8ad 100644 --- a/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepositoryImpl.kt +++ b/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepositoryImpl.kt @@ -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)) } From 3bc3a8e3ee8d9c6a863ef40e2f2c9e602a454acd Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Mon, 18 Nov 2024 15:14:58 +0100 Subject: [PATCH 2/8] remove unused endpoint Signed-off-by: sowjanyakch --- app/src/main/java/com/nextcloud/talk/api/NcApi.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/api/NcApi.java b/app/src/main/java/com/nextcloud/talk/api/NcApi.java index 38476a29a3..6567aab8e0 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApi.java +++ b/app/src/main/java/com/nextcloud/talk/api/NcApi.java @@ -655,14 +655,6 @@ Observable rejectInvitation(@Header("Authorization") String auth Observable listBans(@Header("Authorization") String authorization, @Url String url); - @FormUrlEncoded - @POST - Observable banActor(@Header("Authorization") String authorization, - @Url String url, - @Field("actorType") String actorType, - @Field("actorId") String actorId, - @Field("internalNote") String internalNote); - @DELETE Observable unbanActor(@Header("Authorization") String authorization, @Url String url); From 121d7e6907ba611be57f66d1db4953cdbae1bea7 Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Mon, 18 Nov 2024 15:31:26 +0100 Subject: [PATCH 3/8] convert rxjava to coroutines - list bans Signed-off-by: sowjanyakch --- .../java/com/nextcloud/talk/api/NcApi.java | 1 - .../com/nextcloud/talk/api/NcApiCoroutines.kt | 8 ++++++ .../data/network/ChatNetworkDataSource.kt | 1 - .../chat/data/network/RetrofitChatNetwork.kt | 5 ---- .../viewmodel/ConversationInfoViewModel.kt | 27 ++++++------------- .../conversations/ConversationsRepository.kt | 2 ++ .../ConversationsRepositoryImpl.kt | 5 ++++ 7 files changed, 23 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/api/NcApi.java b/app/src/main/java/com/nextcloud/talk/api/NcApi.java index 6567aab8e0..e2b02f1c37 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApi.java +++ b/app/src/main/java/com/nextcloud/talk/api/NcApi.java @@ -25,7 +25,6 @@ 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; diff --git a/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt b/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt index 0b5d51b628..2f6f964732 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt +++ b/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt @@ -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, diff --git a/app/src/main/java/com/nextcloud/talk/chat/data/network/ChatNetworkDataSource.kt b/app/src/main/java/com/nextcloud/talk/chat/data/network/ChatNetworkDataSource.kt index ded1c81660..f97299c4b2 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/data/network/ChatNetworkDataSource.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/data/network/ChatNetworkDataSource.kt @@ -64,6 +64,5 @@ interface ChatNetworkDataSource { fun createRoom(credentials: String, url: String, map: Map): Observable fun setChatReadMarker(credentials: String, url: String, previousMessageId: Int): Observable fun editChatMessage(credentials: String, url: String, text: String): Observable - fun listBans(credentials: String, url: String): Observable> fun unbanActor(credentials: String, url: String): Observable } diff --git a/app/src/main/java/com/nextcloud/talk/chat/data/network/RetrofitChatNetwork.kt b/app/src/main/java/com/nextcloud/talk/chat/data/network/RetrofitChatNetwork.kt index b5057bd7a2..84d00d4bdf 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/data/network/RetrofitChatNetwork.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/data/network/RetrofitChatNetwork.kt @@ -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> { - return ncApi.listBans(credentials, url).map { it.ocs?.data } - } - override fun unbanActor(credentials: String, url: String): Observable { return ncApi.unbanActor(credentials, url) } diff --git a/app/src/main/java/com/nextcloud/talk/conversationinfo/viewmodel/ConversationInfoViewModel.kt b/app/src/main/java/com/nextcloud/talk/conversationinfo/viewmodel/ConversationInfoViewModel.kt index 1e86d166c6..9ab42244cd 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfo/viewmodel/ConversationInfoViewModel.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfo/viewmodel/ConversationInfoViewModel.kt @@ -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> { - override fun onSubscribe(p0: Disposable) { - // unused atm - } - - override fun onError(e: Throwable) { - _getTalkBanState.value = ListBansErrorState - } - - override fun onComplete() { - // unused atm - } + viewModelScope.launch{ + try{ + val listBans = conversationsRepository.listBans(user.getCredentials(), url) + _getTalkBanState.value = ListBansSuccessState(listBans) + }catch(exception:Exception){ + _getTalkBanState.value = ListBansErrorState + } - override fun onNext(talkBans: List) { - _getTalkBanState.value = ListBansSuccessState(talkBans) - } - }) + } } fun banActor(user: User, token: String, actorType: String, actorId: String, internalNote: String) { diff --git a/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepository.kt b/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepository.kt index c9397280c0..8fc2d9c4c5 100644 --- a/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepository.kt +++ b/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepository.kt @@ -34,6 +34,8 @@ interface ConversationsRepository { internalNote: String ): TalkBan + suspend fun listBans(credentials: String, url: String): List + suspend fun setPassword(password: String, token: String): GenericOverall suspend fun setConversationReadOnly(roomToken: String, state: Int): GenericOverall diff --git a/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepositoryImpl.kt b/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepositoryImpl.kt index 1766f9a8ad..58c3bca423 100644 --- a/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepositoryImpl.kt +++ b/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepositoryImpl.kt @@ -111,6 +111,11 @@ class ConversationsRepositoryImpl( return coroutineApi.banActor(credentials, url, actorType, actorId, internalNote) } + override suspend fun listBans(credentials: String, url: String): List { + val talkBanOverall = coroutineApi.listBans(credentials, url) + return talkBanOverall.ocs?.data!! + } + private fun apiVersion(): Int { return ApiUtils.getConversationApiVersion(user, intArrayOf(ApiUtils.API_V4)) } From bdda04c21e0a59802069ababa51a12bf62b618bb Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Mon, 18 Nov 2024 15:34:08 +0100 Subject: [PATCH 4/8] remove unused code Signed-off-by: sowjanyakch --- app/src/main/java/com/nextcloud/talk/api/NcApi.java | 4 ---- app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt | 1 - .../nextcloud/talk/chat/data/network/ChatNetworkDataSource.kt | 1 - 3 files changed, 6 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/api/NcApi.java b/app/src/main/java/com/nextcloud/talk/api/NcApi.java index e2b02f1c37..3ed8ae06dc 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApi.java +++ b/app/src/main/java/com/nextcloud/talk/api/NcApi.java @@ -650,10 +650,6 @@ Observable acceptInvitation(@Header("Authorization") String auth Observable rejectInvitation(@Header("Authorization") String authorization, @Url String url); - @GET - Observable listBans(@Header("Authorization") String authorization, - @Url String url); - @DELETE Observable unbanActor(@Header("Authorization") String authorization, @Url String url); diff --git a/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt b/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt index 2f6f964732..1ed82671a9 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt +++ b/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt @@ -13,7 +13,6 @@ 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 diff --git a/app/src/main/java/com/nextcloud/talk/chat/data/network/ChatNetworkDataSource.kt b/app/src/main/java/com/nextcloud/talk/chat/data/network/ChatNetworkDataSource.kt index f97299c4b2..2439d5d942 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/data/network/ChatNetworkDataSource.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/data/network/ChatNetworkDataSource.kt @@ -13,7 +13,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 io.reactivex.Observable import retrofit2.Response From a95433c6bcb03e9fb1bf7ed5ff4589fa016257b2 Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Mon, 18 Nov 2024 15:46:11 +0100 Subject: [PATCH 5/8] convert rxjava to coroutines - unban actor Signed-off-by: sowjanyakch --- .../com/nextcloud/talk/api/NcApiCoroutines.kt | 8 ++--- .../data/network/ChatNetworkDataSource.kt | 1 - .../chat/data/network/RetrofitChatNetwork.kt | 4 --- .../viewmodel/ConversationInfoViewModel.kt | 35 ++++++------------- .../conversations/ConversationsRepository.kt | 1 + .../ConversationsRepositoryImpl.kt | 8 +++-- 6 files changed, 22 insertions(+), 35 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt b/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt index 1ed82671a9..3bbdf0f901 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt +++ b/app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt @@ -132,10 +132,10 @@ interface NcApiCoroutines { ): TalkBan @GET - suspend fun listBans( - @Header("Authorization") authorization: String, - @Url url: String - ): TalkBanOverall + suspend fun listBans(@Header("Authorization") authorization: String, @Url url: String): TalkBanOverall + + @DELETE + suspend fun unbanActor(@Header("Authorization") authorization: String, @Url url: String): GenericOverall @POST suspend fun addConversationToFavorites( diff --git a/app/src/main/java/com/nextcloud/talk/chat/data/network/ChatNetworkDataSource.kt b/app/src/main/java/com/nextcloud/talk/chat/data/network/ChatNetworkDataSource.kt index 2439d5d942..3b52c0a41e 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/data/network/ChatNetworkDataSource.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/data/network/ChatNetworkDataSource.kt @@ -63,5 +63,4 @@ interface ChatNetworkDataSource { fun createRoom(credentials: String, url: String, map: Map): Observable fun setChatReadMarker(credentials: String, url: String, previousMessageId: Int): Observable fun editChatMessage(credentials: String, url: String, text: String): Observable - fun unbanActor(credentials: String, url: String): Observable } diff --git a/app/src/main/java/com/nextcloud/talk/chat/data/network/RetrofitChatNetwork.kt b/app/src/main/java/com/nextcloud/talk/chat/data/network/RetrofitChatNetwork.kt index 84d00d4bdf..080b0706f6 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/data/network/RetrofitChatNetwork.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/data/network/RetrofitChatNetwork.kt @@ -178,8 +178,4 @@ class RetrofitChatNetwork(private val ncApi: NcApi) : ChatNetworkDataSource { override fun editChatMessage(credentials: String, url: String, text: String): Observable { return ncApi.editChatMessage(credentials, url, text).map { it } } - - override fun unbanActor(credentials: String, url: String): Observable { - return ncApi.unbanActor(credentials, url) - } } diff --git a/app/src/main/java/com/nextcloud/talk/conversationinfo/viewmodel/ConversationInfoViewModel.kt b/app/src/main/java/com/nextcloud/talk/conversationinfo/viewmodel/ConversationInfoViewModel.kt index 9ab42244cd..7cf70aa715 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfo/viewmodel/ConversationInfoViewModel.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfo/viewmodel/ConversationInfoViewModel.kt @@ -153,14 +153,13 @@ class ConversationInfoViewModel @Inject constructor( fun listBans(user: User, token: String) { val url = ApiUtils.getUrlForBans(user.baseUrl!!, token) - viewModelScope.launch{ - try{ + viewModelScope.launch { + try { val listBans = conversationsRepository.listBans(user.getCredentials(), url) _getTalkBanState.value = ListBansSuccessState(listBans) - }catch(exception:Exception){ + } catch (exception: Exception) { _getTalkBanState.value = ListBansErrorState } - } } @@ -195,26 +194,14 @@ class ConversationInfoViewModel @Inject constructor( fun unbanActor(user: User, token: String, banId: Int) { val url = ApiUtils.getUrlForUnban(user.baseUrl!!, token, banId) - chatNetworkDataSource.unbanActor(user.getCredentials(), url) - .subscribeOn(Schedulers.io()) - ?.observeOn(AndroidSchedulers.mainThread()) - ?.subscribe(object : Observer { - override fun onSubscribe(p0: Disposable) { - // unused atm - } - - override fun onError(p0: Throwable) { - _getUnBanActorState.value = UnBanActorErrorState - } - - override fun onComplete() { - // unused atm - } - - override fun onNext(p0: GenericOverall) { - _getUnBanActorState.value = UnBanActorSuccessState - } - }) + viewModelScope.launch { + try { + conversationsRepository.unbanActor(user.getCredentials(), url) + _getUnBanActorState.value = UnBanActorSuccessState + } catch (exception: Exception) { + _getUnBanActorState.value = UnBanActorErrorState + } + } } fun allowGuests(token: String, allow: Boolean) { diff --git a/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepository.kt b/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepository.kt index 8fc2d9c4c5..df43505046 100644 --- a/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepository.kt +++ b/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepository.kt @@ -35,6 +35,7 @@ interface ConversationsRepository { ): TalkBan suspend fun listBans(credentials: String, url: String): List + suspend fun unbanActor(credentials: String, url: String): GenericOverall suspend fun setPassword(password: String, token: String): GenericOverall diff --git a/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepositoryImpl.kt b/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepositoryImpl.kt index 58c3bca423..2a477ab397 100644 --- a/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepositoryImpl.kt +++ b/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepositoryImpl.kt @@ -112,8 +112,12 @@ class ConversationsRepositoryImpl( } override suspend fun listBans(credentials: String, url: String): List { - val talkBanOverall = coroutineApi.listBans(credentials, url) - return talkBanOverall.ocs?.data!! + val talkBanOverall = coroutineApi.listBans(credentials, url) + return talkBanOverall.ocs?.data!! + } + + override suspend fun unbanActor(credentials: String, url: String): GenericOverall { + return coroutineApi.unbanActor(credentials, url) } private fun apiVersion(): Int { From fa3e8002bc4026d2630b2d68e58bde3279ac5bb7 Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Mon, 18 Nov 2024 15:46:50 +0100 Subject: [PATCH 6/8] remove unused endpoint Signed-off-by: sowjanyakch --- app/src/main/java/com/nextcloud/talk/api/NcApi.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/api/NcApi.java b/app/src/main/java/com/nextcloud/talk/api/NcApi.java index 3ed8ae06dc..78605a7fc4 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApi.java +++ b/app/src/main/java/com/nextcloud/talk/api/NcApi.java @@ -649,8 +649,4 @@ Observable acceptInvitation(@Header("Authorization") String auth @DELETE Observable rejectInvitation(@Header("Authorization") String authorization, @Url String url); - - @DELETE - Observable unbanActor(@Header("Authorization") String authorization, - @Url String url); } \ No newline at end of file From ebfb38b5b552e204f83e690cc7385097899844a1 Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Mon, 18 Nov 2024 18:54:38 +0100 Subject: [PATCH 7/8] write logs for exceptions in viewModel Signed-off-by: sowjanyakch --- .../conversationinfo/viewmodel/ConversationInfoViewModel.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/java/com/nextcloud/talk/conversationinfo/viewmodel/ConversationInfoViewModel.kt b/app/src/main/java/com/nextcloud/talk/conversationinfo/viewmodel/ConversationInfoViewModel.kt index 7cf70aa715..a9ed147e7f 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfo/viewmodel/ConversationInfoViewModel.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfo/viewmodel/ConversationInfoViewModel.kt @@ -159,6 +159,7 @@ class ConversationInfoViewModel @Inject constructor( _getTalkBanState.value = ListBansSuccessState(listBans) } catch (exception: Exception) { _getTalkBanState.value = ListBansErrorState + Log.e(TAG, "Error while getting list of banned participants", exception) } } } @@ -177,6 +178,7 @@ class ConversationInfoViewModel @Inject constructor( _getBanActorState.value = BanActorSuccessState(talkBan) } catch (exception: Exception) { _getBanActorState.value = BanActorErrorState + Log.e(TAG, "Error banning a participant", exception) } } } @@ -200,6 +202,7 @@ class ConversationInfoViewModel @Inject constructor( _getUnBanActorState.value = UnBanActorSuccessState } catch (exception: Exception) { _getUnBanActorState.value = UnBanActorErrorState + Log.e(TAG, "Error while unbanning a participant", exception) } } } From e8cf3eed5643ca0067de03f60e694fa2cd693fec Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Thu, 21 Nov 2024 11:18:36 +0100 Subject: [PATCH 8/8] add setConversationReadOnly must have been lost during resolving merge conflicts Signed-off-by: Marcel Hibbe --- .../repositories/conversations/ConversationsRepositoryImpl.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepositoryImpl.kt b/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepositoryImpl.kt index 2a477ab397..5732b07cda 100644 --- a/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepositoryImpl.kt +++ b/app/src/main/java/com/nextcloud/talk/repositories/conversations/ConversationsRepositoryImpl.kt @@ -75,6 +75,10 @@ class ConversationsRepositoryImpl( return coroutineApi.unarchiveConversation(credentials, url) } + override fun setConversationReadOnly(credentials: String, url: String, state: Int): Observable { + return api.setConversationReadOnly(credentials, url, state) + } + override suspend fun setConversationReadOnly(roomToken: String, state: Int): GenericOverall { val apiVersion = ApiUtils.getConversationApiVersion(user, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V1)) val url = ApiUtils.getUrlForConversationReadOnly(apiVersion, user.baseUrl!!, roomToken)