diff --git a/app/src/main/java/app/fedilab/android/client/endpoints/MastodonAdminService.java b/app/src/main/java/app/fedilab/android/client/endpoints/MastodonAdminService.java index 7db4317ec..5d3aff278 100644 --- a/app/src/main/java/app/fedilab/android/client/endpoints/MastodonAdminService.java +++ b/app/src/main/java/app/fedilab/android/client/endpoints/MastodonAdminService.java @@ -18,13 +18,16 @@ package app.fedilab.android.client.endpoints; import java.util.List; import app.fedilab.android.client.entities.api.admin.AdminAccount; +import app.fedilab.android.client.entities.api.admin.AdminDomainBlock; import app.fedilab.android.client.entities.api.admin.AdminReport; import retrofit2.Call; +import retrofit2.http.DELETE; import retrofit2.http.Field; import retrofit2.http.FormUrlEncoded; import retrofit2.http.GET; import retrofit2.http.Header; import retrofit2.http.POST; +import retrofit2.http.PUT; import retrofit2.http.Path; import retrofit2.http.Query; @@ -115,6 +118,7 @@ public interface MastodonAdminService { @Query("limit") int limit ); + //***************** ADMIN REPORTS ************** @GET("admin/reports/{id}") Call getReport( @@ -149,4 +153,53 @@ public interface MastodonAdminService { @Header("Authorization") String app_token, @Path("id") String id ); + + + //*************** ADMIN DOMAINS **************** + + @GET("admin/domain_blocks") + Call> getDomainBlocks( + @Header("Authorization") String token, + @Query("max_id") String max_id, + @Query("limit") int limit + ); + + @GET("admin/domain_blocks/{id}") + Call getDomainBlock( + @Header("Authorization") String token, + @Path("id") String id + ); + + + @FormUrlEncoded + @POST("admin/domain_blocks") + Call blockDomain( + @Header("Authorization") String app_token, + @Path("domain") String domain, + @Field("severity") String severity, + @Field("reject_media") Boolean reject_media, + @Field("reject_reports") Boolean reject_reports, + @Field("private_comment") String private_comment, + @Field("public_comment") String public_comment, + @Field("obfuscate") Boolean obfuscate + ); + + @FormUrlEncoded + @PUT("admin/domain_blocks") + Call updateBlockDomain( + @Header("Authorization") String app_token, + @Path("domain") String domain, + @Field("severity") String severity, + @Field("reject_media") Boolean reject_media, + @Field("reject_reports") Boolean reject_reports, + @Field("private_comment") String private_comment, + @Field("public_comment") String public_comment, + @Field("obfuscate") Boolean obfuscate + ); + + @DELETE("admin/domain_blocks/{id}") + Call deleteBlockDomain( + @Header("Authorization") String app_token, + @Path("id") String id + ); } diff --git a/app/src/main/java/app/fedilab/android/client/entities/api/admin/AdminDomainBlocks.java b/app/src/main/java/app/fedilab/android/client/entities/api/admin/AdminDomainBlocks.java new file mode 100644 index 000000000..451da28d4 --- /dev/null +++ b/app/src/main/java/app/fedilab/android/client/entities/api/admin/AdminDomainBlocks.java @@ -0,0 +1,26 @@ +package app.fedilab.android.client.entities.api.admin; +/* Copyright 2022 Thomas Schneider + * + * This file is a part of Fedilab + * + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Fedilab; if not, + * see . */ + + +import java.util.List; + +import app.fedilab.android.client.entities.api.Pagination; + +public class AdminDomainBlocks { + + public Pagination pagination = new Pagination(); + public List adminDomainBlocks; +} diff --git a/app/src/main/java/app/fedilab/android/viewmodel/mastodon/AdminVM.java b/app/src/main/java/app/fedilab/android/viewmodel/mastodon/AdminVM.java index d00a39d33..11568c0a0 100644 --- a/app/src/main/java/app/fedilab/android/viewmodel/mastodon/AdminVM.java +++ b/app/src/main/java/app/fedilab/android/viewmodel/mastodon/AdminVM.java @@ -29,6 +29,8 @@ import java.util.concurrent.TimeUnit; import app.fedilab.android.client.endpoints.MastodonAdminService; import app.fedilab.android.client.entities.api.admin.AdminAccount; import app.fedilab.android.client.entities.api.admin.AdminAccounts; +import app.fedilab.android.client.entities.api.admin.AdminDomainBlock; +import app.fedilab.android.client.entities.api.admin.AdminDomainBlocks; import app.fedilab.android.client.entities.api.admin.AdminReport; import app.fedilab.android.client.entities.api.admin.AdminReports; import app.fedilab.android.helper.Helper; @@ -51,6 +53,9 @@ public class AdminVM extends AndroidViewModel { private MutableLiveData adminAccountsListMutableLiveData; private MutableLiveData adminReportMutableLiveData; private MutableLiveData adminReporstListMutableLiveData; + private MutableLiveData adminDomainBlockMutableLiveData; + private MutableLiveData adminDomainBlockListMutableLiveData; + public AdminVM(@NonNull Application application) { super(application); @@ -556,4 +561,73 @@ public class AdminVM extends AndroidViewModel { }).start(); return adminReportMutableLiveData; } + + + /** + * View all domains blocked. + * + * @param instance Instance domain of the active account + * @param token Access token of the active account + * @return {@link LiveData} containing a {@link List} of {@link AdminDomainBlocks}s + */ + public LiveData getDomainBlocks(@NonNull String instance, + String token, + String max_id) { + MastodonAdminService mastodonAdminService = init(instance); + adminDomainBlockListMutableLiveData = new MutableLiveData<>(); + new Thread(() -> { + List adminDomainBlockList; + Call> getDomainBlocks = mastodonAdminService.getDomainBlocks(token, max_id, MastodonHelper.statusesPerCall(getApplication())); + AdminDomainBlocks adminDomainBlocks = new AdminDomainBlocks(); + if (getDomainBlocks != null) { + try { + Response> getDomainBlocksResponse = getDomainBlocks.execute(); + if (getDomainBlocksResponse.isSuccessful()) { + adminDomainBlocks.adminDomainBlocks = getDomainBlocksResponse.body(); + adminDomainBlocks.pagination = MastodonHelper.getPagination(getDomainBlocksResponse.headers()); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + Handler mainHandler = new Handler(Looper.getMainLooper()); + Runnable myRunnable = () -> adminDomainBlockListMutableLiveData.setValue(adminDomainBlocks); + mainHandler.post(myRunnable); + }).start(); + return adminDomainBlockListMutableLiveData; + } + + + /** + * View a single blocked domain + * + * @param instance Instance domain of the active account + * @param token Access token of the active account + * @return {@link LiveData} containing a {@link List} of {@link AdminDomainBlocks}s + */ + public LiveData getDomainBlock(@NonNull String instance, + String token, + String id) { + MastodonAdminService mastodonAdminService = init(instance); + adminDomainBlockMutableLiveData = new MutableLiveData<>(); + new Thread(() -> { + AdminDomainBlock adminDomainBlock = null; + Call getDomainBlock = mastodonAdminService.getDomainBlock(token, id); + if (getDomainBlock != null) { + try { + Response getDomainBlocksResponse = getDomainBlock.execute(); + if (getDomainBlocksResponse.isSuccessful()) { + adminDomainBlock = getDomainBlocksResponse.body(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + Handler mainHandler = new Handler(Looper.getMainLooper()); + AdminDomainBlock finalAdminDomainBlock = adminDomainBlock; + Runnable myRunnable = () -> adminDomainBlockMutableLiveData.setValue(finalAdminDomainBlock); + mainHandler.post(myRunnable); + }).start(); + return adminDomainBlockMutableLiveData; + } }