2019-04-06 15:08:12 +02:00
|
|
|
import { Module, MutationTree, ActionTree } from 'vuex'
|
2019-04-14 16:11:24 +02:00
|
|
|
import { RootState } from '@/store'
|
2019-04-15 15:37:57 +02:00
|
|
|
import { Notify } from '~/src/types/notify'
|
2019-06-05 16:16:07 +02:00
|
|
|
import { BaseConfig, Notification } from '~/src/types/preference'
|
2019-12-04 14:35:53 +01:00
|
|
|
import { MyWindow } from '~/src/types/global'
|
|
|
|
|
2020-04-11 11:22:49 +02:00
|
|
|
const win = (window as any) as MyWindow
|
2019-04-06 15:08:12 +02:00
|
|
|
|
2019-06-06 16:44:50 +02:00
|
|
|
export type NotificationState = {
|
2019-04-06 15:08:12 +02:00
|
|
|
notification: Notification
|
|
|
|
}
|
|
|
|
|
|
|
|
const state: NotificationState = {
|
|
|
|
notification: {
|
|
|
|
notify: {
|
|
|
|
reply: true,
|
|
|
|
reblog: true,
|
|
|
|
favourite: true,
|
2020-04-25 14:25:28 +02:00
|
|
|
follow: true,
|
2020-05-23 16:21:33 +02:00
|
|
|
follow_request: true,
|
2021-03-02 03:28:03 +01:00
|
|
|
reaction: true,
|
|
|
|
status: true
|
2019-04-06 15:08:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const MUTATION_TYPES = {
|
|
|
|
UPDATE_NOTIFICATION: 'updateNotification'
|
|
|
|
}
|
|
|
|
|
|
|
|
const mutations: MutationTree<NotificationState> = {
|
|
|
|
[MUTATION_TYPES.UPDATE_NOTIFICATION]: (state, notification: Notification) => {
|
|
|
|
state.notification = notification
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-14 16:11:24 +02:00
|
|
|
const actions: ActionTree<NotificationState, RootState> = {
|
2020-11-29 14:31:01 +01:00
|
|
|
loadNotification: async ({ commit }) => {
|
|
|
|
const conf: BaseConfig = await win.ipcRenderer.invoke('get-preferences')
|
|
|
|
commit(MUTATION_TYPES.UPDATE_NOTIFICATION, conf.notification)
|
|
|
|
return conf
|
2019-04-06 15:08:12 +02:00
|
|
|
},
|
2020-11-28 17:47:38 +01:00
|
|
|
updateNotify: async ({ commit, state, dispatch }, notify: object) => {
|
2019-04-06 15:08:12 +02:00
|
|
|
const newNotify: Notify = Object.assign({}, state.notification.notify, notify)
|
|
|
|
const newNotification: Notification = Object.assign({}, state.notification, {
|
|
|
|
notify: newNotify
|
|
|
|
})
|
|
|
|
const config = {
|
|
|
|
notification: newNotification
|
|
|
|
}
|
2020-11-28 17:47:38 +01:00
|
|
|
const conf: BaseConfig = await win.ipcRenderer.invoke('update-preferences', config)
|
|
|
|
commit(MUTATION_TYPES.UPDATE_NOTIFICATION, conf.notification)
|
|
|
|
dispatch('App/loadPreferences', null, { root: true })
|
2019-04-06 15:08:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
namespaced: true,
|
|
|
|
state: state,
|
|
|
|
mutations: mutations,
|
|
|
|
actions: actions
|
2019-04-14 16:11:24 +02:00
|
|
|
} as Module<NotificationState, RootState>
|