Commit f9b87f76 authored by Thomas's avatar Thomas
Browse files

Fix issue #534 - Allow to filter notifications for admin/moderators

parent 0b690838
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -1528,6 +1528,18 @@ public class Helper {
                channelId = "channel_status";
                channelTitle = context.getString(R.string.channel_notif_status);
                break;
            case UPDATE:
                channelId = "channel_update";
                channelTitle = context.getString(R.string.channel_notif_update);
                break;
            case SIGN_UP:
                channelId = "channel_signup";
                channelTitle = context.getString(R.string.channel_notif_signup);
                break;
            case REPORT:
                channelId = "channel_report";
                channelTitle = context.getString(R.string.channel_notif_report);
                break;
            default:
                channelId = "channel_boost";
                channelTitle = context.getString(R.string.channel_notif_boost);
@@ -1989,6 +2001,9 @@ public class Helper {
        BOOST,
        FAV,
        POLL,
        UPDATE,
        SIGN_UP,
        REPORT,
        STATUS,
        BACKUP,
        STORE,
+80 −36
Original line number Diff line number Diff line
@@ -158,6 +158,9 @@ public class NotificationsHelper {
        boolean notif_poll = prefs.getBoolean(context.getString(R.string.SET_NOTIF_POLL), true);
        boolean notif_fav = prefs.getBoolean(context.getString(R.string.SET_NOTIF_FAVOURITE), true);
        boolean notif_status = prefs.getBoolean(context.getString(R.string.SET_NOTIF_STATUS), true);
        boolean notif_update = prefs.getBoolean(context.getString(R.string.SET_NOTIF_UPDATE), true);
        boolean notif_signup = prefs.getBoolean(context.getString(R.string.SET_NOTIF_ADMIN_SIGNUP), true);
        boolean notif_report = prefs.getBoolean(context.getString(R.string.SET_NOTIF_ADMIN_REPORT), true);

        final String max_id = prefs.getString(context.getString(R.string.LAST_NOTIFICATION_ID) + key, null);

@@ -232,7 +235,6 @@ public class NotificationsHelper {
                            title = String.format("%s %s", notification.account.display_name, context.getString(R.string.notif_reblog));
                        else
                            title = String.format("@%s %s", notification.account.acct, context.getString(R.string.notif_reblog));
                    }
                        if (notification.status != null) {
                            if (notification.status.spoiler_text != null && notification.status.spoiler_text.length() > 0) {
                                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
@@ -246,6 +248,7 @@ public class NotificationsHelper {
                                    message = new SpannableString(Html.fromHtml(notification.status.content)).toString();
                            }
                        }
                    }
                    break;
                case "favourite":
                    notifType = Helper.NotifType.FAV;
@@ -254,7 +257,6 @@ public class NotificationsHelper {
                            title = String.format("%s %s", notification.account.display_name, context.getString(R.string.notif_favourite));
                        else
                            title = String.format("@%s %s", notification.account.acct, context.getString(R.string.notif_favourite));
                    }
                        if (notification.status != null) {
                            if (notification.status.spoiler_text != null && notification.status.spoiler_text.length() > 0) {
                                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
@@ -268,6 +270,7 @@ public class NotificationsHelper {
                                    message = new SpannableString(Html.fromHtml(notification.status.content)).toString();
                            }
                        }
                    }
                    break;
                case "follow_request":
                    notifType = Helper.NotifType.FOLLLOW;
@@ -298,7 +301,25 @@ public class NotificationsHelper {
                            title = context.getString(R.string.notif_poll_self);
                        else
                            title = context.getString(R.string.notif_poll);
                        if (notification.status != null) {
                            if (notification.status.spoiler_text != null && notification.status.spoiler_text.length() > 0) {
                                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
                                    message = new SpannableString(Html.fromHtml(notification.status.spoiler_text, FROM_HTML_MODE_LEGACY)).toString();
                                else
                                    message = new SpannableString(Html.fromHtml(notification.status.spoiler_text)).toString();
                            } else {
                                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
                                    message = new SpannableString(Html.fromHtml(notification.status.content, FROM_HTML_MODE_LEGACY)).toString();
                                else
                                    message = new SpannableString(Html.fromHtml(notification.status.content)).toString();
                            }
                        }
                    }
                    break;
                case "update":
                    notifType = Helper.NotifType.UPDATE;
                    if (notif_update) {
                        title = context.getString(R.string.notif_update_push);
                        if (notification.status != null) {
                            if (notification.status.spoiler_text != null && notification.status.spoiler_text.length() > 0) {
                                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
@@ -312,6 +333,29 @@ public class NotificationsHelper {
                                    message = new SpannableString(Html.fromHtml(notification.status.content)).toString();
                            }
                        }
                    }
                    break;
                case "admin.sign_up":
                    notifType = Helper.NotifType.SIGN_UP;
                    if (notif_signup) {
                        title = context.getString(R.string.notif_sign_up);
                        if (notification.account.display_name != null && notification.account.display_name.length() > 0)
                            message = String.format("%s %s", notification.account.display_name, context.getString(R.string.notif_signed_up));
                        else
                            message = String.format("@%s %s", notification.account.acct, context.getString(R.string.notif_signed_up));
                        targeted_account = notification.account.id;
                    }
                    break;
                case "admin.report":
                    notifType = Helper.NotifType.REPORT;
                    if (notif_report) {
                        title = context.getString(R.string.notif_report);
                        if (notification.account.display_name != null && notification.account.display_name.length() > 0)
                            message = String.format("%s %s", notification.account.display_name, context.getString(R.string.notif_reported));
                        else
                            message = String.format("@%s %s", notification.account.acct, context.getString(R.string.notif_reported));
                        targeted_account = notification.account.id;
                    }
                    break;
                default:
            }
@@ -321,7 +365,7 @@ public class NotificationsHelper {
                intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.putExtra(Helper.INTENT_ACTION, Helper.NOTIFICATION_INTENT);
                intent.putExtra(Helper.PREF_KEY_ID, account.user_id);
                if (targeted_account != null && notifType == Helper.NotifType.FOLLLOW)
                if (targeted_account != null)
                    intent.putExtra(Helper.INTENT_TARGETED_ACCOUNT, targeted_account);
                intent.putExtra(Helper.PREF_INSTANCE, account.instance);
                notificationUrl = notification.account.avatar;
+18 −0
Original line number Diff line number Diff line
@@ -83,6 +83,8 @@ public class FragmentNotificationContainer extends Fragment {
            binding.tabLayout.addTab(binding.tabLayout.newTab().setIcon(R.drawable.ic_baseline_home_24));
            binding.tabLayout.addTab(binding.tabLayout.newTab().setIcon(R.drawable.ic_baseline_person_add_alt_1_24));
            binding.tabLayout.addTab(binding.tabLayout.newTab().setIcon(R.drawable.ic_baseline_edit_24));
            binding.tabLayout.addTab(binding.tabLayout.newTab().setIcon(R.drawable.ic_baseline_person_add_alt_1_24));
            binding.tabLayout.addTab(binding.tabLayout.newTab().setIcon(R.drawable.ic_baseline_report_24));
            binding.viewpagerNotificationContainer.setAdapter(new FedilabNotificationPageAdapter(getChildFragmentManager(), true));
        }
        AtomicBoolean changes = new AtomicBoolean(false);
@@ -98,6 +100,8 @@ public class FragmentNotificationContainer extends Fragment {
            ThemeHelper.changeButtonColor(requireActivity(), dialogView.displayUpdatesFromPeople);
            ThemeHelper.changeButtonColor(requireActivity(), dialogView.displayFollows);
            ThemeHelper.changeButtonColor(requireActivity(), dialogView.displayUpdates);
            ThemeHelper.changeButtonColor(requireActivity(), dialogView.displaySignups);
            ThemeHelper.changeButtonColor(requireActivity(), dialogView.displayReports);

            DrawableCompat.setTintList(DrawableCompat.wrap(dialogView.displayAllCategories.getThumbDrawable()), ThemeHelper.getSwitchCompatThumbDrawable(requireActivity()));
            DrawableCompat.setTintList(DrawableCompat.wrap(dialogView.displayAllCategories.getTrackDrawable()), ThemeHelper.getSwitchCompatTrackDrawable(requireActivity()));
@@ -134,6 +138,8 @@ public class FragmentNotificationContainer extends Fragment {
            dialogView.displayUpdatesFromPeople.setChecked(true);
            dialogView.displayFollows.setChecked(true);
            dialogView.displayUpdates.setChecked(true);
            dialogView.displaySignups.setChecked(true);
            dialogView.displayReports.setChecked(true);
            String excludedCategories = sharedpreferences.getString(getString(R.string.SET_EXCLUDED_NOTIFICATIONS_TYPE) + BaseMainActivity.currentUserID + BaseMainActivity.currentInstance, null);
            List<String> excludedCategoriesList = new ArrayList<>();
            if (excludedCategories != null) {
@@ -168,6 +174,14 @@ public class FragmentNotificationContainer extends Fragment {
                            excludedCategoriesList.add("update");
                            dialogView.displayUpdates.setChecked(false);
                            break;
                        case "admin.sign_up":
                            excludedCategoriesList.add("admin.sign_up");
                            dialogView.displaySignups.setChecked(false);
                            break;
                        case "admin.report":
                            excludedCategoriesList.add("admin.report");
                            dialogView.displayReports.setChecked(false);
                            break;
                    }
                }
            }
@@ -188,6 +202,10 @@ public class FragmentNotificationContainer extends Fragment {
                    notificationType = "follow";
                } else if (checkedId == R.id.display_updates) {
                    notificationType = "update";
                } else if (checkedId == R.id.display_signups) {
                    notificationType = "admin.sign_up";
                } else if (checkedId == R.id.display_reports) {
                    notificationType = "admin.report";
                }
                if (isChecked) {
                    excludedCategoriesList.remove(notificationType);
+7 −1
Original line number Diff line number Diff line
@@ -86,6 +86,12 @@ public class FedilabNotificationPageAdapter extends FragmentStatePagerAdapter {
                case 7:
                    bundle.putSerializable(Helper.ARG_NOTIFICATION_TYPE, FragmentMastodonNotification.NotificationTypeEnum.UPDATES);
                    break;
                case 8:
                    bundle.putSerializable(Helper.ARG_NOTIFICATION_TYPE, FragmentMastodonNotification.NotificationTypeEnum.ADMIN_SIGNUP);
                    break;
                case 9:
                    bundle.putSerializable(Helper.ARG_NOTIFICATION_TYPE, FragmentMastodonNotification.NotificationTypeEnum.ADMIN_REPORT);
                    break;
            }
        }
        fragmentMastodonNotification.setArguments(bundle);
@@ -94,6 +100,6 @@ public class FedilabNotificationPageAdapter extends FragmentStatePagerAdapter {

    @Override
    public int getCount() {
        return extended ? 8 : 2;
        return extended ? 10 : 2;
    }
}
 No newline at end of file
+1 −1
Original line number Diff line number Diff line
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:tint="?attr/colorControlNormal"
    android:tint="#FFFFFF"
    android:viewportWidth="24"
    android:viewportHeight="24">
    <path
Loading