refs #1307 Confirm timelines after initialized
This commit is contained in:
parent
3808ecbd2a
commit
3046a17fcd
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<EnabledTimelines> => {
|
||||
const proxy = await proxyConfiguration.forMastodon()
|
||||
const timelines = await confirm(account, proxy)
|
||||
|
||||
return timelines
|
||||
}
|
||||
)
|
||||
|
||||
// user streaming
|
||||
let userStreamings: { [key: string]: UserStreaming | null } = {}
|
||||
|
||||
|
|
|
@ -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
|
|
@ -102,6 +102,7 @@ const actions: ActionTree<TimelineSpaceState, RootState> = {
|
|||
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(_ => {
|
||||
|
|
|
@ -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<Entity.List>
|
||||
tags: Array<LocalTag>
|
||||
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<SideMenuState> = {
|
||||
|
@ -76,6 +90,9 @@ const mutations: MutationTree<SideMenuState> = {
|
|||
},
|
||||
[MUTATION_TYPES.UPDATE_TAGS]: (state, tags: Array<LocalTag>) => {
|
||||
state.tags = tags
|
||||
},
|
||||
[MUTATION_TYPES.UPDATE_ENABLED_TIMELINES]: (state, timelines: EnabledTimelines) => {
|
||||
state.enabledTimelines = timelines
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,6 +123,11 @@ const actions: ActionTree<SideMenuState, RootState> = {
|
|||
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)
|
||||
|
|
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue