refs #982 Add proxy configuration for all requests from renderer
This commit is contained in:
parent
a0a0838fb4
commit
296ec5c6c2
|
@ -36,6 +36,7 @@ export default {
|
|||
this.$store.dispatch('App/loadPreferences').then(conf => {
|
||||
this.$i18n.i18next.changeLanguage(conf.language.language)
|
||||
})
|
||||
this.$store.dispatch('App/loadProxy')
|
||||
},
|
||||
destroyed() {
|
||||
this.$store.dispatch('App/removeShortcutsEvents')
|
||||
|
|
|
@ -10,7 +10,9 @@ import DefaultFonts from '@/utils/fonts'
|
|||
import { RootState } from '@/store'
|
||||
import { Notify } from '~/src/types/notify'
|
||||
import { BaseConfig } from '~/src/types/preference'
|
||||
import { Appearance } from '~src/types/appearance'
|
||||
import { Appearance } from '~/src/types/appearance'
|
||||
import { ManualProxy, ProxyProtocol } from '~/src/types/proxy'
|
||||
import { ProxyConfig } from 'megalodon'
|
||||
|
||||
export type AppState = {
|
||||
theme: ThemeColorType
|
||||
|
@ -24,6 +26,8 @@ export type AppState = {
|
|||
ignoreNFSW: boolean
|
||||
hideAllAttachments: boolean
|
||||
tootPadding: number
|
||||
proxyConfiguration: ProxyConfig | false
|
||||
userAgent: string
|
||||
}
|
||||
|
||||
const state = (): AppState => ({
|
||||
|
@ -42,7 +46,9 @@ const state = (): AppState => ({
|
|||
defaultFonts: DefaultFonts,
|
||||
ignoreCW: false,
|
||||
ignoreNFSW: false,
|
||||
hideAllAttachments: false
|
||||
hideAllAttachments: false,
|
||||
proxyConfiguration: false,
|
||||
userAgent: 'Whalebird'
|
||||
})
|
||||
|
||||
const MUTATION_TYPES = {
|
||||
|
@ -56,7 +62,8 @@ const MUTATION_TYPES = {
|
|||
ADD_FONT: 'addFont',
|
||||
UPDATE_IGNORE_CW: 'updateIgnoreCW',
|
||||
UPDATE_IGNORE_NFSW: 'updateIgnoreNFSW',
|
||||
UPDATE_HIDE_ALL_ATTACHMENTS: 'updateHideAllAttachments'
|
||||
UPDATE_HIDE_ALL_ATTACHMENTS: 'updateHideAllAttachments',
|
||||
UPDATE_PROXY_CONFIGURATION: 'updateProxyConfiguration'
|
||||
}
|
||||
|
||||
const mutations: MutationTree<AppState> = {
|
||||
|
@ -93,6 +100,33 @@ const mutations: MutationTree<AppState> = {
|
|||
},
|
||||
[MUTATION_TYPES.UPDATE_HIDE_ALL_ATTACHMENTS]: (state: AppState, hideAllAttachments: boolean) => {
|
||||
state.hideAllAttachments = hideAllAttachments
|
||||
},
|
||||
[MUTATION_TYPES.UPDATE_PROXY_CONFIGURATION]: (state, proxy: ManualProxy | false) => {
|
||||
if (!proxy) {
|
||||
state.proxyConfiguration = false
|
||||
} else {
|
||||
let protocol = ProxyProtocol.http
|
||||
if (proxy.protocol !== '') {
|
||||
protocol = proxy.protocol
|
||||
}
|
||||
if (proxy.username.length > 0) {
|
||||
state.proxyConfiguration = {
|
||||
host: proxy.host,
|
||||
port: parseInt(proxy.port, 10),
|
||||
protocol: protocol,
|
||||
auth: {
|
||||
username: proxy.username,
|
||||
password: proxy.password
|
||||
}
|
||||
}
|
||||
} else {
|
||||
state.proxyConfiguration = {
|
||||
host: proxy.host,
|
||||
port: parseInt(proxy.port, 10),
|
||||
protocol: protocol
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -154,6 +188,15 @@ const actions: ActionTree<AppState, RootState> = {
|
|||
commit(MUTATION_TYPES.UPDATE_THEME, LightTheme)
|
||||
break
|
||||
}
|
||||
},
|
||||
loadProxy: ({ commit }) => {
|
||||
return new Promise(resolve => {
|
||||
ipcRenderer.once('response-get-proxy-configuration', (_, proxy: ManualProxy | false) => {
|
||||
commit(MUTATION_TYPES.UPDATE_PROXY_CONFIGURATION, proxy)
|
||||
resolve(proxy)
|
||||
})
|
||||
ipcRenderer.send('get-proxy-configuration')
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { ipcRenderer } from 'electron'
|
||||
import axios from 'axios'
|
||||
import Mastodon from 'megalodon'
|
||||
import { Module, MutationTree, ActionTree } from 'vuex'
|
||||
import { RootState } from '@/store'
|
||||
|
||||
|
@ -44,11 +44,11 @@ const actions: ActionTree<LoginState, RootState> = {
|
|||
pageBack: ({ commit }) => {
|
||||
commit(MUTATION_TYPES.CHANGE_INSTANCE, null)
|
||||
},
|
||||
confirmInstance: async ({ commit }, domain: string): Promise<boolean> => {
|
||||
confirmInstance: async ({ commit, rootState }, domain: string): Promise<boolean> => {
|
||||
commit(MUTATION_TYPES.CHANGE_SEARCHING, true)
|
||||
// https://gist.github.com/okapies/60d62d0df0163bbfb4ab09c1766558e8
|
||||
// Check /.well-known/host-meta to confirm mastodon instance.
|
||||
const res = await axios.get(`https://${domain}/.well-known/host-meta`).finally(() => {
|
||||
const res = await Mastodon.get<any>('/.well-known/host-meta', {}, `https://${domain}`, rootState.App.proxyConfiguration).finally(() => {
|
||||
commit(MUTATION_TYPES.CHANGE_SEARCHING, false)
|
||||
})
|
||||
const parser = new DOMParser()
|
||||
|
|
|
@ -29,7 +29,12 @@ const mutations: MutationTree<GeneralState> = {
|
|||
|
||||
const actions: ActionTree<GeneralState, RootState> = {
|
||||
fetchSettings: async ({ commit, rootState }): Promise<Account> => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res = await client.get<Account>('/accounts/verify_credentials')
|
||||
const visibility: VisibilityType | undefined = (Object.values(Visibility) as Array<VisibilityType>).find(v => {
|
||||
return v.key === res.data.source!.privacy
|
||||
|
@ -39,7 +44,12 @@ const actions: ActionTree<GeneralState, RootState> = {
|
|||
return res.data
|
||||
},
|
||||
setVisibility: async ({ commit, rootState }, value: number) => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const visibility: VisibilityType | undefined = (Object.values(Visibility) as Array<VisibilityType>).find(v => {
|
||||
return v.value === value
|
||||
})
|
||||
|
@ -52,7 +62,12 @@ const actions: ActionTree<GeneralState, RootState> = {
|
|||
return res.data
|
||||
},
|
||||
setSensitive: async ({ commit, rootState }, value: boolean) => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res = await client.patch<Account>('/accounts/update_credentials', {
|
||||
source: {
|
||||
sensitive: value
|
||||
|
|
|
@ -161,8 +161,8 @@ const actions: ActionTree<TimelineSpaceState, RootState> = {
|
|||
commit(MUTATION_TYPES.UPDATE_ACCOUNT, blankAccount)
|
||||
return true
|
||||
},
|
||||
detectPleroma: async ({ commit, state }) => {
|
||||
const res = await Mastodon.get<Instance>('/instance', {}, state.account.baseURL + '/api/v1')
|
||||
detectPleroma: async ({ commit, state, rootState }) => {
|
||||
const res = await Mastodon.get<Instance>('/instance', {}, state.account.baseURL + '/api/v1', rootState.App.proxyConfiguration)
|
||||
if (res.data.version.includes('Pleroma')) {
|
||||
commit(MUTATION_TYPES.CHANGE_PLEROMA, true)
|
||||
} else {
|
||||
|
@ -194,16 +194,16 @@ const actions: ActionTree<TimelineSpaceState, RootState> = {
|
|||
/**
|
||||
* fetchEmojis
|
||||
*/
|
||||
fetchEmojis: async ({ commit }, account: LocalAccount): Promise<Array<Emoji>> => {
|
||||
const res = await Mastodon.get<Array<Emoji>>('/custom_emojis', {}, account.baseURL + '/api/v1')
|
||||
fetchEmojis: async ({ commit, rootState }, account: LocalAccount): Promise<Array<Emoji>> => {
|
||||
const res = await Mastodon.get<Array<Emoji>>('/custom_emojis', {}, account.baseURL + '/api/v1', rootState.App.proxyConfiguration)
|
||||
commit(MUTATION_TYPES.UPDATE_EMOJIS, res.data)
|
||||
return res.data
|
||||
},
|
||||
/**
|
||||
* fetchInstance
|
||||
*/
|
||||
fetchInstance: async ({ commit }, account: LocalAccount) => {
|
||||
const res = await Mastodon.get<Instance>('/instance', {}, account.baseURL + '/api/v1')
|
||||
fetchInstance: async ({ commit, rootState }, account: LocalAccount) => {
|
||||
const res = await Mastodon.get<Instance>('/instance', {}, account.baseURL + '/api/v1', rootState.App.proxyConfiguration)
|
||||
commit(MUTATION_TYPES.UPDATE_TOOT_MAX, res.data.max_toot_chars)
|
||||
return true
|
||||
},
|
||||
|
|
|
@ -96,7 +96,12 @@ const mutations: MutationTree<DirectMessagesState> = {
|
|||
|
||||
const actions: ActionTree<DirectMessagesState, RootState> = {
|
||||
fetchTimeline: async ({ commit, rootState }): Promise<Array<Status>> => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<Array<Conversation>> = await client.get<Array<Conversation>>('/conversations', { limit: 40 })
|
||||
const statuses: Array<Status> = res.data.map(con => con.last_status!)
|
||||
commit(MUTATION_TYPES.UPDATE_TIMELINE, statuses)
|
||||
|
@ -107,7 +112,12 @@ const actions: ActionTree<DirectMessagesState, RootState> = {
|
|||
return Promise.resolve(null)
|
||||
}
|
||||
commit(MUTATION_TYPES.CHANGE_LAZY_LOADING, true)
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
return client
|
||||
.get<Array<Conversation>>('/conversations', { max_id: lastStatus.id, limit: 40 })
|
||||
.then(res => {
|
||||
|
|
|
@ -72,8 +72,13 @@ const mutations: MutationTree<FavouritesState> = {
|
|||
}
|
||||
|
||||
const actions: ActionTree<FavouritesState, RootState> = {
|
||||
fetchFavourites: async ({ commit }, account: LocalAccount): Promise<Array<Status>> => {
|
||||
const client = new Mastodon(account.accessToken!, account.baseURL + '/api/v1')
|
||||
fetchFavourites: async ({ commit, rootState }, account: LocalAccount): Promise<Array<Status>> => {
|
||||
const client = new Mastodon(
|
||||
account.accessToken!,
|
||||
account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<Array<Status>> = await client.get<Array<Status>>('/favourites', { limit: 40 })
|
||||
commit(MUTATION_TYPES.UPDATE_FAVOURITES, res.data)
|
||||
// Parse link header
|
||||
|
@ -98,7 +103,12 @@ const actions: ActionTree<FavouritesState, RootState> = {
|
|||
return Promise.resolve(null)
|
||||
}
|
||||
commit(MUTATION_TYPES.CHANGE_LAZY_LOADING, true)
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<Array<Status>> = await client.get<Array<Status>>('/favourites', { max_id: state.maxId, limit: 40 }).finally(() => {
|
||||
commit(MUTATION_TYPES.CHANGE_LAZY_LOADING, false)
|
||||
})
|
||||
|
|
|
@ -22,20 +22,35 @@ const mutations: MutationTree<FollowRequestsState> = {
|
|||
|
||||
const actions: ActionTree<FollowRequestsState, RootState> = {
|
||||
fetchRequests: async ({ commit, rootState }): Promise<Array<Account>> => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<Array<Account>> = await client.get<Array<Account>>('/follow_requests')
|
||||
commit(MUTATION_TYPES.UPDATE_REQUESTS, res.data)
|
||||
return res.data
|
||||
},
|
||||
acceptRequest: async ({ dispatch, rootState }, user: Account) => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<{}> = await client.post<{}>(`/follow_requests/${user.id}/authorize`)
|
||||
await dispatch('fetchRequests')
|
||||
dispatch('TimelineSpace/SideMenu/fetchFollowRequests', rootState.TimelineSpace.account, { root: true })
|
||||
return res.data
|
||||
},
|
||||
rejectRequest: async ({ dispatch, rootState }, user: Account) => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<{}> = await client.post<{}>(`/follow_requests/${user.id}/reject`)
|
||||
await dispatch('fetchRequests')
|
||||
dispatch('TimelineSpace/SideMenu/fetchFollowRequests', rootState.TimelineSpace.account, { root: true })
|
||||
|
|
|
@ -97,7 +97,12 @@ const mutations: MutationTree<TagState> = {
|
|||
|
||||
const actions: ActionTree<TagState, RootState> = {
|
||||
fetch: async ({ commit, rootState }, tag: string): Promise<Array<Status>> => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<Array<Status>> = await client.get<Array<Status>>(`/timelines/tag/${encodeURIComponent(tag)}`, { limit: 40 })
|
||||
commit(MUTATION_TYPES.UPDATE_TIMELINE, res.data)
|
||||
return res.data
|
||||
|
@ -138,7 +143,12 @@ const actions: ActionTree<TagState, RootState> = {
|
|||
return Promise.resolve(null)
|
||||
}
|
||||
commit(MUTATION_TYPES.CHANGE_LAZY_LOADING, true)
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
return client
|
||||
.get<Array<Status>>(`/timelines/tag/${loadPosition.tag}`, { max_id: loadPosition.status.id, limit: 40 })
|
||||
.then(res => {
|
||||
|
|
|
@ -108,7 +108,12 @@ const mutations: MutationTree<HomeState> = {
|
|||
|
||||
const actions: ActionTree<HomeState, RootState> = {
|
||||
fetchTimeline: async ({ commit, rootState }) => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<Array<Status>> = await client.get<Array<Status>>('/timelines/home', { limit: 40 })
|
||||
commit(MUTATION_TYPES.UPDATE_TIMELINE, res.data)
|
||||
return res.data
|
||||
|
@ -118,7 +123,12 @@ const actions: ActionTree<HomeState, RootState> = {
|
|||
return Promise.resolve(null)
|
||||
}
|
||||
commit(MUTATION_TYPES.CHANGE_LAZY_LOADING, true)
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
return client
|
||||
.get<Array<Status>>('/timelines/home', { max_id: lastStatus.id, limit: 40 })
|
||||
.then(res => {
|
||||
|
|
|
@ -23,7 +23,12 @@ const mutations: MutationTree<EditState> = {
|
|||
|
||||
const actions: ActionTree<EditState, RootState> = {
|
||||
fetchMembers: async ({ commit, rootState }, listId: string): Promise<Array<Account>> => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<Array<Account>> = await client.get<Array<Account>>(`/lists/${listId}/accounts`, {
|
||||
limit: 0
|
||||
})
|
||||
|
@ -31,7 +36,12 @@ const actions: ActionTree<EditState, RootState> = {
|
|||
return res.data
|
||||
},
|
||||
removeAccount: async ({ rootState }, remove: RemoveAccountFromList): Promise<{}> => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
return client.del<{}>(`/lists/${remove.listId}/accounts`, {
|
||||
account_ids: [remove.account.id]
|
||||
})
|
||||
|
|
|
@ -22,13 +22,23 @@ const mutations: MutationTree<IndexState> = {
|
|||
|
||||
const actions: ActionTree<IndexState, RootState> = {
|
||||
fetchLists: async ({ commit, rootState }): Promise<Array<List>> => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<Array<List>> = await client.get<Array<List>>('/lists')
|
||||
commit(MUTATION_TYPES.CHANGE_LISTS, res.data)
|
||||
return res.data
|
||||
},
|
||||
createList: async ({ rootState }, title: string): Promise<List> => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<List> = await client.post<List>('/lists', {
|
||||
title: title
|
||||
})
|
||||
|
|
|
@ -97,7 +97,12 @@ const mutations: MutationTree<ShowState> = {
|
|||
|
||||
const actions: ActionTree<ShowState, RootState> = {
|
||||
fetchTimeline: async ({ commit, rootState }, listID: string): Promise<Array<Status>> => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<Array<Status>> = await client.get<Array<Status>>(`/timelines/list/${listID}`, { limit: 40 })
|
||||
commit(MUTATION_TYPES.UPDATE_TIMELINE, res.data)
|
||||
return res.data
|
||||
|
@ -138,7 +143,12 @@ const actions: ActionTree<ShowState, RootState> = {
|
|||
return Promise.resolve(null)
|
||||
}
|
||||
commit(MUTATION_TYPES.CHANGE_LAZY_LOADING, true)
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
return client
|
||||
.get<Array<Status>>(`/timelines/list/${loadPosition.list_id}`, { max_id: loadPosition.status.id, limit: 40 })
|
||||
.then(res => {
|
||||
|
|
|
@ -95,7 +95,12 @@ const mutations: MutationTree<LocalState> = {
|
|||
|
||||
const actions: ActionTree<LocalState, RootState> = {
|
||||
fetchLocalTimeline: async ({ commit, rootState }): Promise<Array<Status>> => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<Array<Status>> = await client.get<Array<Status>>('/timelines/public', { limit: 40, local: true })
|
||||
commit(MUTATION_TYPES.UPDATE_TIMELINE, res.data)
|
||||
return res.data
|
||||
|
@ -105,7 +110,12 @@ const actions: ActionTree<LocalState, RootState> = {
|
|||
return Promise.resolve(null)
|
||||
}
|
||||
commit(MUTATION_TYPES.CHANGE_LAZY_LOADING, true)
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
return client
|
||||
.get<Array<Status>>('/timelines/public', { max_id: lastStatus.id, limit: 40, local: true })
|
||||
.then(res => {
|
||||
|
|
|
@ -95,7 +95,12 @@ const mutations: MutationTree<MentionsState> = {
|
|||
|
||||
const actions: ActionTree<MentionsState, RootState> = {
|
||||
fetchMentions: async ({ commit, rootState }): Promise<Array<Notification>> => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<Array<Notification>> = await client.get<Array<Notification>>('/notifications', {
|
||||
limit: 30,
|
||||
exclude_types: ['follow', 'favourite', 'reblog']
|
||||
|
@ -108,7 +113,12 @@ const actions: ActionTree<MentionsState, RootState> = {
|
|||
return Promise.resolve(null)
|
||||
}
|
||||
commit(MUTATION_TYPES.CHANGE_LAZY_LOADING, true)
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
return client
|
||||
.get<Array<Notification>>('/notifications', { max_id: lastMention.id, limit: 30, exclude_types: ['follow', 'favourite', 'reblog'] })
|
||||
.then(res => {
|
||||
|
|
|
@ -97,7 +97,12 @@ const mutations: MutationTree<NotificationsState> = {
|
|||
|
||||
const actions: ActionTree<NotificationsState, RootState> = {
|
||||
fetchNotifications: async ({ commit, rootState }): Promise<Array<Notification>> => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<Array<Notification>> = await client.get<Array<Notification>>('/notifications', { limit: 30 })
|
||||
|
||||
commit(MUTATION_TYPES.UPDATE_NOTIFICATIONS, res.data)
|
||||
|
@ -108,7 +113,12 @@ const actions: ActionTree<NotificationsState, RootState> = {
|
|||
return Promise.resolve(null)
|
||||
}
|
||||
commit(MUTATION_TYPES.CHANGE_LAZY_LOADING, true)
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
return client
|
||||
.get<Array<Notification>>('/notifications', { max_id: lastNotification.id, limit: 30 })
|
||||
.then(res => {
|
||||
|
|
|
@ -95,7 +95,12 @@ const mutations: MutationTree<PublicState> = {
|
|||
|
||||
const actions: ActionTree<PublicState, RootState> = {
|
||||
fetchPublicTimeline: async ({ commit, rootState }): Promise<Array<Status>> => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<Array<Status>> = await client.get<Array<Status>>('/timelines/public', { limit: 40 })
|
||||
commit(MUTATION_TYPES.UPDATE_TIMELINE, res.data)
|
||||
return res.data
|
||||
|
@ -105,7 +110,12 @@ const actions: ActionTree<PublicState, RootState> = {
|
|||
return Promise.resolve(null)
|
||||
}
|
||||
commit(MUTATION_TYPES.CHANGE_LAZY_LOADING, true)
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
return client
|
||||
.get<Array<Status>>('/timelines/public', { max_id: lastStatus.id, limit: 40 })
|
||||
.then(res => {
|
||||
|
|
|
@ -23,7 +23,12 @@ const mutations: MutationTree<AccountState> = {
|
|||
const actions: ActionTree<AccountState, RootState> = {
|
||||
search: async ({ commit, rootState }, query: string): Promise<Array<Account>> => {
|
||||
commit('TimelineSpace/Contents/changeLoading', true, { root: true })
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
return client
|
||||
.get<Array<Account>>('/accounts/search', { q: query, resolve: true })
|
||||
.then(res => {
|
||||
|
|
|
@ -23,7 +23,12 @@ const mutations: MutationTree<TagState> = {
|
|||
const actions: ActionTree<TagState, RootState> = {
|
||||
search: ({ commit, rootState }, query: string): Promise<Array<Tag>> => {
|
||||
commit('TimelineSpace/Contents/changeLoading', true, { root: true })
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v2')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v2',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
return client
|
||||
.get<Results>('/search', { q: query, resolve: true })
|
||||
.then(res => {
|
||||
|
|
|
@ -23,7 +23,12 @@ const mutations: MutationTree<TootsState> = {
|
|||
const actions: ActionTree<TootsState, RootState> = {
|
||||
search: ({ commit, rootState }, query: string): Promise<Array<Status>> => {
|
||||
commit('TimelineSpace/Contents/changeLoading', true, { root: true })
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
return client
|
||||
.get<Results>('/search', { q: query, resolve: true })
|
||||
.then(res => {
|
||||
|
|
|
@ -45,12 +45,22 @@ const mutations: MutationTree<AccountProfileState> = {
|
|||
|
||||
const actions: ActionTree<AccountProfileState, RootState> = {
|
||||
fetchAccount: async ({ rootState }, accountID: string): Promise<Account> => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<Account> = await client.get<Account>(`/accounts/${accountID}`)
|
||||
return res.data
|
||||
},
|
||||
searchAccount: async ({ rootState }, parsedAccount): Promise<Account> => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<Array<Account>> = await client.get<Array<Account>>('/accounts/search', { q: parsedAccount.url, resolve: true })
|
||||
if (res.data.length <= 0) throw new AccountNotFound('empty result')
|
||||
const account = res.data.find(a => `@${a.acct}` === parsedAccount.acct)
|
||||
|
@ -69,7 +79,12 @@ const actions: ActionTree<AccountProfileState, RootState> = {
|
|||
},
|
||||
fetchRelationship: async ({ commit, rootState }, account: Account): Promise<Relationship> => {
|
||||
commit(MUTATION_TYPES.CHANGE_RELATIONSHIP, null)
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<Relationship> = await client.get<Relationship>('/accounts/relationships', { id: [account.id] })
|
||||
commit(MUTATION_TYPES.CHANGE_RELATIONSHIP, res.data[0])
|
||||
return res.data
|
||||
|
@ -86,14 +101,24 @@ const actions: ActionTree<AccountProfileState, RootState> = {
|
|||
})
|
||||
},
|
||||
follow: async ({ commit, rootState, dispatch }, account: Account) => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<Relationship> = await client.post<Relationship>(`/accounts/${account.id}/follow`)
|
||||
commit(MUTATION_TYPES.CHANGE_RELATIONSHIP, res.data)
|
||||
dispatch('fetchRelationship', account)
|
||||
return res.data
|
||||
},
|
||||
unfollow: async ({ commit, rootState, dispatch }, account: Account) => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<Relationship> = await client.post<Relationship>(`/accounts/${account.id}/unfollow`)
|
||||
commit(MUTATION_TYPES.CHANGE_RELATIONSHIP, res.data)
|
||||
dispatch('fetchRelationship', account)
|
||||
|
@ -103,21 +128,36 @@ const actions: ActionTree<AccountProfileState, RootState> = {
|
|||
commit(MUTATION_TYPES.CHANGE_ACCOUNT, null)
|
||||
},
|
||||
unmute: async ({ rootState, commit, dispatch }, account: Account) => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<Relationship> = await client.post<Relationship>(`/accounts/${account.id}/unmute`)
|
||||
commit(MUTATION_TYPES.CHANGE_RELATIONSHIP, res.data)
|
||||
dispatch('fetchRelationship', account)
|
||||
return res.data
|
||||
},
|
||||
block: async ({ rootState, commit, dispatch }, account: Account) => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<Relationship> = await client.post<Relationship>(`/accounts/${account.id}/block`)
|
||||
commit(MUTATION_TYPES.CHANGE_RELATIONSHIP, res.data)
|
||||
dispatch('fetchRelationship', account)
|
||||
return res.data
|
||||
},
|
||||
unblock: async ({ rootState, commit, dispatch }, account: Account) => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<Relationship> = await client.post<Relationship>(`/accounts/${account.id}/unblock`)
|
||||
commit(MUTATION_TYPES.CHANGE_RELATIONSHIP, res.data)
|
||||
dispatch('fetchRelationship', account)
|
||||
|
|
|
@ -28,14 +28,24 @@ const mutations: MutationTree<FollowersState> = {
|
|||
|
||||
const actions: ActionTree<FollowersState, RootState> = {
|
||||
fetchFollowers: async ({ commit, rootState }, account: Account) => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<Array<Account>> = await client.get<Array<Account>>(`/accounts/${account.id}/followers`, { limit: 80 })
|
||||
commit(MUTATION_TYPES.UPDATE_FOLLOWERS, res.data)
|
||||
return res.data
|
||||
},
|
||||
fetchRelationships: async ({ commit, rootState }, accounts: Array<Account>) => {
|
||||
const ids = accounts.map(a => a.id)
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<Array<Relationship>> = await client.get<Array<Relationship>>(`/accounts/relationships`, {
|
||||
id: ids
|
||||
})
|
||||
|
|
|
@ -28,14 +28,24 @@ const mutations: MutationTree<FollowsState> = {
|
|||
|
||||
const actions: ActionTree<FollowsState, RootState> = {
|
||||
fetchFollows: async ({ commit, rootState }, account: Account) => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<Array<Account>> = await client.get<Array<Account>>(`/accounts/${account.id}/following`, { limit: 80 })
|
||||
commit(MUTATION_TYPES.UPDATE_FOLLOWS, res.data)
|
||||
return res.data
|
||||
},
|
||||
fetchRelationships: async ({ commit, rootState }, accounts: Array<Account>) => {
|
||||
const ids = accounts.map(a => a.id)
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<Array<Relationship>> = await client.get<Array<Relationship>>(`/accounts/relationships`, {
|
||||
id: ids
|
||||
})
|
||||
|
|
|
@ -85,7 +85,12 @@ const mutations: MutationTree<TimelineState> = {
|
|||
const actions: ActionTree<TimelineState, RootState> = {
|
||||
fetchTimeline: async ({ commit, rootState }, account: Account) => {
|
||||
commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', true, { root: true })
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const pinned: Response<Array<Status>> = await client.get<Array<Status>>(`/accounts/${account.id}/statuses`, { limit: 10, pinned: true })
|
||||
commit(MUTATION_TYPES.UPDATE_PINNED_TOOTS, pinned.data)
|
||||
const res: Response<Array<Status>> = await client.get<Array<Status>>(`/accounts/${account.id}/statuses`, { limit: 40 })
|
||||
|
@ -98,7 +103,12 @@ const actions: ActionTree<TimelineState, RootState> = {
|
|||
return Promise.resolve(null)
|
||||
}
|
||||
commit(MUTATION_TYPES.CHANGE_LAZY_LOADING, true)
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
try {
|
||||
const res: Response<Array<Status>> = await client.get<Array<Status>>(`/accounts/${loadPosition.account.id}/statuses`, {
|
||||
max_id: loadPosition.status.id,
|
||||
|
|
|
@ -120,7 +120,12 @@ const actions: ActionTree<TootDetailState, RootState> = {
|
|||
commit(MUTATION_TYPES.CHANGE_TOOT, message)
|
||||
},
|
||||
fetchToot: async ({ commit, rootState }, message: Status) => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<Context> = await client.get<Context>(`/statuses/${message.id}/context`, { limit: 40 })
|
||||
|
||||
commit(MUTATION_TYPES.UPDATE_ANCESTORS, res.data.ancestors)
|
||||
|
|
|
@ -35,7 +35,12 @@ const mutations: MutationTree<HeaderMenuState> = {
|
|||
|
||||
const actions: ActionTree<HeaderMenuState, RootState> = {
|
||||
fetchList: async ({ commit, rootState }, listID: string): Promise<List> => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<List> = await client.get<List>(`/lists/${listID}`)
|
||||
commit(MUTATION_TYPES.UPDATE_TITLE, `#${res.data.title}`)
|
||||
return res.data
|
||||
|
|
|
@ -37,7 +37,12 @@ const actions: ActionTree<AddListMemberState, RootState> = {
|
|||
commit(MUTATION_TYPES.CHANGE_MODAL, value)
|
||||
},
|
||||
search: async ({ commit, rootState }, name: string): Promise<Array<Account>> => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<Array<Account>> = await client.get<Array<Account>>('/accounts/search', {
|
||||
q: name,
|
||||
following: true
|
||||
|
@ -46,7 +51,12 @@ const actions: ActionTree<AddListMemberState, RootState> = {
|
|||
return res.data
|
||||
},
|
||||
add: async ({ state, rootState }, account: Account): Promise<{}> => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<{}> = await client.post<{}>(`/lists/${state.targetListId}/accounts`, {
|
||||
account_ids: [account.id]
|
||||
})
|
||||
|
|
|
@ -47,13 +47,23 @@ const actions: ActionTree<ListMembershipState, RootState> = {
|
|||
commit(MUTATION_TYPES.CHANGE_ACCOUNT, account)
|
||||
},
|
||||
fetchListMembership: async ({ commit, rootState }, account: Account) => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<Array<List>> = await client.get<Array<List>>(`/accounts/${account.id}/lists`)
|
||||
commit(MUTATION_TYPES.CHANGE_BELONG_TO_LISTS, res.data.map(l => l.id))
|
||||
return res.data
|
||||
},
|
||||
fetchLists: async ({ commit, rootState }) => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<Array<List>> = await client.get<Array<List>>('/lists')
|
||||
commit(MUTATION_TYPES.CHANGE_LISTS, res.data)
|
||||
return res.data
|
||||
|
@ -63,7 +73,12 @@ const actions: ActionTree<ListMembershipState, RootState> = {
|
|||
const removedLists = lodash.difference(state.belongToLists, belongToLists)
|
||||
const addedLists = lodash.difference(belongToLists, state.belongToLists)
|
||||
commit(MUTATION_TYPES.CHANGE_BELONG_TO_LISTS, belongToLists)
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const removedPromise = removedLists.map(id => {
|
||||
return client.del<{}>(`/lists/${id}/accounts`, {
|
||||
account_ids: [state.account!.id]
|
||||
|
|
|
@ -34,7 +34,12 @@ const actions: ActionTree<MuteConfirmState, RootState> = {
|
|||
commit(MUTATION_TYPES.CHANGE_ACCOUNT, account)
|
||||
},
|
||||
submit: async ({ state, rootState, dispatch }, notify: boolean) => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<Relationship> = await client.post<Relationship>(`/accounts/${state.account!.id}/mute`, {
|
||||
notifications: notify
|
||||
})
|
||||
|
|
|
@ -172,7 +172,12 @@ const actions: ActionTree<NewTootState, RootState> = {
|
|||
if (rootState.TimelineSpace.account.accessToken === undefined || rootState.TimelineSpace.account.accessToken === null) {
|
||||
throw new AuthenticationError()
|
||||
}
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const attachments = Object.keys(mediaDescription).map(async id => {
|
||||
if (mediaDescription[id] !== null) {
|
||||
return client.put<Attachment>(`/media/${id}`, { description: mediaDescription[id] })
|
||||
|
@ -253,7 +258,12 @@ const actions: ActionTree<NewTootState, RootState> = {
|
|||
}
|
||||
|
||||
commit(MUTATION_TYPES.CHANGE_BLOCK_SUBMIT, true)
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
return client
|
||||
.post<Status>('/statuses', form)
|
||||
.then((res: Response<Status>) => {
|
||||
|
@ -305,7 +315,12 @@ const actions: ActionTree<NewTootState, RootState> = {
|
|||
if (rootState.TimelineSpace.account.accessToken === undefined || rootState.TimelineSpace.account.accessToken === null) {
|
||||
throw new AuthenticationError()
|
||||
}
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const formData = new FormData()
|
||||
formData.append('file', image)
|
||||
return client
|
||||
|
@ -342,7 +357,12 @@ const actions: ActionTree<NewTootState, RootState> = {
|
|||
}
|
||||
},
|
||||
fetchVisibility: async ({ commit, rootState }) => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<Account> = await client.get<Account>('/accounts/verify_credentials')
|
||||
const visibility: VisibilityType | undefined = (Object.values(Visibility) as Array<VisibilityType>).find(v => {
|
||||
return v.key === res.data.source!.privacy
|
||||
|
|
|
@ -165,7 +165,12 @@ const actions: ActionTree<StatusState, RootState> = {
|
|||
})
|
||||
}
|
||||
const searchAPI = async () => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
commit(MUTATION_TYPES.SET_CLIENT, client)
|
||||
const res: Response<Array<Account>> = await client.get<Array<Account>>('/accounts/search', { q: word, resolve: false })
|
||||
if (res.data.length === 0) throw new Error('Empty')
|
||||
|
@ -204,7 +209,12 @@ const actions: ActionTree<StatusState, RootState> = {
|
|||
})
|
||||
}
|
||||
const searchAPI = async () => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v2')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v2',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
commit(MUTATION_TYPES.SET_CLIENT, client)
|
||||
const res: Response<Results> = await client.get<Results>('/search', { q: word })
|
||||
if (res.data.hashtags.length === 0) throw new Error('Empty')
|
||||
|
|
|
@ -32,7 +32,12 @@ const actions: ActionTree<ReportState, RootState> = {
|
|||
commit(MUTATION_TYPES.CHANGE_MODAL_OPEN, true)
|
||||
},
|
||||
submit: async ({ rootState }, { account_id, status_id, comment }) => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
return client.post<{}>(`/reports`, {
|
||||
account_id: account_id,
|
||||
status_ids: [status_id],
|
||||
|
|
|
@ -80,14 +80,24 @@ const mutations: MutationTree<SideMenuState> = {
|
|||
const actions: ActionTree<SideMenuState, RootState> = {
|
||||
fetchLists: async ({ commit, rootState }, account: LocalAccount | null = null): Promise<Array<List>> => {
|
||||
if (account === null) account = rootState.TimelineSpace.account
|
||||
const client = new Mastodon(account!.accessToken!, account!.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
account!.accessToken!,
|
||||
account!.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<Array<List>> = await client.get<Array<List>>('/lists')
|
||||
commit(MUTATION_TYPES.UPDATE_LISTS, res.data)
|
||||
return res.data
|
||||
},
|
||||
fetchFollowRequests: async ({ commit, rootState }, account: LocalAccount | null = null): Promise<Array<Account>> => {
|
||||
if (account === null) account = rootState.TimelineSpace.account
|
||||
const client = new Mastodon(account!.accessToken!, account!.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
account!.accessToken!,
|
||||
account!.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<Array<Account>> = await client.get<Array<Account>>('/follow_requests')
|
||||
commit(MUTATION_TYPES.CHANGE_UNREAD_FOLLOW_REQUESTS, res.data.length > 0)
|
||||
return res.data
|
||||
|
|
|
@ -14,7 +14,12 @@ const state = (): TootState => ({})
|
|||
|
||||
const actions: ActionTree<TootState, RootState> = {
|
||||
reblog: async ({ rootState, dispatch }, message: Status) => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<Status> = await client.post<Status>(`/statuses/${message.id}/reblog`)
|
||||
// API returns new status when reblog.
|
||||
// Reblog target status is in the data.reblog.
|
||||
|
@ -24,42 +29,77 @@ const actions: ActionTree<TootState, RootState> = {
|
|||
return res.data.reblog
|
||||
},
|
||||
unreblog: async ({ rootState, dispatch }, message: Status) => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<Status> = await client.post<Status>(`/statuses/${message.id}/unreblog`)
|
||||
dispatch('TimelineSpace/updateTootForAllTimelines', res.data, { root: true })
|
||||
return res.data
|
||||
},
|
||||
addFavourite: async ({ rootState, dispatch }, message: Status) => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<Status> = await client.post<Status>(`/statuses/${message.id}/favourite`)
|
||||
ipcRenderer.send('fav-rt-action-sound')
|
||||
dispatch('TimelineSpace/updateTootForAllTimelines', res.data, { root: true })
|
||||
return res.data
|
||||
},
|
||||
removeFavourite: async ({ rootState, dispatch }, message: Status) => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res: Response<Status> = await client.post<Status>(`/statuses/${message.id}/unfavourite`)
|
||||
dispatch('TimelineSpace/updateTootForAllTimelines', res.data, { root: true })
|
||||
return res.data
|
||||
},
|
||||
deleteToot: async ({ rootState }, message: Status) => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
await client.del(`/statuses/${message.id}`)
|
||||
return message
|
||||
},
|
||||
block: async ({ rootState }, account: Account) => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
return client.post(`/accounts/${account.id}/block`)
|
||||
},
|
||||
vote: async ({ rootState }, params: VoteParam): Promise<Poll> => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res = await client.post<Poll>(`/polls/${params.id}/votes`, {
|
||||
choices: params.choices
|
||||
})
|
||||
return res.data
|
||||
},
|
||||
refresh: async ({ rootState }, id: string): Promise<Poll> => {
|
||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1',
|
||||
rootState.App.userAgent,
|
||||
rootState.App.proxyConfiguration
|
||||
)
|
||||
const res = await client.get<Poll>(`/polls/${id}`)
|
||||
return res.data
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue