2019-04-04 16:52:08 +02:00
|
|
|
import unreadSettings from '~/src/constants/unreadNotification'
|
|
|
|
import { Module, MutationTree, ActionTree } from 'vuex'
|
2019-04-14 16:11:24 +02:00
|
|
|
import { RootState } from '@/store'
|
2019-04-15 15:24:02 +02:00
|
|
|
import { UnreadNotification } from '~/src/types/unreadNotification'
|
2019-12-04 14:48:55 +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-04 16:52:08 +02:00
|
|
|
|
2019-06-06 16:44:50 +02:00
|
|
|
export type TimelineState = {
|
2019-04-04 16:52:08 +02:00
|
|
|
unreadNotification: UnreadNotification
|
|
|
|
}
|
|
|
|
|
|
|
|
const state = (): TimelineState => ({
|
|
|
|
unreadNotification: {
|
|
|
|
direct: unreadSettings.Direct.default,
|
|
|
|
local: unreadSettings.Local.default,
|
|
|
|
public: unreadSettings.Public.default
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
export const MUTATION_TYPES = {
|
|
|
|
UPDATE_UNREAD_NOTIFICATION: 'updateUnreadNotification'
|
|
|
|
}
|
|
|
|
|
|
|
|
const mutations: MutationTree<TimelineState> = {
|
|
|
|
[MUTATION_TYPES.UPDATE_UNREAD_NOTIFICATION]: (state, settings: UnreadNotification) => {
|
|
|
|
state.unreadNotification = settings
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-14 16:11:24 +02:00
|
|
|
const actions: ActionTree<TimelineState, RootState> = {
|
2020-11-29 15:34:31 +01:00
|
|
|
loadUnreadNotification: async ({ commit, rootState }): Promise<boolean> => {
|
|
|
|
try {
|
|
|
|
const settings: UnreadNotification = await win.ipcRenderer.invoke('get-unread-notification', rootState.Settings.accountID)
|
|
|
|
commit(MUTATION_TYPES.UPDATE_UNREAD_NOTIFICATION, settings)
|
|
|
|
return true
|
|
|
|
} catch (err) {
|
|
|
|
const settings: UnreadNotification = {
|
|
|
|
direct: unreadSettings.Direct.default,
|
|
|
|
local: unreadSettings.Local.default,
|
|
|
|
public: unreadSettings.Public.default
|
|
|
|
}
|
|
|
|
commit(MUTATION_TYPES.UPDATE_UNREAD_NOTIFICATION, settings)
|
|
|
|
return false
|
|
|
|
}
|
2019-04-04 16:52:08 +02:00
|
|
|
},
|
2020-11-29 15:36:36 +01:00
|
|
|
changeUnreadNotification: async ({ dispatch, state, rootState }, timeline: { key: boolean }): Promise<boolean> => {
|
2019-04-16 16:50:53 +02:00
|
|
|
const settings: UnreadNotification = Object.assign({}, state.unreadNotification, timeline, {
|
2019-04-04 16:52:08 +02:00
|
|
|
accountID: rootState.Settings.accountID
|
|
|
|
})
|
2020-11-29 15:36:36 +01:00
|
|
|
await win.ipcRenderer.invoke('update-unread-notification', settings)
|
|
|
|
dispatch('loadUnreadNotification')
|
|
|
|
return true
|
2019-04-04 16:52:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-14 16:11:24 +02:00
|
|
|
const Timeline: Module<TimelineState, RootState> = {
|
2019-04-04 16:52:08 +02:00
|
|
|
namespaced: true,
|
|
|
|
state: state,
|
|
|
|
mutations: mutations,
|
|
|
|
actions: actions
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Timeline
|