mirror of
https://github.com/tooot-app/app
synced 2025-02-02 11:36:56 +01:00
Fix bugs
This commit is contained in:
parent
2f3e398d70
commit
0e348dcef1
1
src/@types/mastodon.d.ts
vendored
1
src/@types/mastodon.d.ts
vendored
@ -395,6 +395,7 @@ declare namespace Mastodon {
|
||||
mention: boolean
|
||||
poll: boolean
|
||||
status: boolean
|
||||
update: boolean
|
||||
'admin.sign_up': boolean
|
||||
'admin.report': boolean
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ const MenuRow: React.FC<Props> = ({
|
||||
>
|
||||
<View
|
||||
style={{
|
||||
flexGrow: 3,
|
||||
flexShrink: 3,
|
||||
flexDirection: 'row',
|
||||
alignItems: 'center',
|
||||
marginRight: StyleConstants.Spacing.M
|
||||
|
@ -1,47 +1,42 @@
|
||||
[
|
||||
{
|
||||
"feature": "notification_type_status",
|
||||
"version": 3.3
|
||||
},
|
||||
{
|
||||
"feature": "account_return_suspended",
|
||||
"version": 3.3,
|
||||
"reference": "https://github.com/mastodon/mastodon/releases/tag/v3.3.0"
|
||||
"version": 3.3
|
||||
},
|
||||
{
|
||||
"feature": "edit_post",
|
||||
"version": 3.5,
|
||||
"reference": "https://github.com/mastodon/mastodon/releases/tag/v3.5.0"
|
||||
"version": 3.5
|
||||
},
|
||||
{
|
||||
"feature": "deprecate_auth_follow",
|
||||
"version": 3.5,
|
||||
"reference": "https://github.com/mastodon/mastodon/releases/tag/v3.5.0"
|
||||
"version": 3.5
|
||||
},
|
||||
{
|
||||
"feature": "notification_type_update",
|
||||
"version": 3.5,
|
||||
"reference": "https://github.com/mastodon/mastodon/releases/tag/v3.5.0"
|
||||
"version": 3.5
|
||||
},
|
||||
{
|
||||
"feature": "notification_type_admin_signup",
|
||||
"version": 3.5,
|
||||
"reference": "https://github.com/mastodon/mastodon/releases/tag/v3.5.0"
|
||||
"version": 3.5
|
||||
},
|
||||
{
|
||||
"feature": "notification_types_positive_filter",
|
||||
"version": 3.5,
|
||||
"reference": "https://github.com/mastodon/mastodon/releases/tag/v3.5.0"
|
||||
"version": 3.5
|
||||
},
|
||||
{
|
||||
"feature": "trends_new_path",
|
||||
"version": 3.5,
|
||||
"reference": "https://github.com/mastodon/mastodon/releases/tag/v3.5.0"
|
||||
"version": 3.5
|
||||
},
|
||||
{
|
||||
"feature": "follow_tags",
|
||||
"version": 4.0,
|
||||
"reference": "https://github.com/mastodon/mastodon/releases/tag/v4.0.0"
|
||||
"version": 4.0
|
||||
},
|
||||
{
|
||||
"feature": "notification_type_admin_report",
|
||||
"version": 4.0,
|
||||
"reference": "https://github.com/mastodon/mastodon/releases/tag/v3.5.0"
|
||||
"version": 4.0
|
||||
}
|
||||
]
|
@ -3,13 +3,17 @@ import Icon from '@components/Icon'
|
||||
import { MenuContainer, MenuRow } from '@components/Menu'
|
||||
import CustomText from '@components/Text'
|
||||
import browserPackage from '@helpers/browserPackage'
|
||||
import { checkPermission } from '@helpers/permissions'
|
||||
import { useAppDispatch } from '@root/store'
|
||||
import { isDevelopment } from '@utils/checkEnvironment'
|
||||
import { useAppsQuery } from '@utils/queryHooks/apps'
|
||||
import { useProfileQuery } from '@utils/queryHooks/profile'
|
||||
import { getExpoToken, retrieveExpoToken } from '@utils/slices/appSlice'
|
||||
import { PUSH_ADMIN, PUSH_DEFAULT, setChannels } from '@utils/slices/instances/push/utils'
|
||||
import {
|
||||
PUSH_ADMIN,
|
||||
PUSH_DEFAULT,
|
||||
setChannels,
|
||||
usePushFeatures
|
||||
} from '@utils/slices/instances/push/utils'
|
||||
import { updateInstancePush } from '@utils/slices/instances/updatePush'
|
||||
import { updateInstancePushAlert } from '@utils/slices/instances/updatePushAlert'
|
||||
import { updateInstancePushDecode } from '@utils/slices/instances/updatePushDecode'
|
||||
@ -73,9 +77,11 @@ const TabMePush: React.FC = () => {
|
||||
}
|
||||
}, [appsQuery.data?.vapid_key])
|
||||
|
||||
const pushFeatures = usePushFeatures()
|
||||
|
||||
const alerts = () =>
|
||||
instancePush?.alerts
|
||||
? PUSH_DEFAULT.map(alert => (
|
||||
? PUSH_DEFAULT(pushFeatures).map(alert => (
|
||||
<MenuRow
|
||||
key={alert}
|
||||
title={t(`me.push.${alert}.heading`)}
|
||||
@ -98,8 +104,7 @@ const TabMePush: React.FC = () => {
|
||||
const profileQuery = useProfileQuery()
|
||||
const adminAlerts = () =>
|
||||
profileQuery.data?.role?.permissions
|
||||
? PUSH_ADMIN.map(({ type, permission }) =>
|
||||
checkPermission(permission, profileQuery.data.role?.permissions) ? (
|
||||
? PUSH_ADMIN(pushFeatures, profileQuery.data?.role?.permissions).map(({ type }) => (
|
||||
<MenuRow
|
||||
key={type}
|
||||
title={t(`me.push.${type}.heading`)}
|
||||
@ -116,8 +121,7 @@ const TabMePush: React.FC = () => {
|
||||
)
|
||||
}
|
||||
/>
|
||||
) : null
|
||||
)
|
||||
))
|
||||
: null
|
||||
|
||||
return (
|
||||
|
@ -4,7 +4,11 @@ import { useAppDispatch } from '@root/store'
|
||||
import { useAnnouncementQuery } from '@utils/queryHooks/announcement'
|
||||
import { useListsQuery } from '@utils/queryHooks/lists'
|
||||
import { useFollowedTagsQuery } from '@utils/queryHooks/tags'
|
||||
import { getInstanceMePage, updateInstanceMePage } from '@utils/slices/instancesSlice'
|
||||
import {
|
||||
checkInstanceFeature,
|
||||
getInstanceMePage,
|
||||
updateInstanceMePage
|
||||
} from '@utils/slices/instancesSlice'
|
||||
import { getInstancePush } from '@utils/slices/instancesSlice'
|
||||
import React, { useEffect } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
@ -17,8 +21,10 @@ const Collections: React.FC = () => {
|
||||
const dispatch = useAppDispatch()
|
||||
const mePage = useSelector(getInstanceMePage)
|
||||
|
||||
const canFollowTags = useSelector(checkInstanceFeature('follow_tags'))
|
||||
useFollowedTagsQuery({
|
||||
options: {
|
||||
enabled: canFollowTags,
|
||||
onSuccess: data =>
|
||||
dispatch(
|
||||
updateInstanceMePage({
|
||||
|
@ -1,17 +1,12 @@
|
||||
import { HeaderLeft, HeaderRight } from '@components/Header'
|
||||
import { MenuContainer, MenuRow } from '@components/Menu'
|
||||
import {
|
||||
checkPermission,
|
||||
PERMISSION_MANAGE_REPORTS,
|
||||
PERMISSION_MANAGE_USERS
|
||||
} from '@helpers/permissions'
|
||||
import { useAppDispatch } from '@root/store'
|
||||
import { useQueryClient } from '@tanstack/react-query'
|
||||
import { TabNotificationsStackScreenProps } from '@utils/navigation/navigators'
|
||||
import { useProfileQuery } from '@utils/queryHooks/profile'
|
||||
import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
|
||||
import { PUSH_ADMIN, PUSH_DEFAULT, usePushFeatures } from '@utils/slices/instances/push/utils'
|
||||
import {
|
||||
checkInstanceFeature,
|
||||
getInstanceNotificationsFilter,
|
||||
updateInstanceNotificationsFilter
|
||||
} from '@utils/slices/instancesSlice'
|
||||
@ -22,32 +17,12 @@ import { Alert } from 'react-native'
|
||||
import { ScrollView } from 'react-native-gesture-handler'
|
||||
import { useSelector } from 'react-redux'
|
||||
|
||||
export const NOTIFICATIONS_FILTERS_DEFAULT: [
|
||||
'follow',
|
||||
'follow_request',
|
||||
'favourite',
|
||||
'reblog',
|
||||
'mention',
|
||||
'poll',
|
||||
'status',
|
||||
'update'
|
||||
] = ['follow', 'follow_request', 'favourite', 'reblog', 'mention', 'poll', 'status', 'update']
|
||||
|
||||
export const NOTIFICATIONS_FILTERS_ADMIN: {
|
||||
type: 'admin.sign_up' | 'admin.report'
|
||||
permission: number
|
||||
}[] = [
|
||||
{ type: 'admin.sign_up', permission: PERMISSION_MANAGE_USERS },
|
||||
{ type: 'admin.report', permission: PERMISSION_MANAGE_REPORTS }
|
||||
]
|
||||
|
||||
const TabNotificationsFilters: React.FC<
|
||||
TabNotificationsStackScreenProps<'Tab-Notifications-Filters'>
|
||||
> = ({ navigation }) => {
|
||||
const { t } = useTranslation('screenTabs')
|
||||
|
||||
const hasTypeStatus = useSelector(checkInstanceFeature('notification_type_status'))
|
||||
const hasTypeUpdate = useSelector(checkInstanceFeature('notification_type_update'))
|
||||
const pushFeatures = usePushFeatures()
|
||||
|
||||
const dispatch = useAppDispatch()
|
||||
|
||||
@ -103,16 +78,7 @@ const TabNotificationsFilters: React.FC<
|
||||
return (
|
||||
<ScrollView style={{ flex: 1 }}>
|
||||
<MenuContainer>
|
||||
{NOTIFICATIONS_FILTERS_DEFAULT.filter(type => {
|
||||
switch (type) {
|
||||
case 'status':
|
||||
return hasTypeStatus
|
||||
case 'update':
|
||||
return hasTypeUpdate
|
||||
default:
|
||||
return true
|
||||
}
|
||||
}).map((type, index) => (
|
||||
{PUSH_DEFAULT(pushFeatures).map((type, index) => (
|
||||
<MenuRow
|
||||
key={index}
|
||||
title={t(`notifications.filters.options.${type}`)}
|
||||
@ -120,9 +86,7 @@ const TabNotificationsFilters: React.FC<
|
||||
switchOnValueChange={() => setFilters({ ...filters, [type]: !filters[type] })}
|
||||
/>
|
||||
))}
|
||||
{NOTIFICATIONS_FILTERS_ADMIN.filter(({ permission }) =>
|
||||
checkPermission(permission, profileQuery.data?.role?.permissions)
|
||||
).map(({ type }) => (
|
||||
{PUSH_ADMIN(pushFeatures, profileQuery.data?.role?.permissions).map(({ type }) => (
|
||||
<MenuRow
|
||||
key={type}
|
||||
title={t(`notifications.filters.options.${type}`)}
|
||||
|
@ -156,6 +156,7 @@ const instancesMigration = {
|
||||
mention: instance.push.alerts.mention.value,
|
||||
poll: instance.push.alerts.poll.value,
|
||||
status: instance.push.alerts.status.value,
|
||||
update: false,
|
||||
'admin.sign_up': false,
|
||||
'admin.report': false
|
||||
}
|
||||
|
@ -102,6 +102,7 @@ const addInstance = createAsyncThunk(
|
||||
mention: true,
|
||||
poll: true,
|
||||
status: true,
|
||||
update: true,
|
||||
'admin.sign_up': false,
|
||||
'admin.report': false
|
||||
},
|
||||
|
@ -1,3 +1,4 @@
|
||||
import features from '@helpers/features'
|
||||
import {
|
||||
checkPermission,
|
||||
PERMISSION_MANAGE_REPORTS,
|
||||
@ -7,22 +8,59 @@ import queryClient from '@helpers/queryClient'
|
||||
import i18n from '@root/i18n/i18n'
|
||||
import { InstanceLatest } from '@utils/migrations/instances/migration'
|
||||
import { queryFunctionProfile, QueryKeyProfile } from '@utils/queryHooks/profile'
|
||||
import { checkInstanceFeature } from '@utils/slices/instancesSlice'
|
||||
import * as Notifications from 'expo-notifications'
|
||||
import { useSelector } from 'react-redux'
|
||||
|
||||
export const PUSH_DEFAULT: [
|
||||
'follow',
|
||||
'follow_request',
|
||||
'favourite',
|
||||
'reblog',
|
||||
'mention',
|
||||
'poll',
|
||||
'status'
|
||||
] = ['follow', 'follow_request', 'favourite', 'reblog', 'mention', 'poll', 'status']
|
||||
export const usePushFeatures = () => {
|
||||
const hasTypeStatus = useSelector(checkInstanceFeature('notification_type_status'))
|
||||
const hasTypeUpdate = useSelector(checkInstanceFeature('notification_type_update'))
|
||||
const hasTypeAdminSignup = useSelector(checkInstanceFeature('notification_type_admin_signup'))
|
||||
const hasTypeAdminReport = useSelector(checkInstanceFeature('notification_type_admin_report'))
|
||||
return { hasTypeStatus, hasTypeUpdate, hasTypeAdminSignup, hasTypeAdminReport }
|
||||
}
|
||||
|
||||
export const PUSH_ADMIN: { type: 'admin.sign_up' | 'admin.report'; permission: number }[] = [
|
||||
export const PUSH_DEFAULT = ({
|
||||
hasTypeUpdate,
|
||||
hasTypeStatus
|
||||
}: {
|
||||
hasTypeUpdate: boolean
|
||||
hasTypeStatus: boolean
|
||||
}) =>
|
||||
['follow', 'follow_request', 'favourite', 'reblog', 'mention', 'poll', 'update', 'status'].filter(
|
||||
type => {
|
||||
switch (type) {
|
||||
case 'status':
|
||||
return hasTypeStatus
|
||||
case 'update':
|
||||
return hasTypeUpdate
|
||||
default:
|
||||
return true
|
||||
}
|
||||
}
|
||||
) as ['follow', 'follow_request', 'favourite', 'reblog', 'mention', 'poll', 'update', 'status']
|
||||
|
||||
export const PUSH_ADMIN = (
|
||||
{
|
||||
hasTypeAdminSignup,
|
||||
hasTypeAdminReport
|
||||
}: {
|
||||
hasTypeAdminSignup: boolean
|
||||
hasTypeAdminReport: boolean
|
||||
},
|
||||
permissions?: string | number | undefined
|
||||
) =>
|
||||
[
|
||||
{ type: 'admin.sign_up', permission: PERMISSION_MANAGE_USERS },
|
||||
{ type: 'admin.report', permission: PERMISSION_MANAGE_REPORTS }
|
||||
]
|
||||
].filter(({ type, permission }) => {
|
||||
switch (type) {
|
||||
case 'admin.sign_up':
|
||||
return hasTypeAdminSignup && checkPermission(permission, permissions)
|
||||
case 'admin.report':
|
||||
return hasTypeAdminReport && checkPermission(permission, permissions)
|
||||
}
|
||||
}) as { type: 'admin.sign_up' | 'admin.report'; permission: number }[]
|
||||
|
||||
export const setChannels = async (instance: InstanceLatest) => {
|
||||
const account = `@${instance.account.acct}@${instance.uri}`
|
||||
@ -48,23 +86,32 @@ export const setChannels = async (instance: InstanceLatest) => {
|
||||
await Notifications.setNotificationChannelGroupAsync(account, { name: account })
|
||||
}
|
||||
|
||||
const checkFeature = (feature: string) =>
|
||||
features
|
||||
.filter(f => f.feature === feature)
|
||||
.filter(f => parseFloat(instance.version) >= f.version)?.length > 0
|
||||
const checkFeatures = {
|
||||
hasTypeStatus: checkFeature('notification_type_status'),
|
||||
hasTypeUpdate: checkFeature('notification_type_update'),
|
||||
hasTypeAdminSignup: checkFeature('notification_type_admin_signup'),
|
||||
hasTypeAdminReport: checkFeature('notification_type_admin_report')
|
||||
}
|
||||
|
||||
if (!instance.push.decode) {
|
||||
await setChannel('default')
|
||||
for (const push of PUSH_DEFAULT) {
|
||||
for (const push of PUSH_DEFAULT(checkFeatures)) {
|
||||
await deleteChannel(push)
|
||||
}
|
||||
for (const { type } of PUSH_ADMIN) {
|
||||
for (const { type } of PUSH_ADMIN(checkFeatures, profileQuery.role?.permissions)) {
|
||||
await deleteChannel(type)
|
||||
}
|
||||
} else {
|
||||
await deleteChannel('default')
|
||||
for (const push of PUSH_DEFAULT) {
|
||||
for (const push of PUSH_DEFAULT(checkFeatures)) {
|
||||
await setChannel(push)
|
||||
}
|
||||
for (const { type, permission } of PUSH_ADMIN) {
|
||||
if (checkPermission(permission, profileQuery.role?.permissions)) {
|
||||
for (const { type } of PUSH_ADMIN(checkFeatures, profileQuery.role?.permissions)) {
|
||||
await setChannel(type)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user