diff --git a/spec/renderer/integration/store/TimelineSpace/Contents/FollowRequests.spec.ts b/spec/renderer/integration/store/TimelineSpace/Contents/FollowRequests.spec.ts index 5b273b46..10ba90d4 100644 --- a/spec/renderer/integration/store/TimelineSpace/Contents/FollowRequests.spec.ts +++ b/spec/renderer/integration/store/TimelineSpace/Contents/FollowRequests.spec.ts @@ -94,7 +94,18 @@ const sideMenuState = (): SideMenuState => { unreadFollowRequests: false, lists: [], tags: [], - collapse: false + collapse: false, + enabledTimelines: { + home: true, + notification: true, + mention: true, + direct: true, + favourite: true, + local: true, + public: true, + tag: true, + list: true + } } } diff --git a/spec/renderer/integration/store/TimelineSpace/SideMenu.spec.ts b/spec/renderer/integration/store/TimelineSpace/SideMenu.spec.ts index 2e355665..cb98a4f5 100644 --- a/spec/renderer/integration/store/TimelineSpace/SideMenu.spec.ts +++ b/spec/renderer/integration/store/TimelineSpace/SideMenu.spec.ts @@ -50,7 +50,18 @@ const state = (): SideMenuState => { unreadFollowRequests: false, lists: [], tags: [], - collapse: false + collapse: false, + enabledTimelines: { + home: true, + notification: true, + mention: true, + direct: true, + favourite: true, + local: true, + public: true, + tag: true, + list: true + } } } diff --git a/src/main/index.ts b/src/main/index.ts index 8fcacf29..08bdad2c 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -13,7 +13,8 @@ import { IpcMainEvent, Notification, NotificationConstructorOptions, - nativeTheme + nativeTheme, + IpcMainInvokeEvent } from 'electron' import Datastore from 'nedb' import { isEmpty } from 'lodash' @@ -49,6 +50,8 @@ import AccountCache from './cache/account' import { InsertAccountCache } from '~/src/types/insertAccountCache' import { Proxy } from '~/src/types/proxy' import ProxyConfiguration from './proxy' +import confirm from './timelines' +import { EnabledTimelines } from '~/src/types/enabledTimelines' /** * Context menu @@ -539,6 +542,16 @@ ipcMain.on('reset-badge', () => { } }) +ipcMain.handle( + 'confirm-timelines', + async (_event: IpcMainInvokeEvent, account: LocalAccount): Promise => { + const proxy = await proxyConfiguration.forMastodon() + const timelines = await confirm(account, proxy) + + return timelines + } +) + // user streaming let userStreamings: { [key: string]: UserStreaming | null } = {} diff --git a/src/main/timelines.ts b/src/main/timelines.ts new file mode 100644 index 00000000..d0f0bbff --- /dev/null +++ b/src/main/timelines.ts @@ -0,0 +1,66 @@ +import generator, { detector, ProxyConfig } from 'megalodon' +import { LocalAccount } from '~/src/types/localAccount' +import { EnabledTimelines } from '~/src/types/enabledTimelines' + +const confirm = async (account: LocalAccount, proxy: ProxyConfig | false) => { + const sns = await detector(account.baseURL, proxy) + const client = generator(sns, account.baseURL, account.accessToken, 'Whalebird', proxy) + + let timelines: EnabledTimelines = { + home: true, + notification: true, + mention: true, + direct: true, + favourite: true, + local: true, + public: true, + tag: true, + list: true + } + + try { + await client.getHomeTimeline({ limit: 1 }) + } catch (err) { + timelines = { ...timelines, home: false } + } + + try { + await client.getNotifications({ limit: 1 }) + } catch (err) { + timelines = { ...timelines, notification: false, mention: false } + } + + try { + await client.getConversationTimeline({ limit: 1 }) + } catch (err) { + timelines = { ...timelines, direct: false } + } + + try { + await client.getFavourites({ limit: 1 }) + } catch (err) { + timelines = { ...timelines, favourite: false } + } + + try { + await client.getLocalTimeline({ limit: 1 }) + } catch (err) { + timelines = { ...timelines, local: false } + } + + try { + await client.getPublicTimeline({ limit: 1 }) + } catch (err) { + timelines = { ...timelines, public: false } + } + + try { + await client.getTagTimeline('whalebird', { limit: 1 }) + } catch (err) { + timelines = { ...timelines, tag: false } + } + + return timelines +} + +export default confirm diff --git a/src/renderer/store/TimelineSpace.ts b/src/renderer/store/TimelineSpace.ts index f55dcab1..c2fca00f 100644 --- a/src/renderer/store/TimelineSpace.ts +++ b/src/renderer/store/TimelineSpace.ts @@ -102,6 +102,7 @@ const actions: ActionTree = { await dispatch('detectSNS') dispatch('TimelineSpace/SideMenu/fetchLists', account, { root: true }) dispatch('TimelineSpace/SideMenu/fetchFollowRequests', account, { root: true }) + dispatch('TimelineSpace/SideMenu/confirmTimelines', account, { root: true }) await dispatch('loadUnreadNotification', accountId) commit(MUTATION_TYPES.CHANGE_LOADING, false) await dispatch('fetchContentsTimelines').catch(_ => { diff --git a/src/renderer/store/TimelineSpace/SideMenu.ts b/src/renderer/store/TimelineSpace/SideMenu.ts index 3f32205f..7bd8541a 100644 --- a/src/renderer/store/TimelineSpace/SideMenu.ts +++ b/src/renderer/store/TimelineSpace/SideMenu.ts @@ -4,6 +4,7 @@ import { LocalTag } from '~/src/types/localTag' import { LocalAccount } from '~/src/types/localAccount' import { RootState } from '@/store' import { MyWindow } from '~/src/types/global' +import { EnabledTimelines } from '~/src/types/enabledTimelines' const win = window as MyWindow @@ -18,6 +19,7 @@ export type SideMenuState = { lists: Array tags: Array collapse: boolean + enabledTimelines: EnabledTimelines } const state = (): SideMenuState => ({ @@ -30,7 +32,18 @@ const state = (): SideMenuState => ({ unreadFollowRequests: false, lists: [], tags: [], - collapse: false + collapse: false, + enabledTimelines: { + home: true, + notification: true, + mention: true, + direct: true, + favourite: true, + local: true, + public: true, + tag: true, + list: true + } }) export const MUTATION_TYPES = { @@ -43,7 +56,8 @@ export const MUTATION_TYPES = { CHANGE_UNREAD_FOLLOW_REQUESTS: 'changeUnreadFollowRequests', UPDATE_LISTS: 'updateLists', CHANGE_COLLAPSE: 'changeCollapse', - UPDATE_TAGS: 'updateTags' + UPDATE_TAGS: 'updateTags', + UPDATE_ENABLED_TIMELINES: 'updateEnabledTimelines' } const mutations: MutationTree = { @@ -76,6 +90,9 @@ const mutations: MutationTree = { }, [MUTATION_TYPES.UPDATE_TAGS]: (state, tags: Array) => { state.tags = tags + }, + [MUTATION_TYPES.UPDATE_ENABLED_TIMELINES]: (state, timelines: EnabledTimelines) => { + state.enabledTimelines = timelines } } @@ -106,6 +123,11 @@ const actions: ActionTree = { commit(MUTATION_TYPES.CHANGE_UNREAD_FOLLOW_REQUESTS, res.data.length > 0) return res.data }, + confirmTimelines: async ({ commit, rootState }, account: LocalAccount | null = null) => { + if (account === null) account = rootState.TimelineSpace.account + const timelines: EnabledTimelines = await win.ipcRenderer.invoke('confirm-timelines', account) + commit(MUTATION_TYPES.UPDATE_ENABLED_TIMELINES, timelines) + }, clearUnread: ({ commit }) => { commit(MUTATION_TYPES.CHANGE_UNREAD_HOME_TIMELINE, false) commit(MUTATION_TYPES.CHANGE_UNREAD_NOTIFICATIONS, false) diff --git a/src/types/enabledTimelines.ts b/src/types/enabledTimelines.ts new file mode 100644 index 00000000..8f3f6f8c --- /dev/null +++ b/src/types/enabledTimelines.ts @@ -0,0 +1,11 @@ +export type EnabledTimelines = { + home: boolean + notification: boolean + mention: boolean + direct: boolean + favourite: boolean + local: boolean + public: boolean + tag: boolean + list: boolean +}