From 5928feebe5aa724a1f5e39b76cf1783e59ee3cae Mon Sep 17 00:00:00 2001 From: stom79 Date: Sun, 27 Jan 2019 11:10:50 +0100 Subject: [PATCH] Allow moderator and admin to delete toots --- .../asynctasks/UpdateAccountInfoAsyncTask.java | 2 ++ .../etalab/mastodon/drawers/StatusListAdapter.java | 9 ++++++++- .../java/fr/gouv/etalab/mastodon/helper/Helper.java | 10 ++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateAccountInfoAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateAccountInfoAsyncTask.java index 400b86a18..803b6641a 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateAccountInfoAsyncTask.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateAccountInfoAsyncTask.java @@ -104,6 +104,8 @@ public class UpdateAccountInfoAsyncTask extends AsyncTask { boolean userExists = new AccountDAO(this.contextReference.get(), db).userExist(account); SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(Helper.PREF_KEY_ID, account.getId()); + editor.putBoolean(Helper.PREF_IS_MODERATOR, account.isModerator()); + editor.putBoolean(Helper.PREF_IS_ADMINISTRATOR, account.isAdmin()); editor.putString(Helper.PREF_INSTANCE, instance); editor.apply(); if( userExists) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java index 2ea95ebed..67e125f07 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java @@ -477,6 +477,10 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct boolean share_details = sharedpreferences.getBoolean(Helper.SET_SHARE_DETAILS, true); boolean confirmFav = sharedpreferences.getBoolean(Helper.SET_NOTIF_VALIDATION_FAV, false); boolean confirmBoost = sharedpreferences.getBoolean(Helper.SET_NOTIF_VALIDATION, true); + + boolean isModerator = sharedpreferences.getBoolean(Helper.PREF_IS_MODERATOR, false); + boolean isAdmin = sharedpreferences.getBoolean(Helper.PREF_IS_ADMINISTRATOR, false); + int translator = sharedpreferences.getInt(Helper.SET_TRANSLATOR, Helper.TRANS_YANDEX); int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS); if (type != RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE && !isCompactMode && displayBookmarkButton) @@ -1650,7 +1654,10 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct stringArrayConf = context.getResources().getStringArray(R.array.more_action_owner_confirm); } else { popup.getMenu().findItem(R.id.action_redraft).setVisible(false); - popup.getMenu().findItem(R.id.action_remove).setVisible(false); + if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA && (isAdmin || isModerator)) + popup.getMenu().findItem(R.id.action_remove).setVisible(true); + else + popup.getMenu().findItem(R.id.action_remove).setVisible(false); //Same instance if (status.getAccount().getAcct().split("@").length < 2) popup.getMenu().findItem(R.id.action_block_domain).setVisible(false); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java index b79fb9504..ea1490f1a 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java @@ -201,6 +201,8 @@ public class Helper { public static final String PREF_KEY_ID = "userID"; + public static final String PREF_IS_MODERATOR = "is_moderator"; + public static final String PREF_IS_ADMINISTRATOR = "is_administrator"; public static final String PREF_INSTANCE = "instance"; public static final String REDIRECT_CONTENT = "urn:ietf:wg:oauth:2.0:oob"; public static final String REDIRECT_CONTENT_WEB = "mastalab://backtomastalab"; @@ -533,6 +535,8 @@ public class Helper { editor.putString(Helper.CLIENT_ID, null); editor.putString(Helper.CLIENT_SECRET, null); editor.putString(Helper.PREF_KEY_ID, null); + editor.putBoolean(Helper.PREF_IS_MODERATOR, false); + editor.putBoolean(Helper.PREF_IS_ADMINISTRATOR, false); editor.putString(Helper.PREF_INSTANCE, null); editor.putString(Helper.ID, null); editor.apply(); @@ -1347,6 +1351,8 @@ public class Helper { editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, account.getToken()); editor.putString(Helper.PREF_KEY_ID, account.getId()); editor.putString(Helper.PREF_INSTANCE, account.getInstance().trim()); + editor.putBoolean(Helper.PREF_IS_MODERATOR, account.isModerator()); + editor.putBoolean(Helper.PREF_IS_ADMINISTRATOR, account.isAdmin()); editor.commit(); Intent changeAccount = new Intent(activity, MainActivity.class); changeAccount.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); @@ -1678,6 +1684,8 @@ public class Helper { editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, accountChoice.getToken()); editor.putString(Helper.PREF_KEY_ID, accountChoice.getId()); editor.putString(Helper.PREF_INSTANCE, accountChoice.getInstance().trim()); + editor.putBoolean(Helper.PREF_IS_MODERATOR, accountChoice.isModerator()); + editor.putBoolean(Helper.PREF_IS_ADMINISTRATOR, accountChoice.isAdmin()); editor.commit(); if(accountChoice.getSocial() != null && accountChoice.getSocial().equals("PEERTUBE")) Toasty.info(activity, activity.getString(R.string.toast_account_changed, "@" + accountChoice.getAcct()), Toast.LENGTH_LONG).show(); @@ -1731,6 +1739,8 @@ public class Helper { editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, accountChoice.getToken()); editor.putString(Helper.PREF_KEY_ID, accountChoice.getId()); editor.putString(Helper.PREF_INSTANCE, accountChoice.getInstance().trim()); + editor.putBoolean(Helper.PREF_IS_MODERATOR, accountChoice.isModerator()); + editor.putBoolean(Helper.PREF_IS_ADMINISTRATOR, accountChoice.isAdmin()); editor.commit(); Intent changeAccount = new Intent(activity, MainActivity.class); changeAccount.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);