1
0
mirror of https://github.com/tooot-app/app synced 2025-06-05 22:19:13 +02:00
This commit is contained in:
xmflsct
2022-12-09 21:09:00 +01:00
parent 44f83e44b9
commit 1b58bcad3e
25 changed files with 267 additions and 254 deletions

View File

@ -1,33 +1,11 @@
import queryClient from '@helpers/queryClient'
import { store } from '@root/store'
import { InstanceLatest } from './migrations/instances/migration'
// import { prefetchTimelineQuery } from './queryHooks/timeline'
import { updateInstanceActive } from './slices/instancesSlice'
const initQuery = async ({
instance,
prefetch
}: {
instance: InstanceLatest
prefetch?: { enabled: boolean; page?: 'Following' | 'LocalPublic' }
}) => {
const initQuery = async ({ instance }: { instance: InstanceLatest }) => {
store.dispatch(updateInstanceActive(instance))
await queryClient.resetQueries()
// if (prefetch?.enabled && instance.timelinesLookback) {
// if (
// prefetch.page &&
// instance.timelinesLookback[prefetch.page]?.ids?.length > 0
// ) {
// await prefetchTimelineQuery(instance.timelinesLookback[prefetch.page])
// }
// for (const page of Object.keys(instance.timelinesLookback)) {
// if (page !== prefetch.page) {
// prefetchTimelineQuery(instance.timelinesLookback[page])
// }
// }
// }
}
export default initQuery

View File

@ -6,6 +6,7 @@ import { InstanceV7 } from './v7'
import { InstanceV8 } from './v8'
import { InstanceV9 } from './v9'
import { InstanceV10 } from './v10'
import { InstanceV11 } from './v11'
const instancesMigration = {
4: (state: InstanceV3): InstanceV4 => {
@ -128,9 +129,34 @@ const instancesMigration = {
}
})
}
},
11: (state: { instances: InstanceV10[] }): { instances: InstanceV11[] } => {
return {
instances: state.instances.map(instance => {
return {
...instance,
push: {
...instance.push,
global: instance.push.global.value,
decode: instance.push.decode.value,
alerts: {
follow: instance.push.alerts.follow.value,
follow_request: instance.push.alerts.follow_request.value,
favourite: instance.push.alerts.favourite.value,
reblog: instance.push.alerts.reblog.value,
mention: instance.push.alerts.mention.value,
poll: instance.push.alerts.poll.value,
status: instance.push.alerts.status.value,
'admin.sign_up': false,
'admin.report': false
}
}
}
})
}
}
}
export { InstanceV10 as InstanceLatest }
export { InstanceV11 as InstanceLatest }
export default instancesMigration

View File

@ -0,0 +1,60 @@
import { ComposeStateDraft } from '@screens/Compose/utils/types'
import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
export type InstanceV11 = {
active: boolean
appData: {
clientId: string
clientSecret: string
}
url: string
token: string
uri: Mastodon.Instance['uri']
urls: Mastodon.Instance['urls']
account: {
id: Mastodon.Account['id']
acct: Mastodon.Account['acct']
avatarStatic: Mastodon.Account['avatar_static']
preferences: Mastodon.Preferences
}
version: string
configuration?: Mastodon.Instance['configuration']
filters: Mastodon.Filter[]
notifications_filter: {
follow: boolean
follow_request: boolean
favourite: boolean
reblog: boolean
mention: boolean
poll: boolean
status: boolean
update: boolean
}
push: {
global: boolean
decode: boolean
alerts: Mastodon.PushSubscription['alerts']
keys: {
auth?: string
public?: string // legacy
private?: string // legacy
}
}
timelinesLookback?: {
[key: string]: {
queryKey: QueryKeyTimeline
ids: Mastodon.Status['id'][]
}
}
mePage: {
lists: { shown: boolean }
announcements: { shown: boolean; unread: number }
}
drafts: ComposeStateDraft[]
frequentEmojis: {
emoji: Pick<Mastodon.Emoji, 'shortcode' | 'url' | 'static_url'>
score: number
count: number
lastUsed: number
}[]
}

View File

@ -23,7 +23,7 @@ const pushUseConnect = () => {
const expoToken = useSelector(getExpoToken)
const instances = useSelector(getInstances, (prev, next) => prev.length === next.length)
const pushEnabled = instances.filter(instance => instance.push.global.value)
const pushEnabled = instances.filter(instance => instance.push.global)
const connect = () => {
apiTooot({
@ -60,7 +60,7 @@ const pushUseConnect = () => {
dispatch(disableAllPushes())
instances.forEach(instance => {
if (instance.push.global.value) {
if (instance.push.global) {
apiGeneral<{}>({
method: 'delete',
domain: instance.url,

View File

@ -31,10 +31,7 @@ const pushUseReceive = () => {
description: notification.request.content.body!,
onPress: () => {
if (notificationIndex !== -1) {
initQuery({
instance: instances[notificationIndex],
prefetch: { enabled: true }
})
initQuery({ instance: instances[notificationIndex] })
}
pushUseNavigate(payloadData.notification_id)
}

View File

@ -27,10 +27,7 @@ const pushUseRespond = () => {
instance.account.id === payloadData.accountId
)
if (notificationIndex !== -1) {
initQuery({
instance: instances[notificationIndex],
prefetch: { enabled: true }
})
initQuery({ instance: instances[notificationIndex] })
}
pushUseNavigate(payloadData.notification_id)
}

View File

@ -21,12 +21,12 @@ const queryFunction = async () => {
return res.body
}
const useProfileQuery = ({
options
}: {
options?: UseQueryOptions<AccountWithSource, AxiosError>
}) => {
return useQuery(queryKey, queryFunction, options)
const useProfileQuery = (
params: {
options: UseQueryOptions<AccountWithSource, AxiosError>
} | void
) => {
return useQuery(queryKey, queryFunction, params?.options)
}
type MutationVarsProfileBase =

View File

@ -90,16 +90,18 @@ const addInstance = createAsyncThunk(
update: true
},
push: {
global: { loading: false, value: false },
decode: { loading: false, value: false },
global: false,
decode: false,
alerts: {
follow: { loading: false, value: true },
follow_request: { loading: false, value: true },
favourite: { loading: false, value: true },
reblog: { loading: false, value: true },
mention: { loading: false, value: true },
poll: { loading: false, value: true },
status: { loading: false, value: true }
follow: true,
follow_request: true,
favourite: true,
reblog: true,
mention: true,
poll: true,
status: true,
'admin.sign_up': false,
'admin.report': false
},
keys: { auth: undefined, public: undefined, private: undefined }
},

View File

@ -6,7 +6,6 @@ import { RootState } from '@root/store'
import * as Sentry from '@sentry/react-native'
import { InstanceLatest } from '@utils/migrations/instances/migration'
import { getInstance } from '@utils/slices/instancesSlice'
import { Theme } from '@utils/styles/themes'
import * as Notifications from 'expo-notifications'
import * as Random from 'expo-random'
import i18next from 'i18next'
@ -97,7 +96,7 @@ const pushRegister = async (
accountId,
accountFull,
serverKey: res.body.server_key,
auth: instancePush.decode.value === false ? null : auth
auth: instancePush.decode === false ? null : auth
})
if (Platform.OS === 'android') {
@ -106,7 +105,7 @@ const pushRegister = async (
...androidDefaults
}).then(group => {
if (group) {
if (instancePush.decode.value === false) {
if (instancePush.decode === false) {
Notifications.setNotificationChannelAsync(`${group.id}_default`, {
groupId: group.id,
name: i18n.t('meSettingsPush:content.default.heading'),

View File

@ -6,7 +6,7 @@ import { updateInstancePush } from './updatePush'
const removeInstance = createAsyncThunk(
'instances/remove',
async (instance: InstanceLatest, { dispatch }): Promise<InstanceLatest> => {
if (instance.push.global.value) {
if (instance.push.global) {
dispatch(updateInstancePush(false))
}

View File

@ -13,7 +13,7 @@ export const updateInstancePushDecode = createAsyncThunk(
async (
disable: boolean,
{ getState }
): Promise<{ disable: InstanceLatest['push']['decode']['value'] }> => {
): Promise<{ disable: InstanceLatest['push']['decode'] }> => {
const state = getState() as RootState
const instance = getInstance(state)
if (!instance?.url || !instance.account.id || !instance.push.keys) {
@ -43,14 +43,11 @@ export const updateInstancePushDecode = createAsyncThunk(
name: i18n.t('meSettingsPush:content.follow.heading'),
...androidDefaults
})
Notifications.setNotificationChannelAsync(
`${accountFull}_favourite`,
{
groupId: accountFull,
name: i18n.t('meSettingsPush:content.favourite.heading'),
...androidDefaults
}
)
Notifications.setNotificationChannelAsync(`${accountFull}_favourite`, {
groupId: accountFull,
name: i18n.t('meSettingsPush:content.favourite.heading'),
...androidDefaults
})
Notifications.setNotificationChannelAsync(`${accountFull}_reblog`, {
groupId: accountFull,
name: i18n.t('meSettingsPush:content.reblog.heading'),
@ -74,9 +71,7 @@ export const updateInstancePushDecode = createAsyncThunk(
...androidDefaults
})
Notifications.deleteNotificationChannelAsync(`${accountFull}_follow`)
Notifications.deleteNotificationChannelAsync(
`${accountFull}_favourite`
)
Notifications.deleteNotificationChannelAsync(`${accountFull}_favourite`)
Notifications.deleteNotificationChannelAsync(`${accountFull}_reblog`)
Notifications.deleteNotificationChannelAsync(`${accountFull}_mention`)
Notifications.deleteNotificationChannelAsync(`${accountFull}_poll`)

View File

@ -73,18 +73,11 @@ const instancesSlice = createSlice({
},
clearPushLoading: ({ instances }) => {
const activeIndex = findInstanceActive(instances)
instances[activeIndex].push.global.loading = false
instances[activeIndex].push.decode.loading = false
instances[activeIndex].push.alerts.favourite.loading = false
instances[activeIndex].push.alerts.follow.loading = false
instances[activeIndex].push.alerts.mention.loading = false
instances[activeIndex].push.alerts.poll.loading = false
instances[activeIndex].push.alerts.reblog.loading = false
},
disableAllPushes: ({ instances }) => {
instances = instances.map(instance => {
let newInstance = instance
newInstance.push.global.value = false
newInstance.push.global = false
return newInstance
})
},
@ -238,48 +231,21 @@ const instancesSlice = createSlice({
// Update Instance Push Global
.addCase(updateInstancePush.fulfilled, (state, action) => {
const activeIndex = findInstanceActive(state.instances)
state.instances[activeIndex].push.global.loading = false
state.instances[activeIndex].push.global.value = action.meta.arg
state.instances[activeIndex].push.global = action.meta.arg
state.instances[activeIndex].push.keys = { auth: action.payload }
})
.addCase(updateInstancePush.rejected, state => {
const activeIndex = findInstanceActive(state.instances)
state.instances[activeIndex].push.global.loading = false
})
.addCase(updateInstancePush.pending, state => {
const activeIndex = findInstanceActive(state.instances)
state.instances[activeIndex].push.global.loading = true
})
// Update Instance Push Decode
.addCase(updateInstancePushDecode.fulfilled, (state, action) => {
const activeIndex = findInstanceActive(state.instances)
state.instances[activeIndex].push.decode.loading = false
state.instances[activeIndex].push.decode.value = action.payload.disable
})
.addCase(updateInstancePushDecode.rejected, state => {
const activeIndex = findInstanceActive(state.instances)
state.instances[activeIndex].push.decode.loading = false
})
.addCase(updateInstancePushDecode.pending, state => {
const activeIndex = findInstanceActive(state.instances)
state.instances[activeIndex].push.decode.loading = true
state.instances[activeIndex].push.decode = action.payload.disable
})
// Update Instance Push Individual Alert
.addCase(updateInstancePushAlert.fulfilled, (state, action) => {
const activeIndex = findInstanceActive(state.instances)
state.instances[activeIndex].push.alerts[action.meta.arg.changed].loading = false
state.instances[activeIndex].push.alerts = action.payload
})
.addCase(updateInstancePushAlert.rejected, (state, action) => {
const activeIndex = findInstanceActive(state.instances)
state.instances[activeIndex].push.alerts[action.meta.arg.changed].loading = false
})
.addCase(updateInstancePushAlert.pending, (state, action) => {
const activeIndex = findInstanceActive(state.instances)
state.instances[activeIndex].push.alerts[action.meta.arg.changed].loading = true
})
// Check if frequently used emojis still exist
.addCase(checkEmojis.fulfilled, (state, action) => {
@ -412,7 +378,6 @@ export const {
updateInstanceNotificationsFilter,
updateInstanceDraft,
removeInstanceDraft,
clearPushLoading,
disableAllPushes,
updateInstanceTimelineLookback,
updateInstanceMePage,