mirror of
https://github.com/tooot-app/app
synced 2025-06-05 22:19:13 +02:00
Added notifications filter
This commit is contained in:
53
src/utils/migrations/instances/migration.ts
Normal file
53
src/utils/migrations/instances/migration.ts
Normal file
@ -0,0 +1,53 @@
|
||||
import { InstanceV3 } from './v3'
|
||||
import { InstanceV4 } from './v4'
|
||||
|
||||
const instancesMigration = {
|
||||
4: (state: InstanceV3) => {
|
||||
return {
|
||||
instances: state.local.instances.map((instance, index) => {
|
||||
// @ts-ignore
|
||||
delete instance.notification
|
||||
return {
|
||||
...instance,
|
||||
active: state.local.activeIndex === index,
|
||||
push: {
|
||||
global: { loading: false, value: false },
|
||||
decode: { loading: false, value: false },
|
||||
alerts: {
|
||||
follow: { loading: false, value: true },
|
||||
favourite: { loading: false, value: true },
|
||||
reblog: { loading: false, value: true },
|
||||
mention: { loading: false, value: true },
|
||||
poll: { loading: false, value: true }
|
||||
},
|
||||
keys: undefined
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
5: (state: InstanceV4) => {
|
||||
// Migration is run on each start, don't know why
|
||||
// @ts-ignore
|
||||
if (state.instances.length && !state.instances[0].notifications_filter) {
|
||||
return {
|
||||
instances: state.instances.map(instance => {
|
||||
// @ts-ignore
|
||||
instance.notifications_filter = {
|
||||
follow: true,
|
||||
favourite: true,
|
||||
reblog: true,
|
||||
mention: true,
|
||||
poll: true,
|
||||
follow_request: true
|
||||
}
|
||||
return instance
|
||||
})
|
||||
}
|
||||
} else {
|
||||
return state
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default instancesMigration
|
@ -21,7 +21,7 @@ type InstanceLocal = {
|
||||
drafts: any[]
|
||||
}
|
||||
|
||||
export type InstancesV3 = {
|
||||
export type InstanceV3 = {
|
||||
local: {
|
||||
activeIndex: number | null
|
||||
instances: InstanceLocal[]
|
||||
|
84
src/utils/migrations/instances/v4.ts
Normal file
84
src/utils/migrations/instances/v4.ts
Normal file
@ -0,0 +1,84 @@
|
||||
import { ComposeStateDraft } from "@screens/Compose/utils/types"
|
||||
|
||||
type Instance = {
|
||||
active: boolean
|
||||
appData: {
|
||||
clientId: string
|
||||
clientSecret: string
|
||||
}
|
||||
url: string
|
||||
token: string
|
||||
uri: Mastodon.Instance['uri']
|
||||
urls: Mastodon.Instance['urls']
|
||||
max_toot_chars: number
|
||||
account: {
|
||||
id: Mastodon.Account['id']
|
||||
acct: Mastodon.Account['acct']
|
||||
avatarStatic: Mastodon.Account['avatar_static']
|
||||
preferences: Mastodon.Preferences
|
||||
}
|
||||
push:
|
||||
| {
|
||||
global: { loading: boolean; value: boolean }
|
||||
decode: { loading: boolean; value: true }
|
||||
alerts: {
|
||||
follow: {
|
||||
loading: boolean
|
||||
value: Mastodon.PushSubscription['alerts']['follow']
|
||||
}
|
||||
favourite: {
|
||||
loading: boolean
|
||||
value: Mastodon.PushSubscription['alerts']['favourite']
|
||||
}
|
||||
reblog: {
|
||||
loading: boolean
|
||||
value: Mastodon.PushSubscription['alerts']['reblog']
|
||||
}
|
||||
mention: {
|
||||
loading: boolean
|
||||
value: Mastodon.PushSubscription['alerts']['mention']
|
||||
}
|
||||
poll: {
|
||||
loading: boolean
|
||||
value: Mastodon.PushSubscription['alerts']['poll']
|
||||
}
|
||||
}
|
||||
keys: {
|
||||
auth: string
|
||||
public: string
|
||||
private: string
|
||||
}
|
||||
}
|
||||
| {
|
||||
global: { loading: boolean; value: boolean }
|
||||
decode: { loading: boolean; value: false }
|
||||
alerts: {
|
||||
follow: {
|
||||
loading: boolean
|
||||
value: Mastodon.PushSubscription['alerts']['follow']
|
||||
}
|
||||
favourite: {
|
||||
loading: boolean
|
||||
value: Mastodon.PushSubscription['alerts']['favourite']
|
||||
}
|
||||
reblog: {
|
||||
loading: boolean
|
||||
value: Mastodon.PushSubscription['alerts']['reblog']
|
||||
}
|
||||
mention: {
|
||||
loading: boolean
|
||||
value: Mastodon.PushSubscription['alerts']['mention']
|
||||
}
|
||||
poll: {
|
||||
loading: boolean
|
||||
value: Mastodon.PushSubscription['alerts']['poll']
|
||||
}
|
||||
}
|
||||
keys: undefined
|
||||
}
|
||||
drafts: ComposeStateDraft[]
|
||||
}
|
||||
|
||||
export type InstanceV4 = {
|
||||
instances: Instance[]
|
||||
}
|
@ -1,5 +1,10 @@
|
||||
import apiInstance from '@api/instance'
|
||||
import haptics from '@components/haptics'
|
||||
import { store } from '@root/store'
|
||||
import {
|
||||
getInstanceActive,
|
||||
getInstanceNotificationsFilter
|
||||
} from '@utils/slices/instancesSlice'
|
||||
import { AxiosError } from 'axios'
|
||||
import { uniqBy } from 'lodash'
|
||||
import {
|
||||
@ -59,10 +64,19 @@ const queryFunction = ({
|
||||
})
|
||||
|
||||
case 'Notifications':
|
||||
const rootStore = store.getState()
|
||||
const notificationsFilter = getInstanceNotificationsFilter(rootStore)
|
||||
return apiInstance<Mastodon.Notification[]>({
|
||||
method: 'get',
|
||||
url: 'notifications',
|
||||
params
|
||||
params: {
|
||||
...params,
|
||||
...(notificationsFilter && {
|
||||
exclude_types: Object.keys(notificationsFilter)
|
||||
// @ts-ignore
|
||||
.filter(filter => notificationsFilter[filter] === false)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
case 'Account_Default':
|
||||
|
@ -70,6 +70,14 @@ const addInstance = createAsyncThunk(
|
||||
avatarStatic: avatar_static,
|
||||
preferences
|
||||
},
|
||||
notifications_filter: {
|
||||
follow: true,
|
||||
favourite: true,
|
||||
reblog: true,
|
||||
mention: true,
|
||||
poll: true,
|
||||
follow_request: true
|
||||
},
|
||||
push: {
|
||||
global: { loading: false, value: false },
|
||||
decode: { loading: false, value: false },
|
||||
|
@ -29,6 +29,14 @@ export type Instance = {
|
||||
avatarStatic: Mastodon.Account['avatar_static']
|
||||
preferences: Mastodon.Preferences
|
||||
}
|
||||
notifications_filter: {
|
||||
follow: boolean
|
||||
favourite: boolean
|
||||
reblog: boolean
|
||||
mention: boolean
|
||||
poll: boolean
|
||||
follow_request: boolean
|
||||
}
|
||||
push:
|
||||
| {
|
||||
global: { loading: boolean; value: boolean }
|
||||
@ -55,13 +63,11 @@ export type Instance = {
|
||||
value: Mastodon.PushSubscription['alerts']['poll']
|
||||
}
|
||||
}
|
||||
keys:
|
||||
| {
|
||||
auth: string
|
||||
public: string
|
||||
private: string
|
||||
}
|
||||
| undefined
|
||||
keys: {
|
||||
auth: string
|
||||
public: string
|
||||
private: string
|
||||
}
|
||||
}
|
||||
| {
|
||||
global: { loading: boolean; value: boolean }
|
||||
@ -127,6 +133,13 @@ const instancesSlice = createSlice({
|
||||
...action.payload
|
||||
}
|
||||
},
|
||||
updateInstanceNotificationsFilter: (
|
||||
{ instances },
|
||||
action: PayloadAction<Instance['notifications_filter']>
|
||||
) => {
|
||||
const activeIndex = findInstanceActive(instances)
|
||||
instances[activeIndex].notifications_filter = action.payload
|
||||
},
|
||||
updateInstanceDraft: (
|
||||
{ instances },
|
||||
action: PayloadAction<ComposeStateDraft>
|
||||
@ -314,6 +327,15 @@ export const getInstanceAccount = ({ instances: { instances } }: RootState) => {
|
||||
return instanceActive !== -1 ? instances[instanceActive].account : null
|
||||
}
|
||||
|
||||
export const getInstanceNotificationsFilter = ({
|
||||
instances: { instances }
|
||||
}: RootState) => {
|
||||
const instanceActive = findInstanceActive(instances)
|
||||
return instanceActive !== -1
|
||||
? instances[instanceActive].notifications_filter
|
||||
: null
|
||||
}
|
||||
|
||||
export const getInstancePush = ({ instances: { instances } }: RootState) => {
|
||||
const instanceActive = findInstanceActive(instances)
|
||||
return instanceActive !== -1 ? instances[instanceActive].push : null
|
||||
@ -327,6 +349,7 @@ export const getInstanceDrafts = ({ instances: { instances } }: RootState) => {
|
||||
export const {
|
||||
updateInstanceActive,
|
||||
updateInstanceAccount,
|
||||
updateInstanceNotificationsFilter,
|
||||
updateInstanceDraft,
|
||||
removeInstanceDraft,
|
||||
disableAllPushes
|
||||
|
Reference in New Issue
Block a user