Add api endpoints
This commit is contained in:
parent
c6bd8ac265
commit
f96de62fef
|
@ -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<AdminReport> getReport(
|
||||
|
@ -149,4 +153,53 @@ public interface MastodonAdminService {
|
|||
@Header("Authorization") String app_token,
|
||||
@Path("id") String id
|
||||
);
|
||||
|
||||
|
||||
//*************** ADMIN DOMAINS ****************
|
||||
|
||||
@GET("admin/domain_blocks")
|
||||
Call<List<AdminDomainBlock>> getDomainBlocks(
|
||||
@Header("Authorization") String token,
|
||||
@Query("max_id") String max_id,
|
||||
@Query("limit") int limit
|
||||
);
|
||||
|
||||
@GET("admin/domain_blocks/{id}")
|
||||
Call<AdminDomainBlock> getDomainBlock(
|
||||
@Header("Authorization") String token,
|
||||
@Path("id") String id
|
||||
);
|
||||
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST("admin/domain_blocks")
|
||||
Call<AdminDomainBlock> 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<AdminDomainBlock> 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<Void> deleteBlockDomain(
|
||||
@Header("Authorization") String app_token,
|
||||
@Path("id") String id
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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 <http://www.gnu.org/licenses>. */
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import app.fedilab.android.client.entities.api.Pagination;
|
||||
|
||||
public class AdminDomainBlocks {
|
||||
|
||||
public Pagination pagination = new Pagination();
|
||||
public List<AdminDomainBlock> adminDomainBlocks;
|
||||
}
|
|
@ -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<AdminAccounts> adminAccountsListMutableLiveData;
|
||||
private MutableLiveData<AdminReport> adminReportMutableLiveData;
|
||||
private MutableLiveData<AdminReports> adminReporstListMutableLiveData;
|
||||
private MutableLiveData<AdminDomainBlock> adminDomainBlockMutableLiveData;
|
||||
private MutableLiveData<AdminDomainBlocks> 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<AdminDomainBlocks> getDomainBlocks(@NonNull String instance,
|
||||
String token,
|
||||
String max_id) {
|
||||
MastodonAdminService mastodonAdminService = init(instance);
|
||||
adminDomainBlockListMutableLiveData = new MutableLiveData<>();
|
||||
new Thread(() -> {
|
||||
List<AdminDomainBlock> adminDomainBlockList;
|
||||
Call<List<AdminDomainBlock>> getDomainBlocks = mastodonAdminService.getDomainBlocks(token, max_id, MastodonHelper.statusesPerCall(getApplication()));
|
||||
AdminDomainBlocks adminDomainBlocks = new AdminDomainBlocks();
|
||||
if (getDomainBlocks != null) {
|
||||
try {
|
||||
Response<List<AdminDomainBlock>> 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<AdminDomainBlock> getDomainBlock(@NonNull String instance,
|
||||
String token,
|
||||
String id) {
|
||||
MastodonAdminService mastodonAdminService = init(instance);
|
||||
adminDomainBlockMutableLiveData = new MutableLiveData<>();
|
||||
new Thread(() -> {
|
||||
AdminDomainBlock adminDomainBlock = null;
|
||||
Call<AdminDomainBlock> getDomainBlock = mastodonAdminService.getDomainBlock(token, id);
|
||||
if (getDomainBlock != null) {
|
||||
try {
|
||||
Response<AdminDomainBlock> 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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue