From 213328ef1a4dc3c97a451b6e7d23658a08f6376e Mon Sep 17 00:00:00 2001 From: xmflsct Date: Sat, 10 Dec 2022 22:43:37 +0100 Subject: [PATCH] Add admin notifications besides push #535 --- src/components/Menu/Row.tsx | 2 +- src/helpers/permissions.ts | 7 + src/i18n/en/screens/actions.json | 13 -- src/i18n/en/screens/tabs.json | 17 ++- src/screens/Actions.tsx | 3 - src/screens/Actions/NotificationsFilter.tsx | 114 --------------- src/screens/Tabs/Me/Push.tsx | 12 +- src/screens/Tabs/Notifications.tsx | 73 --------- src/screens/Tabs/Notifications/Filters.tsx | 138 ++++++++++++++++++ src/screens/Tabs/Notifications/index.tsx | 61 ++++++++ src/screens/Tabs/Shared/index.tsx | 5 - src/utils/migrations/instances/migration.ts | 5 + src/utils/migrations/instances/v11.ts | 2 + src/utils/navigation/navigators.ts | 3 + src/utils/slices/instances/add.ts | 4 +- src/utils/slices/instances/push/utils.ts | 18 +-- src/utils/slices/instances/updatePushAlert.ts | 1 - 17 files changed, 244 insertions(+), 234 deletions(-) delete mode 100644 src/screens/Actions/NotificationsFilter.tsx delete mode 100644 src/screens/Tabs/Notifications.tsx create mode 100644 src/screens/Tabs/Notifications/Filters.tsx create mode 100644 src/screens/Tabs/Notifications/index.tsx diff --git a/src/components/Menu/Row.tsx b/src/components/Menu/Row.tsx index 3953e5c9..5100745d 100644 --- a/src/components/Menu/Row.tsx +++ b/src/components/Menu/Row.tsx @@ -5,7 +5,7 @@ import { StyleConstants } from '@utils/styles/constants' import { useTheme } from '@utils/styles/ThemeManager' import { ColorDefinitions } from '@utils/styles/themes' import React, { useMemo } from 'react' -import { Text, View } from 'react-native' +import { View } from 'react-native' import { Flow } from 'react-native-animated-spinkit' import { State, Switch, TapGestureHandler } from 'react-native-gesture-handler' diff --git a/src/helpers/permissions.ts b/src/helpers/permissions.ts index bbb3a1a4..3ac7986a 100644 --- a/src/helpers/permissions.ts +++ b/src/helpers/permissions.ts @@ -1,2 +1,9 @@ export const PERMISSION_MANAGE_REPORTS = 0x0000000000000010 export const PERMISSION_MANAGE_USERS = 0x0000000000000400 + +export const checkPermission = (permission: number, permissions?: string | number): boolean => + permissions + ? !!( + (typeof permissions === 'string' ? parseInt(permissions || '0') : permissions) & permission + ) + : false diff --git a/src/i18n/en/screens/actions.json b/src/i18n/en/screens/actions.json index 942accaf..970345fa 100644 --- a/src/i18n/en/screens/actions.json +++ b/src/i18n/en/screens/actions.json @@ -2,19 +2,6 @@ "content": { "altText": { "heading": "Alternative Text" - }, - "notificationsFilter": { - "heading": "Show notification types", - "content": { - "follow": "$t(screenTabs:me.push.follow.heading)", - "follow_request": "Follow request", - "favourite": "$t(screenTabs:me.push.favourite.heading)", - "reblog": "$t(screenTabs:me.push.reblog.heading)", - "mention": "$t(screenTabs:me.push.mention.heading)", - "poll": "$t(screenTabs:me.push.poll.heading)", - "status": "Toot from subscribed users", - "update": "Reblog has been edited" - } } } } \ No newline at end of file diff --git a/src/i18n/en/screens/tabs.json b/src/i18n/en/screens/tabs.json index 1c2255c9..409ac790 100644 --- a/src/i18n/en/screens/tabs.json +++ b/src/i18n/en/screens/tabs.json @@ -24,9 +24,22 @@ } }, "notifications": { - "filter": { + "filters": { "accessibilityLabel": "Filter", - "accessibilityHint": "Filter shown notifications' types" + "accessibilityHint": "Filter shown notifications' types", + "title": "Show notifications", + "options": { + "follow": "$t(screenTabs:me.push.follow.heading)", + "follow_request": "Follow request", + "favourite": "$t(screenTabs:me.push.favourite.heading)", + "reblog": "$t(screenTabs:me.push.reblog.heading)", + "mention": "$t(screenTabs:me.push.mention.heading)", + "poll": "$t(screenTabs:me.push.poll.heading)", + "status": "Toot from subscribed users", + "update": "Reblog has been edited", + "admin.sign_up": "$t(screenTabs:me.push.admin.sign_up.heading)", + "admin.report": "$t(screenTabs:me.push.admin.report.heading)" + } } }, "me": { diff --git a/src/screens/Actions.tsx b/src/screens/Actions.tsx index 54626356..0a8b3c3a 100644 --- a/src/screens/Actions.tsx +++ b/src/screens/Actions.tsx @@ -15,7 +15,6 @@ import Animated, { } from 'react-native-reanimated' import { useSafeAreaInsets } from 'react-native-safe-area-context' import ActionsAltText from './Actions/AltText' -import ActionsNotificationsFilter from './Actions/NotificationsFilter' const ScreenActions = ({ route: { params }, @@ -53,8 +52,6 @@ const ScreenActions = ({ const actions = () => { switch (params.type) { - case 'notifications_filter': - return case 'alt_text': return } diff --git a/src/screens/Actions/NotificationsFilter.tsx b/src/screens/Actions/NotificationsFilter.tsx deleted file mode 100644 index 6bd9f0db..00000000 --- a/src/screens/Actions/NotificationsFilter.tsx +++ /dev/null @@ -1,114 +0,0 @@ -import Button from '@components/Button' -import MenuContainer from '@components/Menu/Container' -import MenuHeader from '@components/Menu/Header' -import MenuRow from '@components/Menu/Row' -import { useNavigation } from '@react-navigation/native' -import { - checkInstanceFeature, - getInstanceNotificationsFilter, - updateInstanceNotificationsFilter -} from '@utils/slices/instancesSlice' -import { StyleConstants } from '@utils/styles/constants' -import React, { useMemo } from 'react' -import { useTranslation } from 'react-i18next' -import { useSelector } from 'react-redux' -import { useQueryClient } from '@tanstack/react-query' -import { QueryKeyTimeline } from '@utils/queryHooks/timeline' -import { useAppDispatch } from '@root/store' - -const ActionsNotificationsFilter: React.FC = () => { - const navigation = useNavigation() - const { t } = useTranslation('screenActions') - - const queryKey: QueryKeyTimeline = ['Timeline', { page: 'Notifications' }] - const queryClient = useQueryClient() - - const dispatch = useAppDispatch() - const instanceNotificationsFilter = useSelector( - getInstanceNotificationsFilter - ) - - if (!instanceNotificationsFilter) { - navigation.goBack() - return null - } - - const hasTypeStatus = useSelector( - checkInstanceFeature('notification_type_status') - ) - const hasTypeUpdate = useSelector( - checkInstanceFeature('notification_type_update') - ) - const options = useMemo(() => { - return ( - instanceNotificationsFilter && - ( - [ - 'follow', - 'follow_request', - 'favourite', - 'reblog', - 'mention', - 'poll', - 'status', - 'update' - ] as [ - 'follow', - 'follow_request', - 'favourite', - 'reblog', - 'mention', - 'poll', - 'status', - 'update' - ] - ) - .filter(type => { - switch (type) { - case 'status': - return hasTypeStatus - case 'update': - return hasTypeUpdate - default: - return true - } - }) - .map(type => ( - - dispatch( - updateInstanceNotificationsFilter({ - ...instanceNotificationsFilter, - [type]: !instanceNotificationsFilter[type] - }) - ) - } - /> - )) - ) - }, [instanceNotificationsFilter, hasTypeStatus, hasTypeUpdate]) - - return ( - <> - - - {options} - -