[refactor] SideMenu store

This commit is contained in:
AkiraFukushima 2023-01-02 11:18:46 +09:00
parent f79282d83e
commit 797b00d309
No known key found for this signature in database
GPG Key ID: B6E51BAC4DE1A957
11 changed files with 100 additions and 483 deletions

View File

@ -42,8 +42,6 @@ const state = (): JumpState => {
path: 'direct-messages'
}
],
listChannelList: [],
tagChannelList: [],
selectedChannel: {
name: i18n.t('side_menu.home'),
path: 'home'

View File

@ -1,154 +0,0 @@
import { Entity, Response } from 'megalodon'
import { createStore, Store } from 'vuex'
import { ipcMain, ipcRenderer } from '~/spec/mock/electron'
import SideMenu, { SideMenuState } from '~/src/renderer/store/TimelineSpace/SideMenu'
import { MyWindow } from '~/src/types/global'
import { RootState } from '@/store'
;((window as any) as MyWindow).ipcRenderer = ipcRenderer
const mockClient = {
getLists: () => {
return new Promise<Response<Entity.List[]>>(resolve => {
const res: Response<Entity.List[]> = {
data: [list1, list2],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
jest.mock('megalodon', () => ({
...jest.requireActual<object>('megalodon'),
default: jest.fn(() => mockClient),
__esModule: true
}))
// import mockedMegalodon from '~/spec/mock/megalodon'
const list1: Entity.List = {
id: '1',
title: 'example1'
}
const list2: Entity.List = {
id: '2',
title: 'example2'
}
const state = (): SideMenuState => {
return {
unreadHomeTimeline: false,
unreadNotifications: false,
unreadMentions: false,
unreadLocalTimeline: false,
unreadDirectMessagesTimeline: false,
unreadPublicTimeline: false,
unreadFollowRequests: false,
lists: [],
tags: [],
collapse: false,
enabledTimelines: {
home: true,
notification: true,
mention: true,
direct: true,
favourite: true,
bookmark: true,
local: true,
public: true,
tag: true,
list: true
}
}
}
const initStore = () => {
return {
namespaced: true,
state: state(),
actions: SideMenu.actions,
mutations: SideMenu.mutations
}
}
const appStore = {
namespaced: true,
state: {
proxyConfiguration: false
}
}
const timelineStore = () => ({
namespaced: true,
state: {
account: {
id: 0,
accessToken: 'token'
},
server: {
sns: 'mastodon',
baseURL: 'http://localhost'
}
},
modules: {
SideMenu: initStore()
}
})
describe('SideMenu', () => {
let store: Store<RootState>
beforeEach(() => {
store = createStore({
modules: {
App: appStore,
TimelineSpace: timelineStore()
}
})
// mockedMegalodon.mockClear()
})
describe('fetchLists', () => {
it('should be updated', async () => {
// mockedMegalodon.mockImplementation(() => mockClient)
const account = {
accessToken: 'token',
baseURL: 'http://localhost'
}
const lists = await store.dispatch('TimelineSpace/SideMenu/fetchLists', account)
expect(store.state.TimelineSpace.SideMenu.lists).toEqual([list1, list2])
expect(lists).toEqual([list1, list2])
})
})
describe('clearUnread', () => {
it('should be reset', () => {
store.dispatch('TimelineSpace/SideMenu/clearUnread')
expect(store.state.TimelineSpace.SideMenu.unreadHomeTimeline).toEqual(false)
expect(store.state.TimelineSpace.SideMenu.unreadNotifications).toEqual(false)
expect(store.state.TimelineSpace.SideMenu.unreadLocalTimeline).toEqual(false)
expect(store.state.TimelineSpace.SideMenu.unreadDirectMessagesTimeline).toEqual(false)
expect(store.state.TimelineSpace.SideMenu.unreadPublicTimeline).toEqual(false)
})
})
describe('changeCollapse', () => {
it('should be changed', () => {
store.dispatch('TimelineSpace/SideMenu/changeCollapse', true)
expect(store.state.TimelineSpace.SideMenu.collapse).toEqual(true)
})
})
describe('readCollapse', () => {
it('should be read', async () => {
ipcMain.handle('get-collapse', () => {
return true
})
await store.dispatch('TimelineSpace/SideMenu/readCollapse')
expect(store.state.TimelineSpace.SideMenu.collapse).toEqual(true)
})
})
})

View File

@ -1,114 +0,0 @@
import i18n from '~/src/config/i18n'
import Jump, { JumpState, MUTATION_TYPES, Channel } from '@/store/TimelineSpace/Modals/Jump'
import { LocalTag } from '~/src/types/localTag'
import { Entity } from 'megalodon'
describe('TimelineSpace/Modals/Jump', () => {
describe('mutations', () => {
let state: JumpState
beforeEach(() => {
state = {
modalOpen: true,
channel: '',
defaultChannelList: [
{
name: i18n.t('side_menu.home'),
path: 'home'
},
{
name: i18n.t('side_menu.notification'),
path: 'notifications'
},
{
name: i18n.t('side_menu.favourite'),
path: 'favourites'
},
{
name: i18n.t('side_menu.local'),
path: 'local'
},
{
name: i18n.t('side_menu.public'),
path: 'public'
},
{
name: i18n.t('side_menu.hashtag'),
path: 'hashtag'
},
{
name: i18n.t('side_menu.search'),
path: 'search'
},
{
name: i18n.t('side_menu.direct'),
path: 'direct-messages'
}
],
listChannelList: [],
tagChannelList: [],
selectedChannel: {
name: i18n.t('side_menu.home'),
path: 'home'
}
}
})
describe('updateListChannel', () => {
it('should be updated', () => {
const admin: Entity.List = {
id: '0',
title: 'admin'
}
const engineer: Entity.List = {
id: '1',
title: 'engineer'
}
const designer: Entity.List = {
id: '2',
title: 'designer'
}
const channelList = [admin, engineer, designer]
Jump.mutations![MUTATION_TYPES.UPDATE_LIST_CHANNEL](state, channelList)
const adminChannel: Channel = {
path: 'lists/0',
name: '#admin'
}
const engineerChannel: Channel = {
path: 'lists/1',
name: '#engineer'
}
const designerChannel: Channel = {
path: 'lists/2',
name: '#designer'
}
expect(state.listChannelList).toEqual([adminChannel, engineerChannel, designerChannel])
})
})
describe('updateTagChannel', () => {
it('should be updated', () => {
const whalebird: LocalTag = {
tagName: 'whalebird',
id: 0,
accountId: 1
}
const tqrk: LocalTag = {
tagName: 'tqrk',
id: 0,
accountId: 1
}
const channelList = [whalebird, tqrk]
Jump.mutations![MUTATION_TYPES.UPDATE_TAG_CHANNEL](state, channelList)
const whalebirdChannel: Channel = {
name: '#whalebird',
path: 'hashtag/whalebird'
}
const tqrkChannel: Channel = {
name: '#tqrk',
path: 'hashtag/tqrk'
}
expect(state.tagChannelList).toEqual([whalebirdChannel, tqrkChannel])
})
})
})
})

View File

@ -37,11 +37,7 @@ export default defineComponent({
const channelForm = ref<HTMLInputElement>()
const channelList = computed(() =>
store.state.TimelineSpace.Modals.Jump.defaultChannelList
.concat(store.state.TimelineSpace.Modals.Jump.tagChannelList)
.concat(store.state.TimelineSpace.Modals.Jump.listChannelList)
)
const channelList = computed(() => store.state.TimelineSpace.Modals.Jump.defaultChannelList)
const selectedChannel = computed(() => store.state.TimelineSpace.Modals.Jump.selectedChannel)
const inputtedChannel = computed({
get: () => store.state.TimelineSpace.Modals.Jump.channel,
@ -57,8 +53,6 @@ export default defineComponent({
)
onMounted(() => {
store.dispatch(`${space}/${ACTION_TYPES.SYNC_LIST_CHANNEL}`)
store.dispatch(`${space}/${ACTION_TYPES.SYNC_TAG_CHANNEL}`)
nextTick(() => {
setTimeout(() => {
channelForm.value?.focus()

View File

@ -4,11 +4,11 @@
<div :class="collapse ? 'profile-narrow' : 'profile-wide'">
<div class="account">
<div class="avatar" v-if="collapse">
<img :src="account?.avatar" />
<img :src="account.account?.avatar" />
</div>
<div class="acct" v-else>
@{{ account?.username }}
<span class="domain-name">{{ server?.domain }}</span>
@{{ account.account?.username }}
<span class="domain-name">{{ account.server?.domain }}</span>
</div>
<el-dropdown trigger="click" @command="handleProfile" :title="$t('side_menu.profile')">
<span class="el-dropdown-link">
@ -263,13 +263,18 @@
</template>
<script lang="ts">
import { defineComponent, computed, onMounted } from 'vue'
import { defineComponent, computed, onMounted, ref, reactive } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { useStore } from '@/store'
import { ACTION_TYPES } from '@/store/TimelineSpace/SideMenu'
import { ACTION_TYPES as PROFILE_ACTION } from '@/store/TimelineSpace/Contents/SideBar/AccountProfile'
import { ACTION_TYPES as SIDEBAR_ACTION, MUTATION_TYPES as SIDEBAR_MUTATION } from '@/store/TimelineSpace/Contents/SideBar'
import { ACTION_TYPES as GLOBAL_ACTION } from '@/store/GlobalHeader'
import { MyWindow } from '~/src/types/global'
import generator, { Entity, MegalodonInterface } from 'megalodon'
import { LocalAccount } from '~/src/types/localAccount'
import { LocalServer } from '~/src/types/localServer'
import { LocalTag } from '~/src/types/localTag'
export default defineComponent({
name: 'side-menu',
@ -279,6 +284,27 @@ export default defineComponent({
const route = useRoute()
const router = useRouter()
const win = (window as any) as MyWindow
const lists = ref<Array<Entity.List>>([])
const tags = ref<Array<LocalTag>>([])
const enabledTimelines = reactive({
home: true,
notification: true,
mention: true,
direct: true,
favourite: true,
bookmark: true,
local: true,
public: true,
tag: true,
list: true
})
const account = reactive<{ account: LocalAccount | null; server: LocalServer | null }>({
account: null,
server: null
})
const unreadHomeTimeline = computed(() => store.state.TimelineSpace.SideMenu.unreadHomeTimeline)
const unreadNotifications = computed(() => store.state.TimelineSpace.SideMenu.unreadNotifications)
const unreadMentions = computed(() => store.state.TimelineSpace.SideMenu.unreadMentions)
@ -286,27 +312,77 @@ export default defineComponent({
const unreadDirectMessagesTimeline = computed(() => store.state.TimelineSpace.SideMenu.unreadDirectMessagesTimeline)
const unreadPublicTimeline = computed(() => store.state.TimelineSpace.SideMenu.unreadPublicTimeline)
const unreadFollowRequests = computed(() => store.state.TimelineSpace.SideMenu.unreadFollowRequests)
const lists = computed(() => store.state.TimelineSpace.SideMenu.lists)
const tags = computed(() => store.state.TimelineSpace.SideMenu.tags)
const collapse = computed(() => store.state.TimelineSpace.SideMenu.collapse)
const enabledTimelines = computed(() => store.state.TimelineSpace.SideMenu.enabledTimelines)
const account = computed(() => store.state.TimelineSpace.account)
const server = computed(() => store.state.TimelineSpace.server)
const themeColor = computed(() => store.state.App.theme.side_menu_color)
const hideGlobalHeader = computed(() => store.state.GlobalHeader.hide)
const userAgent = computed(() => store.state.App.userAgent)
const activeRoute = computed(() => route.path)
const id = computed(() => route.params.id)
const id = computed(() => parseInt(route.params.id as string))
onMounted(() => {
onMounted(async () => {
store.dispatch(`${space}/${ACTION_TYPES.READ_COLLAPSE}`)
store.dispatch(`${space}/${ACTION_TYPES.LIST_TAGS}`, parseInt(id.value as string))
const [a, s]: [LocalAccount, LocalServer] = await win.ipcRenderer.invoke('get-local-account', id.value)
account.account = a
account.server = s
const client = generator(s.sns, s.baseURL, a.accessToken, userAgent.value)
await fetchLists(client)
await fetchTags(a)
await confirmTimelines(client)
})
const fetchLists = async (client: MegalodonInterface) => {
const res = await client.getLists()
lists.value = res.data
}
const fetchTags = async (account: LocalAccount) => {
tags.value = await win.ipcRenderer.invoke('list-hashtags', account.id)
}
const confirmTimelines = async (client: MegalodonInterface) => {
const notification = async () => {
return client.getNotifications({ limit: 1 }).catch(() => {
enabledTimelines.notification = false
enabledTimelines.mention = false
})
}
const direct = async () => {
return client.getConversationTimeline({ limit: 1 }).catch(() => {
enabledTimelines.direct = false
})
}
const favourite = async () => {
return client.getFavourites({ limit: 1 }).catch(() => {
enabledTimelines.favourite = false
})
}
const bookmark = async () => {
return client.getBookmarks({ limit: 1 }).catch(() => {
enabledTimelines.bookmark = false
})
}
const local = async () => {
return client.getLocalTimeline({ limit: 1 }).catch(() => {
enabledTimelines.local = false
})
}
const pub = async () => {
return client.getPublicTimeline({ limit: 1 }).catch(() => {
enabledTimelines.public = false
})
}
await Promise.all([notification(), direct(), favourite(), bookmark(), local(), pub()])
}
const handleProfile = (command: string) => {
switch (command) {
case 'show':
if (!account.account) {
return
}
store
.dispatch(`TimelineSpace/Contents/SideBar/AccountProfile/${PROFILE_ACTION.FETCH_ACCOUNT}`, account.value!.accountId)
.dispatch(`TimelineSpace/Contents/SideBar/AccountProfile/${PROFILE_ACTION.FETCH_ACCOUNT}`, account.account.accountId)
.then(account => {
store.dispatch(`TimelineSpace/Contents/SideBar/AccountProfile/${PROFILE_ACTION.CHANGE_ACCOUNT}`, account)
store.commit(`TimelineSpace/Contents/SideBar/${SIDEBAR_MUTATION.CHANGE_OPEN_SIDEBAR}`, true)
@ -315,7 +391,9 @@ export default defineComponent({
store.dispatch(`TimelineSpace/Contents/SideBar/${SIDEBAR_ACTION.OPEN_ACCOUNT_COMPONENT}`)
break
case 'edit':
;(window as any).shell.openExternal(server.value!.baseURL + '/settings/profile')
if (account.server) {
;(window as any).shell.openExternal(account.server.baseURL + '/settings/profile')
}
break
case 'settings': {
const url = `/${id.value}/settings`
@ -347,7 +425,6 @@ export default defineComponent({
collapse,
enabledTimelines,
account,
server,
themeColor,
hideGlobalHeader,
activeRoute,

View File

@ -137,7 +137,6 @@
{{ favouritesCount }}
</div>
<el-button
v-if="bookmarkSupported"
:class="originalMessage.bookmarked ? 'bookmarked' : 'bookmark'"
link
:title="$t('cards.toot.bookmark')"
@ -322,7 +321,6 @@ export default defineComponent({
const language = computed(() => store.state.App.language)
const server = computed(() => store.state.TimelineSpace.server)
const account = computed(() => store.state.TimelineSpace.account)
const bookmarkSupported = computed(() => store.state.TimelineSpace.SideMenu.enabledTimelines.bookmark)
const shortcutEnabled = computed(() => focused.value && !overlaid.value)
const originalMessage = computed(() => {
if (message.value.reblog && !message.value.quote) {
@ -679,7 +677,6 @@ export default defineComponent({
language,
server,
account,
bookmarkSupported,
originalMessage,
timestamp,
readableTimestamp,

View File

@ -104,9 +104,6 @@ const actions: ActionTree<TimelineSpaceState, RootState> = {
throw new AccountLoadError()
})
dispatch('TimelineSpace/SideMenu/fetchLists', null, { root: true })
dispatch('TimelineSpace/SideMenu/fetchFollowRequests', null, { root: true })
dispatch('TimelineSpace/SideMenu/confirmTimelines', null, { root: true })
await dispatch(ACTION_TYPES.LOAD_SETTING)
await dispatch(ACTION_TYPES.FETCH_FILTERS)
commit(MUTATION_TYPES.CHANGE_LOADING, false)

View File

@ -85,7 +85,7 @@ export const ACTION_TYPES = {
}
const actions: ActionTree<DirectMessagesState, RootState> = {
[ACTION_TYPES.FETCH_TIMELINE]: async ({ dispatch, commit, rootState }): Promise<Array<Entity.Status>> => {
[ACTION_TYPES.FETCH_TIMELINE]: async ({ commit, rootState }): Promise<Array<Entity.Status>> => {
const client = generator(
rootState.TimelineSpace.server!.sns,
rootState.TimelineSpace.server!.baseURL,
@ -98,8 +98,6 @@ const actions: ActionTree<DirectMessagesState, RootState> = {
commit(MUTATION_TYPES.UPDATE_TIMELINE, statuses)
return statuses
} catch (err) {
// Disable direct timeline
dispatch('TimelineSpace/SideMenu/disableDirect', {}, { root: true })
return []
}
},

View File

@ -96,7 +96,7 @@ export const ACTION_TYPES = {
}
const actions: ActionTree<LocalState, RootState> = {
[ACTION_TYPES.FETCH_LOCAL_TIMELINE]: async ({ dispatch, commit, rootState }): Promise<Array<Entity.Status>> => {
[ACTION_TYPES.FETCH_LOCAL_TIMELINE]: async ({ commit, rootState }): Promise<Array<Entity.Status>> => {
const client = generator(
rootState.TimelineSpace.server!.sns,
rootState.TimelineSpace.server!.baseURL,
@ -109,8 +109,6 @@ const actions: ActionTree<LocalState, RootState> = {
commit(MUTATION_TYPES.UPDATE_TIMELINE, res.data)
return res.data
} catch (err) {
// Disable local timeline
dispatch('TimelineSpace/SideMenu/disableLocal', {}, { root: true })
return []
}
},

View File

@ -1,8 +1,6 @@
import router from '@/router'
import i18n from '~/src/config/i18n'
import { Module, MutationTree, ActionTree } from 'vuex'
import { Entity } from 'megalodon'
import { LocalTag } from '~/src/types/localTag'
import { RootState } from '@/store'
export type Channel = {
@ -14,8 +12,6 @@ export type JumpState = {
modalOpen: boolean
channel: string
defaultChannelList: Array<Channel>
listChannelList: Array<Channel>
tagChannelList: Array<Channel>
selectedChannel: Channel
}
@ -60,8 +56,6 @@ const state = (): JumpState => ({
path: 'direct-messages'
}
],
listChannelList: [],
tagChannelList: [],
selectedChannel: {
name: i18n.t('side_menu.home'),
path: 'home'
@ -71,9 +65,7 @@ const state = (): JumpState => ({
export const MUTATION_TYPES = {
CHANGE_MODAL: 'changeModal',
UPDATE_CHANNEL: 'updateChannel',
CHANGE_SELECTED: 'changeSelected',
UPDATE_LIST_CHANNEL: 'updateListChannel',
UPDATE_TAG_CHANNEL: 'updateTagChannel'
CHANGE_SELECTED: 'changeSelected'
}
const mutations: MutationTree<JumpState> = {
@ -85,32 +77,12 @@ const mutations: MutationTree<JumpState> = {
},
[MUTATION_TYPES.CHANGE_SELECTED]: (state, channel: Channel) => {
state.selectedChannel = channel
},
[MUTATION_TYPES.UPDATE_LIST_CHANNEL]: (state, lists: Array<Entity.List>) => {
state.listChannelList = lists.map(l => {
const channel: Channel = {
name: `#${l.title}`,
path: `lists/${l.id}`
}
return channel
})
},
[MUTATION_TYPES.UPDATE_TAG_CHANNEL]: (state, tags: Array<LocalTag>) => {
state.tagChannelList = tags.map(t => {
const channel: Channel = {
name: `#${t.tagName}`,
path: `hashtag/${t.tagName}`
}
return channel
})
}
}
export const ACTION_TYPES = {
JUMP_CURRENT_SELECTED: 'jumpCurrentSelected',
JUMP: 'jump',
SYNC_LIST_CHANNEL: 'syncListChannel',
SYNC_TAG_CHANNEL: 'syncTagChannel'
JUMP: 'jump'
}
const actions: ActionTree<JumpState, RootState> = {
@ -121,12 +93,6 @@ const actions: ActionTree<JumpState, RootState> = {
[ACTION_TYPES.JUMP]: ({ commit, rootState }, channel: Channel) => {
commit(MUTATION_TYPES.CHANGE_MODAL, false)
router.push({ path: `/${rootState.TimelineSpace.account!.id}/${channel.path}` })
},
[ACTION_TYPES.SYNC_LIST_CHANNEL]: ({ commit, rootState }) => {
commit(MUTATION_TYPES.UPDATE_LIST_CHANNEL, rootState.TimelineSpace.SideMenu.lists)
},
[ACTION_TYPES.SYNC_TAG_CHANNEL]: ({ commit, rootState }) => {
commit(MUTATION_TYPES.UPDATE_TAG_CHANNEL, rootState.TimelineSpace.SideMenu.tags)
}
}

View File

@ -1,9 +1,6 @@
import generator, { Entity } from 'megalodon'
import { Module, MutationTree, ActionTree } from 'vuex'
import { LocalTag } from '~/src/types/localTag'
import { RootState } from '@/store'
import { MyWindow } from '~/src/types/global'
import { EnabledTimelines } from '~/src/types/enabledTimelines'
const win = (window as any) as MyWindow
@ -15,10 +12,7 @@ export type SideMenuState = {
unreadDirectMessagesTimeline: boolean
unreadPublicTimeline: boolean
unreadFollowRequests: boolean
lists: Array<Entity.List>
tags: Array<LocalTag>
collapse: boolean
enabledTimelines: EnabledTimelines
}
const state = (): SideMenuState => ({
@ -29,21 +23,7 @@ const state = (): SideMenuState => ({
unreadDirectMessagesTimeline: false,
unreadPublicTimeline: false,
unreadFollowRequests: false,
lists: [],
tags: [],
collapse: false,
enabledTimelines: {
home: true,
notification: true,
mention: true,
direct: true,
favourite: true,
bookmark: true,
local: true,
public: true,
tag: true,
list: true
}
collapse: false
})
export const MUTATION_TYPES = {
@ -54,10 +34,7 @@ export const MUTATION_TYPES = {
CHANGE_UNREAD_DIRECT_MESSAGES_TIMELINE: 'changeUnreadDirectMessagesTimeline',
CHANGE_UNREAD_PUBLIC_TIMELINE: 'changeUnreadPublicTimeline',
CHANGE_UNREAD_FOLLOW_REQUESTS: 'changeUnreadFollowRequests',
UPDATE_LISTS: 'updateLists',
CHANGE_COLLAPSE: 'changeCollapse',
UPDATE_TAGS: 'updateTags',
UPDATE_ENABLED_TIMELINES: 'updateEnabledTimelines'
CHANGE_COLLAPSE: 'changeCollapse'
}
const mutations: MutationTree<SideMenuState> = {
@ -82,130 +59,18 @@ const mutations: MutationTree<SideMenuState> = {
[MUTATION_TYPES.CHANGE_UNREAD_FOLLOW_REQUESTS]: (state, value: boolean) => {
state.unreadFollowRequests = value
},
[MUTATION_TYPES.UPDATE_LISTS]: (state, lists: Array<Entity.List>) => {
state.lists = lists
},
[MUTATION_TYPES.CHANGE_COLLAPSE]: (state, collapse: boolean) => {
state.collapse = collapse
},
[MUTATION_TYPES.UPDATE_TAGS]: (state, tags: Array<LocalTag>) => {
state.tags = tags
},
[MUTATION_TYPES.UPDATE_ENABLED_TIMELINES]: (state, timelines: EnabledTimelines) => {
state.enabledTimelines = timelines
}
}
export const ACTION_TYPES = {
FETCH_LISTS: 'fetchLists',
FETCH_FOLLOW_REQUESTS: 'fetchFollowRequests',
CONFIRM_TIMELINES: 'confirmTimelines',
DISABLE_LOCAL: 'disableLocal',
DISABLE_PUBLIC: 'disablePublic',
DISABLE_DIRECT: 'disableDirect',
CLEAR_UNREAD: 'clearUnread',
CHANGE_COLLAPSE: 'changeCollapse',
READ_COLLAPSE: 'readCollapse',
LIST_TAGS: 'listTags'
READ_COLLAPSE: 'readCollapse'
}
const actions: ActionTree<SideMenuState, RootState> = {
[ACTION_TYPES.FETCH_LISTS]: async ({ commit, rootState }): Promise<Array<Entity.List>> => {
const client = generator(
rootState.TimelineSpace.server!.sns,
rootState.TimelineSpace.server!.baseURL,
rootState.TimelineSpace.account!.accessToken,
rootState.App.userAgent
)
const res = await client.getLists()
commit(MUTATION_TYPES.UPDATE_LISTS, res.data)
return res.data
},
[ACTION_TYPES.FETCH_FOLLOW_REQUESTS]: async ({ commit, rootState }): Promise<Array<Entity.Account>> => {
const client = generator(
rootState.TimelineSpace.server!.sns,
rootState.TimelineSpace.server!.baseURL,
rootState.TimelineSpace.account!.accessToken,
rootState.App.userAgent
)
const res = await client.getFollowRequests()
commit(MUTATION_TYPES.CHANGE_UNREAD_FOLLOW_REQUESTS, res.data.length > 0)
return res.data
},
[ACTION_TYPES.CONFIRM_TIMELINES]: async ({ commit, rootState }) => {
const client = generator(
rootState.TimelineSpace.server!.sns,
rootState.TimelineSpace.server!.baseURL,
rootState.TimelineSpace.account!.accessToken,
rootState.App.userAgent
)
let timelines: EnabledTimelines = {
home: true,
notification: true,
mention: true,
direct: true,
favourite: true,
bookmark: true,
local: true,
public: true,
tag: true,
list: true
}
const notification = async () => {
return client.getNotifications({ limit: 1 }).catch(() => {
timelines = { ...timelines, notification: false, mention: false }
})
}
const direct = async () => {
return client.getConversationTimeline({ limit: 1 }).catch(() => {
timelines = { ...timelines, direct: false }
})
}
const favourite = async () => {
return client.getFavourites({ limit: 1 }).catch(() => {
timelines = { ...timelines, favourite: false }
})
}
const bookmark = async () => {
return client.getBookmarks({ limit: 1 }).catch(() => {
timelines = { ...timelines, bookmark: false }
})
}
const local = async () => {
return client.getLocalTimeline({ limit: 1 }).catch(() => {
timelines = { ...timelines, local: false }
})
}
const pub = async () => {
return client.getPublicTimeline({ limit: 1 }).catch(() => {
timelines = { ...timelines, public: false }
})
}
const tag = async () => {
return client.getTagTimeline('whalebird', { limit: 1 }).catch(() => {
timelines = { ...timelines, tag: false }
})
}
await Promise.all([notification(), direct(), favourite(), bookmark(), local(), pub(), tag()])
commit(MUTATION_TYPES.UPDATE_ENABLED_TIMELINES, timelines)
},
[ACTION_TYPES.DISABLE_LOCAL]: ({ commit, state }) => {
let timelines = state.enabledTimelines
timelines = { ...timelines, local: false }
commit(MUTATION_TYPES.UPDATE_ENABLED_TIMELINES, timelines)
},
[ACTION_TYPES.DISABLE_PUBLIC]: ({ commit, state }) => {
let timelines = state.enabledTimelines
timelines = { ...timelines, public: false }
commit(MUTATION_TYPES.UPDATE_ENABLED_TIMELINES, timelines)
},
[ACTION_TYPES.DISABLE_DIRECT]: ({ commit, state }) => {
let timelines = state.enabledTimelines
timelines = { ...timelines, direct: false }
commit(MUTATION_TYPES.UPDATE_ENABLED_TIMELINES, timelines)
},
[ACTION_TYPES.CLEAR_UNREAD]: ({ commit }) => {
commit(MUTATION_TYPES.CHANGE_UNREAD_HOME_TIMELINE, false)
commit(MUTATION_TYPES.CHANGE_UNREAD_NOTIFICATIONS, false)
@ -222,11 +87,6 @@ const actions: ActionTree<SideMenuState, RootState> = {
const value: boolean = await win.ipcRenderer.invoke('get-collapse')
commit(MUTATION_TYPES.CHANGE_COLLAPSE, value)
return value
},
[ACTION_TYPES.LIST_TAGS]: async ({ commit }, accountId: number) => {
const tags: Array<LocalTag> = await win.ipcRenderer.invoke('list-hashtags', accountId)
commit(MUTATION_TYPES.UPDATE_TAGS, tags)
return tags
}
}