diff --git a/src/constants/visibility/index.d.ts b/src/constants/visibility/index.d.ts index f1a063a0..0d5b2084 100644 --- a/src/constants/visibility/index.d.ts +++ b/src/constants/visibility/index.d.ts @@ -1,7 +1,7 @@ export type VisibilityType = { name: string value: number - key: string + key: 'public' | 'unlisted' | 'private' | 'direct' } export type VisibilityList = { diff --git a/src/renderer/store/Login.ts b/src/renderer/store/Login.ts index ca4f555f..cbdaead7 100644 --- a/src/renderer/store/Login.ts +++ b/src/renderer/store/Login.ts @@ -1,4 +1,4 @@ -import Mastodon, { Instance } from 'megalodon' +import { detector } from 'megalodon' import { Module, MutationTree, ActionTree } from 'vuex' import { RootState } from '@/store' import { MyWindow } from '~/src/types/global' @@ -49,24 +49,8 @@ const actions: ActionTree = { confirmInstance: async ({ commit, rootState }, domain: string): Promise => { commit(MUTATION_TYPES.CHANGE_SEARCHING, true) const cleanDomain = domain.trim() - try { - await Mastodon.get('/api/v1/instance', {}, `https://${cleanDomain}`, rootState.App.proxyConfiguration) - commit(MUTATION_TYPES.CHANGE_SEARCHING, false) - } catch (err) { - // https://gist.github.com/okapies/60d62d0df0163bbfb4ab09c1766558e8 - // Check /.well-known/host-meta to confirm mastodon instance. - const res = await Mastodon.get('/.well-known/host-meta', {}, `https://${cleanDomain}`, rootState.App.proxyConfiguration).finally( - () => { - commit(MUTATION_TYPES.CHANGE_SEARCHING, false) - } - ) - const parser = new DOMParser() - const dom = parser.parseFromString(res.data, 'text/xml') - const link = dom.getElementsByTagName('Link')[0].outerHTML - if (!link.includes(`https://${cleanDomain}/.well-known/webfinger`)) { - throw new Error('domain is not activity pub') - } - } + await detector(`https://${cleanDomain}`, rootState.App.proxyConfiguration) + commit(MUTATION_TYPES.CHANGE_SEARCHING, false) commit(MUTATION_TYPES.CHANGE_INSTANCE, cleanDomain) return true } diff --git a/src/renderer/store/Settings/General.ts b/src/renderer/store/Settings/General.ts index 79d3dcea..8dc9279a 100644 --- a/src/renderer/store/Settings/General.ts +++ b/src/renderer/store/Settings/General.ts @@ -1,4 +1,4 @@ -import Mastodon, { Account } from 'megalodon' +import generator, { Entity } from 'megalodon' import { Module, MutationTree, ActionTree } from 'vuex' import Visibility, { VisibilityType } from '~/src/constants/visibility' import { RootState } from '@/store' @@ -28,14 +28,15 @@ const mutations: MutationTree = { } const actions: ActionTree = { - fetchSettings: async ({ commit, rootState }): Promise => { - const client = new Mastodon( - rootState.TimelineSpace.account.accessToken!, - rootState.TimelineSpace.account.baseURL + '/api/v1', + fetchSettings: async ({ commit, rootState }): Promise => { + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res = await client.get('/accounts/verify_credentials') + const res = await client.verifyAccountCredentials() const visibility: VisibilityType | undefined = (Object.values(Visibility) as Array).find(v => { return v.key === res.data.source!.privacy }) @@ -44,35 +45,29 @@ const actions: ActionTree = { 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 = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) const visibility: VisibilityType | undefined = (Object.values(Visibility) as Array).find(v => { return v.value === value }) - const res = await client.patch('/accounts/update_credentials', { - source: { - privacy: visibility!.key - } - }) + const res = await client.updateCredentials({ source: { privacy: visibility!.key } }) commit(MUTATION_TYPES.CHANGE_VISIBILITY, visibility!.value) 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 = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res = await client.patch('/accounts/update_credentials', { - source: { - sensitive: value - } - }) + const res = await client.updateCredentials({ source: { sensitive: value } }) commit(MUTATION_TYPES.CHANGE_SENSITIVE, value) return res.data } diff --git a/src/renderer/store/TimelineSpace.ts b/src/renderer/store/TimelineSpace.ts index ab75df58..f55dcab1 100644 --- a/src/renderer/store/TimelineSpace.ts +++ b/src/renderer/store/TimelineSpace.ts @@ -1,4 +1,4 @@ -import Mastodon, { Account, Emoji, Instance, Status, Notification as NotificationType } from 'megalodon' +import generator, { detector, Entity } from 'megalodon' import SideMenu, { SideMenuState } from './TimelineSpace/SideMenu' import HeaderMenu, { HeaderMenuState } from './TimelineSpace/HeaderMenu' import Modals, { ModalsModuleState } from './TimelineSpace/Modals' @@ -18,10 +18,10 @@ export type TimelineSpaceState = { account: LocalAccount bindingAccount: LocalAccount | null loading: boolean - emojis: Array + emojis: Array tootMax: number unreadNotification: UnreadNotification - pleroma: boolean + sns: 'mastodon' | 'pleroma' | 'misskey' } export const blankAccount: LocalAccount = { @@ -49,7 +49,7 @@ const state = (): TimelineSpaceState => ({ local: unreadSettings.Local.default, public: unreadSettings.Public.default }, - pleroma: false + sns: 'mastodon' }) export const MUTATION_TYPES = { @@ -59,7 +59,7 @@ export const MUTATION_TYPES = { UPDATE_EMOJIS: 'updateEmojis', UPDATE_TOOT_MAX: 'updateTootMax', UPDATE_UNREAD_NOTIFICATION: 'updateUnreadNotification', - CHANGE_PLEROMA: 'changePleroma' + CHANGE_SNS: 'changeSNS' } const mutations: MutationTree = { @@ -72,7 +72,7 @@ const mutations: MutationTree = { [MUTATION_TYPES.CHANGE_LOADING]: (state, value: boolean) => { state.loading = value }, - [MUTATION_TYPES.UPDATE_EMOJIS]: (state, emojis: Array) => { + [MUTATION_TYPES.UPDATE_EMOJIS]: (state, emojis: Array) => { state.emojis = emojis }, [MUTATION_TYPES.UPDATE_TOOT_MAX]: (state, value: number | null) => { @@ -85,8 +85,8 @@ const mutations: MutationTree = { [MUTATION_TYPES.UPDATE_UNREAD_NOTIFICATION]: (state, settings: UnreadNotification) => { state.unreadNotification = settings }, - [MUTATION_TYPES.CHANGE_PLEROMA]: (state, pleroma: boolean) => { - state.pleroma = pleroma + [MUTATION_TYPES.CHANGE_SNS]: (state, sns: 'mastodon' | 'pleroma' | 'misskey') => { + state.sns = sns } } @@ -99,7 +99,7 @@ const actions: ActionTree = { throw new AccountLoadError() }) - await dispatch('detectPleroma') + await dispatch('detectSNS') dispatch('TimelineSpace/SideMenu/fetchLists', account, { root: true }) dispatch('TimelineSpace/SideMenu/fetchFollowRequests', account, { root: true }) await dispatch('loadUnreadNotification', accountId) @@ -163,13 +163,9 @@ const actions: ActionTree = { commit(MUTATION_TYPES.UPDATE_ACCOUNT, blankAccount) return true }, - detectPleroma: async ({ commit, state, rootState }) => { - const res = await Mastodon.get('/instance', {}, state.account.baseURL + '/api/v1', rootState.App.proxyConfiguration) - if (res.data.version.includes('Pleroma')) { - commit(MUTATION_TYPES.CHANGE_PLEROMA, true) - } else { - commit(MUTATION_TYPES.CHANGE_PLEROMA, false) - } + detectSNS: async ({ commit, state, rootState }) => { + const sns = await detector(state.account.baseURL, rootState.App.proxyConfiguration) + commit(MUTATION_TYPES.CHANGE_SNS, sns) }, // ----------------------------------------------- // Shortcuts @@ -196,16 +192,18 @@ const actions: ActionTree = { /** * fetchEmojis */ - fetchEmojis: async ({ commit, rootState }, account: LocalAccount): Promise> => { - const res = await Mastodon.get>('/custom_emojis', {}, account.baseURL + '/api/v1', rootState.App.proxyConfiguration) + fetchEmojis: async ({ commit, state, rootState }, account: LocalAccount): Promise> => { + const client = generator(state.sns, account.baseURL, null, 'Whalebird', rootState.App.proxyConfiguration) + const res = await client.getInstanceCustomEmojis() commit(MUTATION_TYPES.UPDATE_EMOJIS, res.data) return res.data }, /** * fetchInstance */ - fetchInstance: async ({ commit, rootState }, account: LocalAccount) => { - const res = await Mastodon.get('/instance', {}, account.baseURL + '/api/v1', rootState.App.proxyConfiguration) + fetchInstance: async ({ commit, state, rootState }, account: LocalAccount) => { + const client = generator(state.sns, account.baseURL, null, 'Whalebird', rootState.App.proxyConfiguration) + const res = await client.getInstance() commit(MUTATION_TYPES.UPDATE_TOOT_MAX, res.data.max_toot_chars) return true }, @@ -299,7 +297,7 @@ const actions: ActionTree = { await dispatch('waitToUnbindUserStreaming') commit(MUTATION_TYPES.UPDATE_BINDING_ACCOUNT, state.account) - win.ipcRenderer.on(`update-start-all-user-streamings-${state.account._id!}`, (_, update: Status) => { + win.ipcRenderer.on(`update-start-all-user-streamings-${state.account._id!}`, (_, update: Entity.Status) => { commit('TimelineSpace/Contents/Home/appendTimeline', update, { root: true }) // Sometimes archive old statuses if (rootState.TimelineSpace.Contents.Home.heading && Math.random() > 0.8) { @@ -307,14 +305,14 @@ const actions: ActionTree = { } commit('TimelineSpace/SideMenu/changeUnreadHomeTimeline', true, { root: true }) }) - win.ipcRenderer.on(`notification-start-all-user-streamings-${state.account._id!}`, (_, notification: NotificationType) => { + win.ipcRenderer.on(`notification-start-all-user-streamings-${state.account._id!}`, (_, notification: Entity.Notification) => { commit('TimelineSpace/Contents/Notifications/appendNotifications', notification, { root: true }) if (rootState.TimelineSpace.Contents.Notifications.heading && Math.random() > 0.8) { commit('TimelineSpace/Contents/Notifications/archiveNotifications', null, { root: true }) } commit('TimelineSpace/SideMenu/changeUnreadNotifications', true, { root: true }) }) - win.ipcRenderer.on(`mention-start-all-user-streamings-${state.account._id!}`, (_, mention: NotificationType) => { + win.ipcRenderer.on(`mention-start-all-user-streamings-${state.account._id!}`, (_, mention: Entity.Notification) => { commit('TimelineSpace/Contents/Mentions/appendMentions', mention, { root: true }) if (rootState.TimelineSpace.Contents.Mentions.heading && Math.random() > 0.8) { commit('TimelineSpace/Contents/Mentions/archiveMentions', null, { root: true }) @@ -328,7 +326,7 @@ const actions: ActionTree = { }) }, bindLocalStreaming: ({ commit, rootState }) => { - win.ipcRenderer.on('update-start-local-streaming', (_, update: Status) => { + win.ipcRenderer.on('update-start-local-streaming', (_, update: Entity.Status) => { commit('TimelineSpace/Contents/Local/appendTimeline', update, { root: true }) if (rootState.TimelineSpace.Contents.Local.heading && Math.random() > 0.8) { commit('TimelineSpace/Contents/Local/archiveTimeline', {}, { root: true }) @@ -352,7 +350,7 @@ const actions: ActionTree = { }) }, bindPublicStreaming: ({ commit, rootState }) => { - win.ipcRenderer.on('update-start-public-streaming', (_, update: Status) => { + win.ipcRenderer.on('update-start-public-streaming', (_, update: Entity.Status) => { commit('TimelineSpace/Contents/Public/appendTimeline', update, { root: true }) if (rootState.TimelineSpace.Contents.Public.heading && Math.random() > 0.8) { commit('TimelineSpace/Contents/Public/archiveTimeline', {}, { root: true }) @@ -376,7 +374,7 @@ const actions: ActionTree = { }) }, bindDirectMessagesStreaming: ({ commit, rootState }) => { - win.ipcRenderer.on('update-start-directmessages-streaming', (_, update: Status) => { + win.ipcRenderer.on('update-start-directmessages-streaming', (_, update: Entity.Status) => { commit('TimelineSpace/Contents/DirectMessages/appendTimeline', update, { root: true }) if (rootState.TimelineSpace.Contents.DirectMessages.heading && Math.random() > 0.8) { commit('TimelineSpace/Contents/DirectMessages/archiveTimeline', {}, { root: true }) @@ -437,7 +435,7 @@ const actions: ActionTree = { stopDirectMessagesStreaming: () => { win.ipcRenderer.send('stop-directmessages-streaming') }, - updateTootForAllTimelines: ({ commit, state }, status: Status): boolean => { + updateTootForAllTimelines: ({ commit, state }, status: Entity.Status): boolean => { commit('TimelineSpace/Contents/Home/updateToot', status, { root: true }) commit('TimelineSpace/Contents/Notifications/updateToot', status, { root: true }) commit('TimelineSpace/Contents/Mentions/updateToot', status, { root: true }) diff --git a/src/renderer/store/TimelineSpace/Contents/DirectMessages.ts b/src/renderer/store/TimelineSpace/Contents/DirectMessages.ts index 3a51aa75..168e530d 100644 --- a/src/renderer/store/TimelineSpace/Contents/DirectMessages.ts +++ b/src/renderer/store/TimelineSpace/Contents/DirectMessages.ts @@ -1,12 +1,12 @@ -import Mastodon, { Status, Response, Conversation } from 'megalodon' +import generator, { Entity } from 'megalodon' import { Module, MutationTree, ActionTree } from 'vuex' import { RootState } from '@/store' export type DirectMessagesState = { lazyLoading: boolean heading: boolean - timeline: Array - unreadTimeline: Array + timeline: Array + unreadTimeline: Array filter: string } @@ -39,7 +39,7 @@ const mutations: MutationTree = { [MUTATION_TYPES.CHANGE_HEADING]: (state, value: boolean) => { state.heading = value }, - [MUTATION_TYPES.APPEND_TIMELINE]: (state, update: Status) => { + [MUTATION_TYPES.APPEND_TIMELINE]: (state, update: Entity.Status) => { // Reject duplicated status in timeline if (!state.timeline.find(item => item.id === update.id) && !state.unreadTimeline.find(item => item.id === update.id)) { if (state.heading) { @@ -49,14 +49,14 @@ const mutations: MutationTree = { } } }, - [MUTATION_TYPES.UPDATE_TIMELINE]: (state, messages: Array) => { + [MUTATION_TYPES.UPDATE_TIMELINE]: (state, messages: Array) => { state.timeline = messages }, [MUTATION_TYPES.MERGE_TIMELINE]: state => { state.timeline = state.unreadTimeline.slice(0, 80).concat(state.timeline) state.unreadTimeline = [] }, - [MUTATION_TYPES.INSERT_TIMELINE]: (state, messages: Array) => { + [MUTATION_TYPES.INSERT_TIMELINE]: (state, messages: Array) => { state.timeline = state.timeline.concat(messages) }, [MUTATION_TYPES.ARCHIVE_TIMELINE]: state => { @@ -66,7 +66,7 @@ const mutations: MutationTree = { state.timeline = [] state.unreadTimeline = [] }, - [MUTATION_TYPES.UPDATE_TOOT]: (state, message: Status) => { + [MUTATION_TYPES.UPDATE_TOOT]: (state, message: Entity.Status) => { // Replace target message in DirectMessagesTimeline and notifications state.timeline = state.timeline.map(toot => { if (toot.id === message.id) { @@ -98,33 +98,35 @@ const mutations: MutationTree = { } const actions: ActionTree = { - fetchTimeline: async ({ commit, rootState }): Promise> => { - const client = new Mastodon( - rootState.TimelineSpace.account.accessToken!, - rootState.TimelineSpace.account.baseURL + '/api/v1', + fetchTimeline: async ({ commit, rootState }): Promise> => { + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response> = await client.get>('/conversations', { limit: 40 }) - const statuses: Array = res.data.map(con => con.last_status!) + const res = await client.getConversationTimeline({ limit: 40 }) + const statuses: Array = res.data.map(con => con.last_status!) commit(MUTATION_TYPES.UPDATE_TIMELINE, statuses) return statuses }, - lazyFetchTimeline: ({ state, commit, rootState }, lastStatus: Status): Promise | null> => { + lazyFetchTimeline: ({ state, commit, rootState }, lastStatus: Entity.Status): Promise | null> => { if (state.lazyLoading) { 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 = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) return client - .get>('/conversations', { max_id: lastStatus.id, limit: 40 }) + .getConversationTimeline({ max_id: lastStatus.id, limit: 40 }) .then(res => { - const statuses: Array = res.data.map(con => con.last_status!) + const statuses: Array = res.data.map(con => con.last_status!) commit(MUTATION_TYPES.INSERT_TIMELINE, statuses) return statuses }) diff --git a/src/renderer/store/TimelineSpace/Contents/Favourites.ts b/src/renderer/store/TimelineSpace/Contents/Favourites.ts index 1e2eff2e..6627184a 100644 --- a/src/renderer/store/TimelineSpace/Contents/Favourites.ts +++ b/src/renderer/store/TimelineSpace/Contents/Favourites.ts @@ -1,11 +1,11 @@ -import Mastodon, { Status, Response } from 'megalodon' +import generator, { Entity } from 'megalodon' import parse from 'parse-link-header' import { Module, MutationTree, ActionTree } from 'vuex' import { RootState } from '@/store' import { LocalAccount } from '~/src/types/localAccount' export type FavouritesState = { - favourites: Array + favourites: Array lazyLoading: boolean filter: string maxId: string | null @@ -29,13 +29,13 @@ export const MUTATION_TYPES = { } const mutations: MutationTree = { - [MUTATION_TYPES.UPDATE_FAVOURITES]: (state, favourites: Array) => { + [MUTATION_TYPES.UPDATE_FAVOURITES]: (state, favourites: Array) => { state.favourites = favourites }, - [MUTATION_TYPES.INSERT_FAVOURITES]: (state, favourites: Array) => { + [MUTATION_TYPES.INSERT_FAVOURITES]: (state, favourites: Array) => { state.favourites = state.favourites.concat(favourites) }, - [MUTATION_TYPES.UPDATE_TOOT]: (state, message: Status) => { + [MUTATION_TYPES.UPDATE_TOOT]: (state, message: Entity.Status) => { state.favourites = state.favourites.map(toot => { if (toot.id === message.id) { return message @@ -51,7 +51,7 @@ const mutations: MutationTree = { } }) }, - [MUTATION_TYPES.DELETE_TOOT]: (state, message: Status) => { + [MUTATION_TYPES.DELETE_TOOT]: (state, message: Entity.Status) => { state.favourites = state.favourites.filter(toot => { if (toot.reblog !== null && toot.reblog.id === message.id) { return false @@ -72,14 +72,15 @@ const mutations: MutationTree = { } const actions: ActionTree = { - fetchFavourites: async ({ commit, rootState }, account: LocalAccount): Promise> => { - const client = new Mastodon( - account.accessToken!, - account.baseURL + '/api/v1', + fetchFavourites: async ({ commit, rootState }, account: LocalAccount): Promise> => { + const client = generator( + rootState.TimelineSpace.sns, + account.baseURL, + account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response> = await client.get>('/favourites', { limit: 40 }) + const res = await client.getFavourites({ limit: 40 }) commit(MUTATION_TYPES.UPDATE_FAVOURITES, res.data) // Parse link header try { @@ -95,7 +96,7 @@ const actions: ActionTree = { } return res.data }, - lazyFetchFavourites: async ({ state, commit, rootState }): Promise | null> => { + lazyFetchFavourites: async ({ state, commit, rootState }): Promise | null> => { if (state.lazyLoading) { return Promise.resolve(null) } @@ -103,13 +104,14 @@ const actions: ActionTree = { 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 = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response> = await client.get>('/favourites', { max_id: state.maxId, limit: 40 }).finally(() => { + const res = await client.getFavourites({ max_id: state.maxId, limit: 40 }).finally(() => { commit(MUTATION_TYPES.CHANGE_LAZY_LOADING, false) }) commit(MUTATION_TYPES.INSERT_FAVOURITES, res.data) diff --git a/src/renderer/store/TimelineSpace/Contents/FollowRequests.ts b/src/renderer/store/TimelineSpace/Contents/FollowRequests.ts index ddaf25a5..93b39690 100644 --- a/src/renderer/store/TimelineSpace/Contents/FollowRequests.ts +++ b/src/renderer/store/TimelineSpace/Contents/FollowRequests.ts @@ -1,9 +1,9 @@ -import Mastodon, { Account, Response } from 'megalodon' +import generator, { Entity } from 'megalodon' import { Module, MutationTree, ActionTree } from 'vuex' import { RootState } from '@/store' export type FollowRequestsState = { - requests: Array + requests: Array } const state = (): FollowRequestsState => ({ @@ -15,43 +15,46 @@ export const MUTATION_TYPES = { } const mutations: MutationTree = { - [MUTATION_TYPES.UPDATE_REQUESTS]: (state, accounts: Array) => { + [MUTATION_TYPES.UPDATE_REQUESTS]: (state, accounts: Array) => { state.requests = accounts } } const actions: ActionTree = { - fetchRequests: async ({ commit, rootState }): Promise> => { - const client = new Mastodon( - rootState.TimelineSpace.account.accessToken!, - rootState.TimelineSpace.account.baseURL + '/api/v1', + fetchRequests: async ({ commit, rootState }): Promise> => { + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response> = await client.get>('/follow_requests') + const res = await client.getFollowRequests() 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', + acceptRequest: async ({ dispatch, rootState }, user: Entity.Account) => { + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response<{}> = await client.post<{}>(`/follow_requests/${user.id}/authorize`) + const res = await client.acceptFollowRequest(user.id) 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', + rejectRequest: async ({ dispatch, rootState }, user: Entity.Account) => { + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response<{}> = await client.post<{}>(`/follow_requests/${user.id}/reject`) + const res = await client.rejectFollowRequest(user.id) await dispatch('fetchRequests') dispatch('TimelineSpace/SideMenu/fetchFollowRequests', rootState.TimelineSpace.account, { root: true }) return res.data diff --git a/src/renderer/store/TimelineSpace/Contents/Hashtag/Tag.ts b/src/renderer/store/TimelineSpace/Contents/Hashtag/Tag.ts index e4b27e54..3e250815 100644 --- a/src/renderer/store/TimelineSpace/Contents/Hashtag/Tag.ts +++ b/src/renderer/store/TimelineSpace/Contents/Hashtag/Tag.ts @@ -1,4 +1,4 @@ -import Mastodon, { Status, Response } from 'megalodon' +import generator, { Entity } from 'megalodon' import { Module, MutationTree, ActionTree } from 'vuex' import { RootState } from '@/store' import { LoadPositionWithTag } from '@/types/loadPosition' @@ -7,8 +7,8 @@ import { MyWindow } from '~/src/types/global' const win = window as MyWindow export type TagState = { - timeline: Array - unreadTimeline: Array + timeline: Array + unreadTimeline: Array lazyLoading: boolean heading: boolean filter: string @@ -40,7 +40,7 @@ const mutations: MutationTree = { [MUTATION_TYPES.CHANGE_HEADING]: (state, value: boolean) => { state.heading = value }, - [MUTATION_TYPES.APPEND_TIMELINE]: (state, update: Status) => { + [MUTATION_TYPES.APPEND_TIMELINE]: (state, update: Entity.Status) => { // Reject duplicated status in timeline if (!state.timeline.find(item => item.id === update.id) && !state.unreadTimeline.find(item => item.id === update.id)) { if (state.heading) { @@ -50,14 +50,14 @@ const mutations: MutationTree = { } } }, - [MUTATION_TYPES.UPDATE_TIMELINE]: (state, timeline: Array) => { + [MUTATION_TYPES.UPDATE_TIMELINE]: (state, timeline: Array) => { state.timeline = timeline }, [MUTATION_TYPES.MERGE_TIMELINE]: state => { state.timeline = state.unreadTimeline.slice(0, 80).concat(state.timeline) state.unreadTimeline = [] }, - [MUTATION_TYPES.INSERT_TIMELINE]: (state, messages: Array) => { + [MUTATION_TYPES.INSERT_TIMELINE]: (state, messages: Array) => { state.timeline = state.timeline.concat(messages) }, [MUTATION_TYPES.ARCHIVE_TIMELINE]: state => { @@ -67,7 +67,7 @@ const mutations: MutationTree = { state.timeline = [] state.unreadTimeline = [] }, - [MUTATION_TYPES.UPDATE_TOOT]: (state, message: Status) => { + [MUTATION_TYPES.UPDATE_TOOT]: (state, message: Entity.Status) => { state.timeline = state.timeline.map(toot => { if (toot.id === message.id) { return message @@ -101,19 +101,20 @@ const mutations: MutationTree = { } const actions: ActionTree = { - fetch: async ({ commit, rootState }, tag: string): Promise> => { - const client = new Mastodon( - rootState.TimelineSpace.account.accessToken!, - rootState.TimelineSpace.account.baseURL + '/api/v1', + fetch: async ({ commit, rootState }, tag: string): Promise> => { + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response> = await client.get>(`/timelines/tag/${encodeURIComponent(tag)}`, { limit: 40 }) + const res = await client.getTagTimeline(encodeURIComponent(tag), { limit: 40 }) commit(MUTATION_TYPES.UPDATE_TIMELINE, res.data) return res.data }, startStreaming: ({ state, commit, rootState }, tag: string) => { - win.ipcRenderer.on('update-start-tag-streaming', (_, update: Status) => { + win.ipcRenderer.on('update-start-tag-streaming', (_, update: Entity.Status) => { commit(MUTATION_TYPES.APPEND_TIMELINE, update) if (state.heading && Math.random() > 0.8) { commit(MUTATION_TYPES.ARCHIVE_TIMELINE) @@ -148,14 +149,15 @@ const actions: ActionTree = { 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 = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) return client - .get>(`/timelines/tag/${loadPosition.tag}`, { max_id: loadPosition.status.id, limit: 40 }) + .getTagTimeline(loadPosition.tag, { max_id: loadPosition.status.id, limit: 40 }) .then(res => { commit(MUTATION_TYPES.INSERT_TIMELINE, res.data) return res.data diff --git a/src/renderer/store/TimelineSpace/Contents/Home.ts b/src/renderer/store/TimelineSpace/Contents/Home.ts index 5518ab54..048156d6 100644 --- a/src/renderer/store/TimelineSpace/Contents/Home.ts +++ b/src/renderer/store/TimelineSpace/Contents/Home.ts @@ -1,4 +1,4 @@ -import Mastodon, { Status, Response } from 'megalodon' +import generator, { Entity } from 'megalodon' import { Module, MutationTree, ActionTree } from 'vuex' import { RootState } from '@/store' @@ -7,8 +7,8 @@ export type HomeState = { heading: boolean showReblogs: boolean showReplies: boolean - timeline: Array - unreadTimeline: Array + timeline: Array + unreadTimeline: Array filter: string } @@ -45,7 +45,7 @@ const mutations: MutationTree = { [MUTATION_TYPES.CHANGE_HEADING]: (state, value: boolean) => { state.heading = value }, - [MUTATION_TYPES.APPEND_TIMELINE]: (state, update: Status) => { + [MUTATION_TYPES.APPEND_TIMELINE]: (state, update: Entity.Status) => { // Reject duplicated status in timeline if (!state.timeline.find(item => item.id === update.id) && !state.unreadTimeline.find(item => item.id === update.id)) { if (state.heading) { @@ -55,14 +55,14 @@ const mutations: MutationTree = { } } }, - [MUTATION_TYPES.UPDATE_TIMELINE]: (state, messages: Array) => { + [MUTATION_TYPES.UPDATE_TIMELINE]: (state, messages: Array) => { state.timeline = messages }, [MUTATION_TYPES.MERGE_TIMELINE]: state => { state.timeline = state.unreadTimeline.slice(0, 80).concat(state.timeline) state.unreadTimeline = [] }, - [MUTATION_TYPES.INSERT_TIMELINE]: (state, messages: Array) => { + [MUTATION_TYPES.INSERT_TIMELINE]: (state, messages: Array) => { state.timeline = state.timeline.concat(messages) }, [MUTATION_TYPES.ARCHIVE_TIMELINE]: state => { @@ -72,7 +72,7 @@ const mutations: MutationTree = { state.timeline = [] state.unreadTimeline = [] }, - [MUTATION_TYPES.UPDATE_TOOT]: (state, message: Status) => { + [MUTATION_TYPES.UPDATE_TOOT]: (state, message: Entity.Status) => { // Replace target message in homeTimeline and notifications state.timeline = state.timeline.map(toot => { if (toot.id === message.id) { @@ -111,29 +111,31 @@ const mutations: MutationTree = { const actions: ActionTree = { fetchTimeline: async ({ commit, rootState }) => { - const client = new Mastodon( - rootState.TimelineSpace.account.accessToken!, - rootState.TimelineSpace.account.baseURL + '/api/v1', + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response> = await client.get>('/timelines/home', { limit: 40 }) + const res = await client.getHomeTimeline({ limit: 40 }) commit(MUTATION_TYPES.UPDATE_TIMELINE, res.data) return res.data }, - lazyFetchTimeline: async ({ state, commit, rootState }, lastStatus: Status): Promise | null> => { + lazyFetchTimeline: async ({ state, commit, rootState }, lastStatus: Entity.Status): Promise | null> => { if (state.lazyLoading) { 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 = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) return client - .get>('/timelines/home', { max_id: lastStatus.id, limit: 40 }) + .getHomeTimeline({ max_id: lastStatus.id, limit: 40 }) .then(res => { commit(MUTATION_TYPES.INSERT_TIMELINE, res.data) return res.data diff --git a/src/renderer/store/TimelineSpace/Contents/Lists/Edit.ts b/src/renderer/store/TimelineSpace/Contents/Lists/Edit.ts index a61a9ba8..2eb30e02 100644 --- a/src/renderer/store/TimelineSpace/Contents/Lists/Edit.ts +++ b/src/renderer/store/TimelineSpace/Contents/Lists/Edit.ts @@ -1,10 +1,10 @@ -import Mastodon, { Account, Response } from 'megalodon' +import generator, { Entity } from 'megalodon' import { Module, MutationTree, ActionTree } from 'vuex' import { RootState } from '@/store' import { RemoveAccountFromList } from '@/types/removeAccountFromList' export type EditState = { - members: Array + members: Array } const state = (): EditState => ({ @@ -16,35 +16,33 @@ export const MUTATION_TYPES = { } const mutations: MutationTree = { - [MUTATION_TYPES.CHANGE_MEMBERS]: (state, members: Array) => { + [MUTATION_TYPES.CHANGE_MEMBERS]: (state, members: Array) => { state.members = members } } const actions: ActionTree = { - fetchMembers: async ({ commit, rootState }, listId: string): Promise> => { - const client = new Mastodon( - rootState.TimelineSpace.account.accessToken!, - rootState.TimelineSpace.account.baseURL + '/api/v1', + fetchMembers: async ({ commit, rootState }, listId: string): Promise> => { + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response> = await client.get>(`/lists/${listId}/accounts`, { - limit: 0 - }) + const res = await client.getAccountsInList(listId, { limit: 0 }) commit(MUTATION_TYPES.CHANGE_MEMBERS, res.data) 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 = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - return client.del<{}>(`/lists/${remove.listId}/accounts`, { - account_ids: [remove.account.id] - }) + return client.deleteAccountsFromList(remove.listId, [remove.account.id]) } } diff --git a/src/renderer/store/TimelineSpace/Contents/Lists/Index.ts b/src/renderer/store/TimelineSpace/Contents/Lists/Index.ts index d98cfae1..d763cf71 100644 --- a/src/renderer/store/TimelineSpace/Contents/Lists/Index.ts +++ b/src/renderer/store/TimelineSpace/Contents/Lists/Index.ts @@ -1,9 +1,9 @@ -import Mastodon, { List, Response } from 'megalodon' +import generator, { Entity } from 'megalodon' import { Module, MutationTree, ActionTree } from 'vuex' import { RootState } from '@/store' export type IndexState = { - lists: Array + lists: Array } const state = (): IndexState => ({ @@ -15,33 +15,33 @@ export const MUTATION_TYPES = { } const mutations: MutationTree = { - [MUTATION_TYPES.CHANGE_LISTS]: (state, lists: Array) => { + [MUTATION_TYPES.CHANGE_LISTS]: (state, lists: Array) => { state.lists = lists } } const actions: ActionTree = { - fetchLists: async ({ commit, rootState }): Promise> => { - const client = new Mastodon( - rootState.TimelineSpace.account.accessToken!, - rootState.TimelineSpace.account.baseURL + '/api/v1', + fetchLists: async ({ commit, rootState }): Promise> => { + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response> = await client.get>('/lists') + const res = await client.getLists() commit(MUTATION_TYPES.CHANGE_LISTS, res.data) return res.data }, - createList: async ({ rootState }, title: string): Promise => { - const client = new Mastodon( - rootState.TimelineSpace.account.accessToken!, - rootState.TimelineSpace.account.baseURL + '/api/v1', + createList: async ({ rootState }, title: string): Promise => { + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response = await client.post('/lists', { - title: title - }) + const res = await client.createList(title) return res.data } } diff --git a/src/renderer/store/TimelineSpace/Contents/Lists/Show.ts b/src/renderer/store/TimelineSpace/Contents/Lists/Show.ts index 770ebb2c..0ad24fad 100644 --- a/src/renderer/store/TimelineSpace/Contents/Lists/Show.ts +++ b/src/renderer/store/TimelineSpace/Contents/Lists/Show.ts @@ -1,4 +1,4 @@ -import Mastodon, { Status, Response } from 'megalodon' +import generator, { Entity } from 'megalodon' import { Module, MutationTree, ActionTree } from 'vuex' import { RootState } from '@/store' import { LoadPositionWithList } from '@/types/loadPosition' @@ -7,8 +7,8 @@ import { MyWindow } from '~/src/types/global' const win = window as MyWindow export type ShowState = { - timeline: Array - unreadTimeline: Array + timeline: Array + unreadTimeline: Array lazyLoading: boolean heading: boolean filter: string @@ -40,7 +40,7 @@ const mutations: MutationTree = { [MUTATION_TYPES.CHANGE_HEADING]: (state, value: boolean) => { state.heading = value }, - [MUTATION_TYPES.APPEND_TIMELINE]: (state, update: Status) => { + [MUTATION_TYPES.APPEND_TIMELINE]: (state, update: Entity.Status) => { // Reject duplicated status in timeline if (!state.timeline.find(item => item.id === update.id) && !state.unreadTimeline.find(item => item.id === update.id)) { if (state.heading) { @@ -50,14 +50,14 @@ const mutations: MutationTree = { } } }, - [MUTATION_TYPES.UPDATE_TIMELINE]: (state, timeline: Array) => { + [MUTATION_TYPES.UPDATE_TIMELINE]: (state, timeline: Array) => { state.timeline = timeline }, [MUTATION_TYPES.MERGE_TIMELINE]: state => { state.timeline = state.unreadTimeline.slice(0, 80).concat(state.timeline) state.unreadTimeline = [] }, - [MUTATION_TYPES.INSERT_TIMELINE]: (state, messages: Array) => { + [MUTATION_TYPES.INSERT_TIMELINE]: (state, messages: Array) => { state.timeline = state.timeline.concat(messages) }, [MUTATION_TYPES.ARCHIVE_TIMELINE]: state => { @@ -67,7 +67,7 @@ const mutations: MutationTree = { state.timeline = [] state.unreadTimeline = [] }, - [MUTATION_TYPES.UPDATE_TOOT]: (state, message: Status) => { + [MUTATION_TYPES.UPDATE_TOOT]: (state, message: Entity.Status) => { state.timeline = state.timeline.map(toot => { if (toot.id === message.id) { return message @@ -101,19 +101,20 @@ const mutations: MutationTree = { } const actions: ActionTree = { - fetchTimeline: async ({ commit, rootState }, listID: string): Promise> => { - const client = new Mastodon( - rootState.TimelineSpace.account.accessToken!, - rootState.TimelineSpace.account.baseURL + '/api/v1', + fetchTimeline: async ({ commit, rootState }, listID: string): Promise> => { + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response> = await client.get>(`/timelines/list/${listID}`, { limit: 40 }) + const res = await client.getListTimeline(listID, { limit: 40 }) commit(MUTATION_TYPES.UPDATE_TIMELINE, res.data) return res.data }, startStreaming: ({ state, commit, rootState }, listID: string) => { - win.ipcRenderer.on('update-start-list-streaming', (_, update: Status) => { + win.ipcRenderer.on('update-start-list-streaming', (_, update: Entity.Status) => { commit(MUTATION_TYPES.APPEND_TIMELINE, update) if (state.heading && Math.random() > 0.8) { commit(MUTATION_TYPES.ARCHIVE_TIMELINE) @@ -143,19 +144,20 @@ const actions: ActionTree = { resolve() }) }, - lazyFetchTimeline: async ({ state, commit, rootState }, loadPosition: LoadPositionWithList): Promise | null> => { + lazyFetchTimeline: async ({ state, commit, rootState }, loadPosition: LoadPositionWithList): Promise | null> => { if (state.lazyLoading) { 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 = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) return client - .get>(`/timelines/list/${loadPosition.list_id}`, { max_id: loadPosition.status.id, limit: 40 }) + .getListTimeline(loadPosition.list_id, { max_id: loadPosition.status.id, limit: 40 }) .then(res => { commit(MUTATION_TYPES.INSERT_TIMELINE, res.data) return res.data diff --git a/src/renderer/store/TimelineSpace/Contents/Local.ts b/src/renderer/store/TimelineSpace/Contents/Local.ts index 3e988789..82153ab3 100644 --- a/src/renderer/store/TimelineSpace/Contents/Local.ts +++ b/src/renderer/store/TimelineSpace/Contents/Local.ts @@ -1,10 +1,10 @@ -import Mastodon, { Status, Response } from 'megalodon' +import generator, { Entity } from 'megalodon' import { Module, MutationTree, ActionTree } from 'vuex' import { RootState } from '@/store' export type LocalState = { - timeline: Array - unreadTimeline: Array + timeline: Array + unreadTimeline: Array lazyLoading: boolean heading: boolean filter: string @@ -36,7 +36,7 @@ const mutations: MutationTree = { [MUTATION_TYPES.CHANGE_HEADING]: (state, value: boolean) => { state.heading = value }, - [MUTATION_TYPES.APPEND_TIMELINE]: (state, update: Status) => { + [MUTATION_TYPES.APPEND_TIMELINE]: (state, update: Entity.Status) => { // Reject duplicated status in timeline if (!state.timeline.find(item => item.id === update.id) && !state.unreadTimeline.find(item => item.id === update.id)) { if (state.heading) { @@ -46,14 +46,14 @@ const mutations: MutationTree = { } } }, - [MUTATION_TYPES.UPDATE_TIMELINE]: (state, messages: Array) => { + [MUTATION_TYPES.UPDATE_TIMELINE]: (state, messages: Array) => { state.timeline = messages }, [MUTATION_TYPES.MERGE_TIMELINE]: state => { state.timeline = state.unreadTimeline.slice(0, 80).concat(state.timeline) state.unreadTimeline = [] }, - [MUTATION_TYPES.INSERT_TIMELINE]: (state, messages: Array) => { + [MUTATION_TYPES.INSERT_TIMELINE]: (state, messages: Array) => { state.timeline = state.timeline.concat(messages) }, [MUTATION_TYPES.ARCHIVE_TIMELINE]: state => { @@ -63,7 +63,7 @@ const mutations: MutationTree = { state.timeline = [] state.unreadTimeline = [] }, - [MUTATION_TYPES.UPDATE_TOOT]: (state, message: Status) => { + [MUTATION_TYPES.UPDATE_TOOT]: (state, message: Entity.Status) => { state.timeline = state.timeline.map(toot => { if (toot.id === message.id) { return message @@ -97,30 +97,32 @@ const mutations: MutationTree = { } const actions: ActionTree = { - fetchLocalTimeline: async ({ commit, rootState }): Promise> => { - const client = new Mastodon( - rootState.TimelineSpace.account.accessToken!, - rootState.TimelineSpace.account.baseURL + '/api/v1', + fetchLocalTimeline: async ({ commit, rootState }): Promise> => { + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response> = await client.get>('/timelines/public', { limit: 40, local: true }) + const res = await client.getLocalTimeline({ limit: 40 }) commit(MUTATION_TYPES.UPDATE_TIMELINE, res.data) return res.data }, - lazyFetchTimeline: async ({ state, commit, rootState }, lastStatus: Status): Promise | null> => { + lazyFetchTimeline: async ({ state, commit, rootState }, lastStatus: Entity.Status): Promise | null> => { if (state.lazyLoading) { 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 = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) return client - .get>('/timelines/public', { max_id: lastStatus.id, limit: 40, local: true }) + .getLocalTimeline({ max_id: lastStatus.id, limit: 40 }) .then(res => { commit(MUTATION_TYPES.INSERT_TIMELINE, res.data) return res.data diff --git a/src/renderer/store/TimelineSpace/Contents/Mentions.ts b/src/renderer/store/TimelineSpace/Contents/Mentions.ts index 58ace721..e0754de1 100644 --- a/src/renderer/store/TimelineSpace/Contents/Mentions.ts +++ b/src/renderer/store/TimelineSpace/Contents/Mentions.ts @@ -1,12 +1,12 @@ -import Mastodon, { Notification, Response } from 'megalodon' +import generator, { Entity, NotificationType } from 'megalodon' import { Module, MutationTree, ActionTree, GetterTree } from 'vuex' import { RootState } from '@/store' export type MentionsState = { lazyLoading: boolean heading: boolean - mentions: Array - unreadMentions: Array + mentions: Array + unreadMentions: Array filter: string } @@ -39,7 +39,7 @@ const mutations: MutationTree = { [MUTATION_TYPES.CHANGE_HEADING]: (state, value: boolean) => { state.heading = value }, - [MUTATION_TYPES.APPEND_MENTIONS]: (state, update: Notification) => { + [MUTATION_TYPES.APPEND_MENTIONS]: (state, update: Entity.Notification) => { // Reject duplicated status in timeline if (!state.mentions.find(item => item.id === update.id) && !state.unreadMentions.find(item => item.id === update.id)) { if (state.heading) { @@ -49,14 +49,14 @@ const mutations: MutationTree = { } } }, - [MUTATION_TYPES.UPDATE_MENTIONS]: (state, messages: Array) => { + [MUTATION_TYPES.UPDATE_MENTIONS]: (state, messages: Array) => { state.mentions = messages }, [MUTATION_TYPES.MERGE_MENTIONS]: state => { state.mentions = state.unreadMentions.slice(0, 80).concat(state.mentions) state.unreadMentions = [] }, - [MUTATION_TYPES.INSERT_MENTIONS]: (state, messages: Array) => { + [MUTATION_TYPES.INSERT_MENTIONS]: (state, messages: Array) => { state.mentions = state.mentions.concat(messages) }, [MUTATION_TYPES.ARCHIVE_MENTIONS]: state => { @@ -66,9 +66,9 @@ const mutations: MutationTree = { state.mentions = [] state.unreadMentions = [] }, - [MUTATION_TYPES.UPDATE_TOOT]: (state, message: Notification) => { + [MUTATION_TYPES.UPDATE_TOOT]: (state, message: Entity.Notification) => { state.mentions = state.mentions.map(mention => { - if (mention.status !== null && mention.status.id === message.id) { + if (mention.status !== undefined && mention.status.id === message.id) { const status = { status: message } @@ -97,33 +97,39 @@ const mutations: MutationTree = { } const actions: ActionTree = { - fetchMentions: async ({ commit, rootState }): Promise> => { - const client = new Mastodon( - rootState.TimelineSpace.account.accessToken!, - rootState.TimelineSpace.account.baseURL + '/api/v1', + fetchMentions: async ({ commit, rootState }): Promise> => { + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response> = await client.get>('/notifications', { + const res = await client.getNotifications({ limit: 30, - exclude_types: ['follow', 'favourite', 'reblog'] + exclude_types: [NotificationType.Follow, NotificationType.Favourite, NotificationType.Reblog, NotificationType.Poll] }) commit(MUTATION_TYPES.UPDATE_MENTIONS, res.data) return res.data }, - lazyFetchMentions: async ({ state, commit, rootState }, lastMention: Notification): Promise | null> => { + lazyFetchMentions: async ({ state, commit, rootState }, lastMention: Entity.Notification): Promise | null> => { if (state.lazyLoading) { 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 = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) return client - .get>('/notifications', { max_id: lastMention.id, limit: 30, exclude_types: ['follow', 'favourite', 'reblog'] }) + .getNotifications({ + max_id: lastMention.id, + limit: 30, + exclude_types: [NotificationType.Follow, NotificationType.Favourite, NotificationType.Reblog, NotificationType.Poll] + }) .then(res => { commit(MUTATION_TYPES.INSERT_MENTIONS, res.data) return res.data diff --git a/src/renderer/store/TimelineSpace/Contents/Notifications.ts b/src/renderer/store/TimelineSpace/Contents/Notifications.ts index c4c4a50f..eb4c99f6 100644 --- a/src/renderer/store/TimelineSpace/Contents/Notifications.ts +++ b/src/renderer/store/TimelineSpace/Contents/Notifications.ts @@ -1,4 +1,4 @@ -import Mastodon, { Notification, Status, Response } from 'megalodon' +import generator, { Entity } from 'megalodon' import { Module, MutationTree, ActionTree } from 'vuex' import { RootState } from '@/store' import { MyWindow } from '~/src/types/global' @@ -8,8 +8,8 @@ const win = window as MyWindow export type NotificationsState = { lazyLoading: boolean heading: boolean - notifications: Array - unreadNotifications: Array + notifications: Array + unreadNotifications: Array filter: string } @@ -42,7 +42,7 @@ const mutations: MutationTree = { [MUTATION_TYPES.CHANGE_HEADING]: (state, value: boolean) => { state.heading = value }, - [MUTATION_TYPES.APPEND_NOTIFICATIONS]: (state, notification: Notification) => { + [MUTATION_TYPES.APPEND_NOTIFICATIONS]: (state, notification: Entity.Notification) => { // Reject duplicated status in timeline if ( !state.notifications.find(item => item.id === notification.id) && @@ -55,17 +55,17 @@ const mutations: MutationTree = { } } }, - [MUTATION_TYPES.UPDATE_NOTIFICATIONS]: (state, notifications: Array) => { + [MUTATION_TYPES.UPDATE_NOTIFICATIONS]: (state, notifications: Array) => { state.notifications = notifications }, [MUTATION_TYPES.MERGE_NOTIFICATIONS]: state => { state.notifications = state.unreadNotifications.slice(0, 80).concat(state.notifications) state.unreadNotifications = [] }, - [MUTATION_TYPES.INSERT_NOTIFICATIONS]: (state, notifications: Array) => { + [MUTATION_TYPES.INSERT_NOTIFICATIONS]: (state, notifications: Array) => { state.notifications = state.notifications.concat(notifications) }, - [MUTATION_TYPES.UPDATE_TOOT]: (state, message: Status) => { + [MUTATION_TYPES.UPDATE_TOOT]: (state, message: Entity.Status) => { state.notifications = state.notifications.map(notification => { // I want to update toot only mention. // Because Toot component don't use status information when other patterns. @@ -104,31 +104,35 @@ const mutations: MutationTree = { } const actions: ActionTree = { - fetchNotifications: async ({ commit, rootState }): Promise> => { - const client = new Mastodon( - rootState.TimelineSpace.account.accessToken!, - rootState.TimelineSpace.account.baseURL + '/api/v1', + fetchNotifications: async ({ commit, rootState }): Promise> => { + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response> = await client.get>('/notifications', { limit: 30 }) - + const res = await client.getNotifications({ limit: 30 }) commit(MUTATION_TYPES.UPDATE_NOTIFICATIONS, res.data) return res.data }, - lazyFetchNotifications: ({ state, commit, rootState }, lastNotification: Notification): Promise | null> => { + lazyFetchNotifications: ( + { state, commit, rootState }, + lastNotification: Entity.Notification + ): Promise | null> => { if (state.lazyLoading) { 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 = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) return client - .get>('/notifications', { max_id: lastNotification.id, limit: 30 }) + .getNotifications({ max_id: lastNotification.id, limit: 30 }) .then(res => { commit(MUTATION_TYPES.INSERT_NOTIFICATIONS, res.data) return res.data diff --git a/src/renderer/store/TimelineSpace/Contents/Public.ts b/src/renderer/store/TimelineSpace/Contents/Public.ts index 92931056..cb68428b 100644 --- a/src/renderer/store/TimelineSpace/Contents/Public.ts +++ b/src/renderer/store/TimelineSpace/Contents/Public.ts @@ -1,10 +1,10 @@ -import Mastodon, { Status, Response } from 'megalodon' +import generator, { Entity } from 'megalodon' import { Module, MutationTree, ActionTree } from 'vuex' import { RootState } from '@/store' export type PublicState = { - timeline: Array - unreadTimeline: Array + timeline: Array + unreadTimeline: Array lazyLoading: boolean heading: boolean filter: string @@ -36,7 +36,7 @@ const mutations: MutationTree = { [MUTATION_TYPES.CHANGE_HEADING]: (state, value: boolean) => { state.heading = value }, - [MUTATION_TYPES.APPEND_TIMELINE]: (state, update: Status) => { + [MUTATION_TYPES.APPEND_TIMELINE]: (state, update: Entity.Status) => { // Reject duplicated status in timeline if (!state.timeline.find(item => item.id === update.id) && !state.unreadTimeline.find(item => item.id === update.id)) { if (state.heading) { @@ -46,14 +46,14 @@ const mutations: MutationTree = { } } }, - [MUTATION_TYPES.UPDATE_TIMELINE]: (state, messages: Array) => { + [MUTATION_TYPES.UPDATE_TIMELINE]: (state, messages: Array) => { state.timeline = messages }, [MUTATION_TYPES.MERGE_TIMELINE]: state => { state.timeline = state.unreadTimeline.slice(0, 80).concat(state.timeline) state.unreadTimeline = [] }, - [MUTATION_TYPES.INSERT_TIMELINE]: (state, messages: Array) => { + [MUTATION_TYPES.INSERT_TIMELINE]: (state, messages: Array) => { state.timeline = state.timeline.concat(messages) }, [MUTATION_TYPES.ARCHIVE_TIMELINE]: state => { @@ -63,7 +63,7 @@ const mutations: MutationTree = { state.timeline = [] state.unreadTimeline = [] }, - [MUTATION_TYPES.UPDATE_TOOT]: (state, message: Status) => { + [MUTATION_TYPES.UPDATE_TOOT]: (state, message: Entity.Status) => { state.timeline = state.timeline.map(toot => { if (toot.id === message.id) { return message @@ -97,30 +97,32 @@ const mutations: MutationTree = { } const actions: ActionTree = { - fetchPublicTimeline: async ({ commit, rootState }): Promise> => { - const client = new Mastodon( - rootState.TimelineSpace.account.accessToken!, - rootState.TimelineSpace.account.baseURL + '/api/v1', + fetchPublicTimeline: async ({ commit, rootState }): Promise> => { + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response> = await client.get>('/timelines/public', { limit: 40 }) + const res = await client.getPublicTimeline({ limit: 40 }) commit(MUTATION_TYPES.UPDATE_TIMELINE, res.data) return res.data }, - lazyFetchTimeline: ({ state, commit, rootState }, lastStatus: Status): Promise | null> => { + lazyFetchTimeline: ({ state, commit, rootState }, lastStatus: Entity.Status): Promise | null> => { if (state.lazyLoading) { 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 = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) return client - .get>('/timelines/public', { max_id: lastStatus.id, limit: 40 }) + .getPublicTimeline({ max_id: lastStatus.id, limit: 40 }) .then(res => { commit(MUTATION_TYPES.INSERT_TIMELINE, res.data) return res.data diff --git a/src/renderer/store/TimelineSpace/Contents/Search/Account.ts b/src/renderer/store/TimelineSpace/Contents/Search/Account.ts index 96cfa228..ab8ab6a6 100644 --- a/src/renderer/store/TimelineSpace/Contents/Search/Account.ts +++ b/src/renderer/store/TimelineSpace/Contents/Search/Account.ts @@ -1,4 +1,4 @@ -import Mastodon, { Account } from 'megalodon' +import generator, { Entity } from 'megalodon' import { Module, MutationTree, ActionTree } from 'vuex' import { RootState } from '@/store' @@ -21,16 +21,17 @@ const mutations: MutationTree = { } const actions: ActionTree = { - search: async ({ commit, rootState }, query: string): Promise> => { + search: async ({ commit, rootState }, query: string): Promise> => { commit('TimelineSpace/Contents/changeLoading', true, { root: true }) - const client = new Mastodon( - rootState.TimelineSpace.account.accessToken!, - rootState.TimelineSpace.account.baseURL + '/api/v1', + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) return client - .get>('/accounts/search', { q: query, resolve: true }) + .searchAccount(query, { resolve: true }) .then(res => { commit(MUTATION_TYPES.UPDATE_RESULTS, res.data) return res.data diff --git a/src/renderer/store/TimelineSpace/Contents/Search/Tag.ts b/src/renderer/store/TimelineSpace/Contents/Search/Tag.ts index 4456a17b..80a44cf5 100644 --- a/src/renderer/store/TimelineSpace/Contents/Search/Tag.ts +++ b/src/renderer/store/TimelineSpace/Contents/Search/Tag.ts @@ -1,9 +1,9 @@ -import Mastodon, { Tag, Results } from 'megalodon' +import generator, { Entity } from 'megalodon' import { Module, MutationTree, ActionTree } from 'vuex' import { RootState } from '@/store' export type TagState = { - results: Array + results: Array } const state = (): TagState => ({ @@ -15,22 +15,23 @@ export const MUTATION_TYPES = { } const mutations: MutationTree = { - [MUTATION_TYPES.UPDATE_RESULTS]: (state, results: Array) => { + [MUTATION_TYPES.UPDATE_RESULTS]: (state, results: Array) => { state.results = results } } const actions: ActionTree = { - search: ({ commit, rootState }, query: string): Promise> => { + search: ({ commit, rootState }, query: string): Promise> => { commit('TimelineSpace/Contents/changeLoading', true, { root: true }) - const client = new Mastodon( - rootState.TimelineSpace.account.accessToken!, - rootState.TimelineSpace.account.baseURL + '/api/v2', + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) return client - .get('/search', { q: query, resolve: true }) + .search(query, 'hashtags', { resolve: true }) .then(res => { commit(MUTATION_TYPES.UPDATE_RESULTS, res.data.hashtags) return res.data.hashtags diff --git a/src/renderer/store/TimelineSpace/Contents/Search/Toots.ts b/src/renderer/store/TimelineSpace/Contents/Search/Toots.ts index 87b20f35..9826be0f 100644 --- a/src/renderer/store/TimelineSpace/Contents/Search/Toots.ts +++ b/src/renderer/store/TimelineSpace/Contents/Search/Toots.ts @@ -1,9 +1,9 @@ -import Mastodon, { Status, Results } from 'megalodon' +import generator, { Entity } from 'megalodon' import { Module, MutationTree, ActionTree } from 'vuex' import { RootState } from '@/store' export type TootsState = { - results: Array + results: Array } const state = (): TootsState => ({ @@ -15,22 +15,23 @@ export const MUTATION_TYPES = { } const mutations: MutationTree = { - [MUTATION_TYPES.UPDATE_RESULTS]: (state, results: Array) => { + [MUTATION_TYPES.UPDATE_RESULTS]: (state, results: Array) => { state.results = results } } const actions: ActionTree = { - search: ({ commit, rootState }, query: string): Promise> => { + search: ({ commit, rootState }, query: string): Promise> => { commit('TimelineSpace/Contents/changeLoading', true, { root: true }) - const client = new Mastodon( - rootState.TimelineSpace.account.accessToken!, - rootState.TimelineSpace.account.baseURL + '/api/v1', + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) return client - .get('/search', { q: query, resolve: true }) + .search(query, 'statuses', { resolve: true }) .then(res => { commit(MUTATION_TYPES.UPDATE_RESULTS, res.data.statuses) return res.data.statuses diff --git a/src/renderer/store/TimelineSpace/Contents/SideBar/AccountProfile.ts b/src/renderer/store/TimelineSpace/Contents/SideBar/AccountProfile.ts index 57242e64..9a3b86d1 100644 --- a/src/renderer/store/TimelineSpace/Contents/SideBar/AccountProfile.ts +++ b/src/renderer/store/TimelineSpace/Contents/SideBar/AccountProfile.ts @@ -1,4 +1,4 @@ -import Mastodon, { Account, Relationship, Response, Status, Context } from 'megalodon' +import generator, { Entity } from 'megalodon' import Timeline, { TimelineState } from './AccountProfile/Timeline' import Follows, { FollowsState } from './AccountProfile/Follows' import Followers, { FollowersState } from './AccountProfile/Followers' @@ -13,12 +13,12 @@ type ParsedAccount = { type SearchAccount = { parsedAccount: ParsedAccount - status: Status + status: Entity.Status } export type AccountProfileState = { - account: Account | null - relationship: Relationship | null + account: Entity.Account | null + relationship: Entity.Relationship | null loading: boolean } @@ -43,10 +43,10 @@ export const MUTATION_TYPES = { } const mutations: MutationTree = { - [MUTATION_TYPES.CHANGE_ACCOUNT]: (state, account: Account | null) => { + [MUTATION_TYPES.CHANGE_ACCOUNT]: (state, account: Entity.Account | null) => { state.account = account }, - [MUTATION_TYPES.CHANGE_RELATIONSHIP]: (state, relationship: Relationship | null) => { + [MUTATION_TYPES.CHANGE_RELATIONSHIP]: (state, relationship: Entity.Relationship | null) => { state.relationship = relationship }, [MUTATION_TYPES.CHANGE_LOADING]: (state, value: boolean) => { @@ -55,27 +55,29 @@ const mutations: MutationTree = { } const actions: ActionTree = { - fetchAccount: async ({ rootState }, accountID: string): Promise => { - const client = new Mastodon( - rootState.TimelineSpace.account.accessToken!, - rootState.TimelineSpace.account.baseURL + '/api/v1', + fetchAccount: async ({ rootState }, accountID: string): Promise => { + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response = await client.get(`/accounts/${accountID}`) + const res = await client.getAccount(accountID) return res.data }, - searchAccount: async ({ rootState }, searchAccount: SearchAccount): Promise => { - const client = new Mastodon( - rootState.TimelineSpace.account.accessToken!, - rootState.TimelineSpace.account.baseURL + '/api/v1', + searchAccount: async ({ rootState }, searchAccount: SearchAccount): Promise => { + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) // Find account in toot if (searchAccount.status.in_reply_to_account_id) { - const res: Response = await client.get(`/accounts/${searchAccount.status.in_reply_to_account_id}`) + const res = await client.getAccount(searchAccount.status.in_reply_to_account_id) if (res.status === 200) { const user = accountMatch([res.data], searchAccount.parsedAccount, rootState.TimelineSpace.account.domain) if (user) return user @@ -84,37 +86,35 @@ const actions: ActionTree = { // Find account in context if (searchAccount.status.in_reply_to_id) { - const res: Response = await client.get(`/statuses/${searchAccount.status.id}/context`) + const res = await client.getStatusContext(searchAccount.status.id) if (res.status === 200) { - const accounts: Array = res.data.ancestors.map(s => s.account).concat(res.data.descendants.map(s => s.account)) + const accounts: Array = res.data.ancestors.map(s => s.account).concat(res.data.descendants.map(s => s.account)) const user = accountMatch(accounts, searchAccount.parsedAccount, rootState.TimelineSpace.account.domain) if (user) return user } } // Search account name - const res: Response> = await client.get>('/accounts/search', { - q: searchAccount.parsedAccount.url, - resolve: true - }) + const res = await client.searchAccount(searchAccount.parsedAccount.url, { resolve: true }) if (res.data.length <= 0) throw new AccountNotFound('empty result') const user = accountMatch(res.data, searchAccount.parsedAccount, rootState.TimelineSpace.account.domain) if (!user) throw new AccountNotFound('not found') return user }, - changeAccount: ({ commit, dispatch }, account: Account) => { + changeAccount: ({ commit, dispatch }, account: Entity.Account) => { dispatch('fetchRelationship', account) commit(MUTATION_TYPES.CHANGE_ACCOUNT, account) }, - fetchRelationship: async ({ commit, rootState }, account: Account): Promise => { + fetchRelationship: async ({ commit, rootState }, account: Entity.Account): Promise => { commit(MUTATION_TYPES.CHANGE_RELATIONSHIP, null) - const client = new Mastodon( - rootState.TimelineSpace.account.accessToken!, - rootState.TimelineSpace.account.baseURL + '/api/v1', + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response = await client.get('/accounts/relationships', { id: [account.id] }) + const res = await client.getRelationship([account.id]) commit(MUTATION_TYPES.CHANGE_RELATIONSHIP, res.data[0]) return res.data }, @@ -129,26 +129,28 @@ const actions: ActionTree = { commit(MUTATION_TYPES.CHANGE_LOADING, false) }) }, - follow: async ({ commit, rootState, dispatch }, account: Account) => { - const client = new Mastodon( - rootState.TimelineSpace.account.accessToken!, - rootState.TimelineSpace.account.baseURL + '/api/v1', + follow: async ({ commit, rootState, dispatch }, account: Entity.Account) => { + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response = await client.post(`/accounts/${account.id}/follow`) + const res = await client.followAccount(account.id) 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', + unfollow: async ({ commit, rootState, dispatch }, account: Entity.Account) => { + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response = await client.post(`/accounts/${account.id}/unfollow`) + const res = await client.unfollowAccount(account.id) commit(MUTATION_TYPES.CHANGE_RELATIONSHIP, res.data) dispatch('fetchRelationship', account) return res.data @@ -156,38 +158,41 @@ const actions: ActionTree = { close: ({ commit }) => { 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', + unmute: async ({ rootState, commit, dispatch }, account: Entity.Account) => { + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response = await client.post(`/accounts/${account.id}/unmute`) + const res = await client.unmuteAccount(account.id) 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', + block: async ({ rootState, commit, dispatch }, account: Entity.Account) => { + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response = await client.post(`/accounts/${account.id}/block`) + const res = await client.blockAccount(account.id) 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 = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response = await client.post(`/accounts/${account.id}/unblock`) + const res = await client.unblockAccount(account.id) commit(MUTATION_TYPES.CHANGE_RELATIONSHIP, res.data) dispatch('fetchRelationship', account) return res.data @@ -226,7 +231,7 @@ class AccountNotFound extends Error {} export default AccountProfile -const accountMatch = (findAccounts: Array, parsedAccount: ParsedAccount, domain: string): Account | false => { +const accountMatch = (findAccounts: Array, parsedAccount: ParsedAccount, domain: string): Entity.Account | false => { const account = findAccounts.find(a => `@${a.acct}` === parsedAccount.acct) if (account) return account const pleromaUser = findAccounts.find(a => a.acct === parsedAccount.acct) diff --git a/src/renderer/store/TimelineSpace/Contents/SideBar/AccountProfile/Followers.ts b/src/renderer/store/TimelineSpace/Contents/SideBar/AccountProfile/Followers.ts index 5c21edfa..ea3a9061 100644 --- a/src/renderer/store/TimelineSpace/Contents/SideBar/AccountProfile/Followers.ts +++ b/src/renderer/store/TimelineSpace/Contents/SideBar/AccountProfile/Followers.ts @@ -1,10 +1,10 @@ -import Mastodon, { Account, Relationship, Response } from 'megalodon' +import generator, { Entity } from 'megalodon' import { Module, MutationTree, ActionTree } from 'vuex' import { RootState } from '@/store' export type FollowersState = { - followers: Array - relationships: Array + followers: Array + relationships: Array } const state = (): FollowersState => ({ @@ -18,37 +18,38 @@ export const MUTATION_TYPES = { } const mutations: MutationTree = { - [MUTATION_TYPES.UPDATE_FOLLOWERS]: (state, users: Array) => { + [MUTATION_TYPES.UPDATE_FOLLOWERS]: (state, users: Array) => { state.followers = users }, - [MUTATION_TYPES.UPDATE_RELATIONSHIPS]: (state, relations: Array) => { + [MUTATION_TYPES.UPDATE_RELATIONSHIPS]: (state, relations: Array) => { state.relationships = relations } } const actions: ActionTree = { - fetchFollowers: async ({ commit, rootState }, account: Account) => { - const client = new Mastodon( - rootState.TimelineSpace.account.accessToken!, - rootState.TimelineSpace.account.baseURL + '/api/v1', + fetchFollowers: async ({ commit, rootState }, account: Entity.Account) => { + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response> = await client.get>(`/accounts/${account.id}/followers`, { limit: 80 }) + const res = await client.getAccountFollowers(account.id, { limit: 80 }) commit(MUTATION_TYPES.UPDATE_FOLLOWERS, res.data) return res.data }, - fetchRelationships: async ({ commit, rootState }, accounts: Array) => { + fetchRelationships: async ({ commit, rootState }, accounts: Array) => { const ids = accounts.map(a => a.id) - const client = new Mastodon( - rootState.TimelineSpace.account.accessToken!, - rootState.TimelineSpace.account.baseURL + '/api/v1', + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, + rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response> = await client.get>(`/accounts/relationships`, { - id: ids - }) + const res = await client.getRelationship(ids) commit(MUTATION_TYPES.UPDATE_RELATIONSHIPS, res.data) return res.data } diff --git a/src/renderer/store/TimelineSpace/Contents/SideBar/AccountProfile/Follows.ts b/src/renderer/store/TimelineSpace/Contents/SideBar/AccountProfile/Follows.ts index 2e4309e6..93e16c5e 100644 --- a/src/renderer/store/TimelineSpace/Contents/SideBar/AccountProfile/Follows.ts +++ b/src/renderer/store/TimelineSpace/Contents/SideBar/AccountProfile/Follows.ts @@ -1,10 +1,10 @@ -import Mastodon, { Account, Relationship, Response } from 'megalodon' +import generator, { Entity } from 'megalodon' import { Module, MutationTree, ActionTree } from 'vuex' import { RootState } from '@/store' export type FollowsState = { - follows: Array - relationships: Array + follows: Array + relationships: Array } const state = (): FollowsState => ({ @@ -18,37 +18,37 @@ export const MUTATION_TYPES = { } const mutations: MutationTree = { - [MUTATION_TYPES.UPDATE_FOLLOWS]: (state, users: Array) => { + [MUTATION_TYPES.UPDATE_FOLLOWS]: (state, users: Array) => { state.follows = users }, - [MUTATION_TYPES.UPDATE_RELATIONSHIPS]: (state, relations: Array) => { + [MUTATION_TYPES.UPDATE_RELATIONSHIPS]: (state, relations: Array) => { state.relationships = relations } } const actions: ActionTree = { fetchFollows: async ({ commit, rootState }, account: Account) => { - const client = new Mastodon( - rootState.TimelineSpace.account.accessToken!, - rootState.TimelineSpace.account.baseURL + '/api/v1', + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response> = await client.get>(`/accounts/${account.id}/following`, { limit: 80 }) + const res = await client.getAccountFollowing(account.id, { limit: 80 }) commit(MUTATION_TYPES.UPDATE_FOLLOWS, res.data) return res.data }, - fetchRelationships: async ({ commit, rootState }, accounts: Array) => { + fetchRelationships: async ({ commit, rootState }, accounts: Array) => { const ids = accounts.map(a => a.id) - const client = new Mastodon( - rootState.TimelineSpace.account.accessToken!, - rootState.TimelineSpace.account.baseURL + '/api/v1', + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response> = await client.get>(`/accounts/relationships`, { - id: ids - }) + const res = await client.getRelationship(ids) commit(MUTATION_TYPES.UPDATE_RELATIONSHIPS, res.data) return res.data } diff --git a/src/renderer/store/TimelineSpace/Contents/SideBar/AccountProfile/Timeline.ts b/src/renderer/store/TimelineSpace/Contents/SideBar/AccountProfile/Timeline.ts index 5ed1f95a..73ba84e9 100644 --- a/src/renderer/store/TimelineSpace/Contents/SideBar/AccountProfile/Timeline.ts +++ b/src/renderer/store/TimelineSpace/Contents/SideBar/AccountProfile/Timeline.ts @@ -1,11 +1,11 @@ -import Mastodon, { Status, Response } from 'megalodon' +import generator, { Entity } from 'megalodon' import { Module, MutationTree, ActionTree } from 'vuex' import { RootState } from '@/store' import { LoadPositionWithAccount } from '@/types/loadPosition' export type TimelineState = { - timeline: Array - pinnedToots: Array + timeline: Array + pinnedToots: Array lazyLoading: boolean } @@ -26,19 +26,19 @@ export const MUTATION_TYPES = { } const mutations: MutationTree = { - [MUTATION_TYPES.UPDATE_TIMELINE]: (state, timeline: Array) => { + [MUTATION_TYPES.UPDATE_TIMELINE]: (state, timeline: Array) => { state.timeline = timeline }, - [MUTATION_TYPES.INSERT_TIMELINE]: (state, messages: Array) => { + [MUTATION_TYPES.INSERT_TIMELINE]: (state, messages: Array) => { state.timeline = state.timeline.concat(messages) }, - [MUTATION_TYPES.UPDATE_PINNED_TOOTS]: (state, messages: Array) => { + [MUTATION_TYPES.UPDATE_PINNED_TOOTS]: (state, messages: Array) => { state.pinnedToots = messages }, [MUTATION_TYPES.CHANGE_LAZY_LOADING]: (state, value: boolean) => { state.lazyLoading = value }, - [MUTATION_TYPES.UPDATE_PINNED_TOOT]: (state, message: Status) => { + [MUTATION_TYPES.UPDATE_PINNED_TOOT]: (state, message: Entity.Status) => { state.pinnedToots = state.pinnedToots.map(toot => { if (toot.id === message.id) { return message @@ -54,7 +54,7 @@ const mutations: MutationTree = { } }) }, - [MUTATION_TYPES.UPDATE_TOOT]: (state, message: Status) => { + [MUTATION_TYPES.UPDATE_TOOT]: (state, message: Entity.Status) => { // Replace target message in timeline state.timeline = state.timeline.map(toot => { if (toot.id === message.id) { @@ -71,7 +71,7 @@ const mutations: MutationTree = { } }) }, - [MUTATION_TYPES.DELETE_TOOT]: (state, message: Status) => { + [MUTATION_TYPES.DELETE_TOOT]: (state, message: Entity.Status) => { state.timeline = state.timeline.filter(toot => { if (toot.reblog !== null && toot.reblog.id === message.id) { return false @@ -85,15 +85,16 @@ const mutations: MutationTree = { const actions: ActionTree = { 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 = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const pinned: Response> = await client.get>(`/accounts/${account.id}/statuses`, { limit: 10, pinned: true }) + const pinned = await client.getAccountStatuses(account.id, { pinned: true, limit: 10 }) commit(MUTATION_TYPES.UPDATE_PINNED_TOOTS, pinned.data) - const res: Response> = await client.get>(`/accounts/${account.id}/statuses`, { limit: 40 }) + const res = await client.getAccountStatuses(account.id, { limit: 40, pinned: false }) commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', false, { root: true }) commit(MUTATION_TYPES.UPDATE_TIMELINE, res.data) return res.data @@ -103,16 +104,18 @@ const actions: ActionTree = { 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 = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) try { - const res: Response> = await client.get>(`/accounts/${loadPosition.account.id}/statuses`, { + const res = await client.getAccountStatuses(loadPosition.account.id, { max_id: loadPosition.status.id, - limit: 40 + limit: 40, + pinned: false }) commit(MUTATION_TYPES.INSERT_TIMELINE, res.data) } finally { diff --git a/src/renderer/store/TimelineSpace/Contents/SideBar/TootDetail.ts b/src/renderer/store/TimelineSpace/Contents/SideBar/TootDetail.ts index 146dc87f..895d06a4 100644 --- a/src/renderer/store/TimelineSpace/Contents/SideBar/TootDetail.ts +++ b/src/renderer/store/TimelineSpace/Contents/SideBar/TootDetail.ts @@ -1,11 +1,11 @@ -import Mastodon, { Status, Context, Response } from 'megalodon' +import generator, { Entity } from 'megalodon' import { Module, MutationTree, ActionTree } from 'vuex' import { RootState } from '@/store' export type TootDetailState = { - message: Status | null - ancestors: Array - descendants: Array + message: Entity.Status | null + ancestors: Array + descendants: Array } const state = (): TootDetailState => ({ @@ -27,16 +27,16 @@ export const MUTATION_TYPES = { } const mutations: MutationTree = { - [MUTATION_TYPES.CHANGE_TOOT]: (state, message: Status) => { + [MUTATION_TYPES.CHANGE_TOOT]: (state, message: Entity.Status) => { state.message = message }, - [MUTATION_TYPES.UPDATE_ANCESTORS]: (state, ancestors: Array) => { + [MUTATION_TYPES.UPDATE_ANCESTORS]: (state, ancestors: Array) => { state.ancestors = ancestors }, - [MUTATION_TYPES.UPDATE_DESCENDANTS]: (state, descendants: Array) => { + [MUTATION_TYPES.UPDATE_DESCENDANTS]: (state, descendants: Array) => { state.descendants = descendants }, - [MUTATION_TYPES.UPDATE_ANCESTORS_TOOT]: (state, message: Status) => { + [MUTATION_TYPES.UPDATE_ANCESTORS_TOOT]: (state, message: Entity.Status) => { // Replace target message in ancestors state.ancestors = state.ancestors.map(toot => { if (toot.id === message.id) { @@ -53,7 +53,7 @@ const mutations: MutationTree = { } }) }, - [MUTATION_TYPES.DELETE_ANCESTORS_TOOT]: (state, message: Status) => { + [MUTATION_TYPES.DELETE_ANCESTORS_TOOT]: (state, message: Entity.Status) => { state.ancestors = state.ancestors.filter(toot => { if (toot.reblog !== null && toot.reblog.id === message.id) { return false @@ -62,7 +62,7 @@ const mutations: MutationTree = { } }) }, - [MUTATION_TYPES.UPDATE_TOOT]: (state, message: Status) => { + [MUTATION_TYPES.UPDATE_TOOT]: (state, message: Entity.Status) => { if (state.message === null) { return } @@ -77,7 +77,7 @@ const mutations: MutationTree = { state.message = Object.assign({}, state.message, reblog) } }, - [MUTATION_TYPES.DELETE_TOOT]: (state, message: Status) => { + [MUTATION_TYPES.DELETE_TOOT]: (state, message: Entity.Status) => { if (state.message === null) { return } @@ -85,7 +85,7 @@ const mutations: MutationTree = { state.message = null } }, - [MUTATION_TYPES.UPDATE_DESCENDANTS_TOOT]: (state, message: Status) => { + [MUTATION_TYPES.UPDATE_DESCENDANTS_TOOT]: (state, message: Entity.Status) => { // Replace target message in descendants state.descendants = state.descendants.map(toot => { if (toot.id === message.id) { @@ -102,7 +102,7 @@ const mutations: MutationTree = { } }) }, - [MUTATION_TYPES.DELETE_DESCENDANTS_TOOT]: (state, message: Status) => { + [MUTATION_TYPES.DELETE_DESCENDANTS_TOOT]: (state, message: Entity.Status) => { state.descendants = state.descendants.filter(toot => { if (toot.reblog !== null && toot.reblog.id === message.id) { return false @@ -114,20 +114,20 @@ const mutations: MutationTree = { } const actions: ActionTree = { - changeToot: ({ commit }, message: Status) => { + changeToot: ({ commit }, message: Entity.Status) => { commit(MUTATION_TYPES.UPDATE_ANCESTORS, []) commit(MUTATION_TYPES.UPDATE_DESCENDANTS, []) 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', + fetchToot: async ({ commit, rootState }, message: Entity.Status) => { + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response = await client.get(`/statuses/${message.id}/context`, { limit: 40 }) - + const res = await client.getStatusContext(message.id, { limit: 40 }) commit(MUTATION_TYPES.UPDATE_ANCESTORS, res.data.ancestors) commit(MUTATION_TYPES.UPDATE_DESCENDANTS, res.data.descendants) return res.data diff --git a/src/renderer/store/TimelineSpace/HeaderMenu.ts b/src/renderer/store/TimelineSpace/HeaderMenu.ts index c022f94b..82f4c986 100644 --- a/src/renderer/store/TimelineSpace/HeaderMenu.ts +++ b/src/renderer/store/TimelineSpace/HeaderMenu.ts @@ -1,4 +1,4 @@ -import Mastodon, { List, Response } from 'megalodon' +import generator, { Entity } from 'megalodon' import { Module, MutationTree, ActionTree } from 'vuex' import { RootState } from '@/store' import AxiosLoading from '@/utils/axiosLoading' @@ -34,14 +34,15 @@ const mutations: MutationTree = { } const actions: ActionTree = { - fetchList: async ({ commit, rootState }, listID: string): Promise => { - const client = new Mastodon( - rootState.TimelineSpace.account.accessToken!, - rootState.TimelineSpace.account.baseURL + '/api/v1', + fetchList: async ({ commit, rootState }, listID: string): Promise => { + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response = await client.get(`/lists/${listID}`) + const res = await client.getList(listID) commit(MUTATION_TYPES.UPDATE_TITLE, `#${res.data.title}`) return res.data }, diff --git a/src/renderer/store/TimelineSpace/Modals/AddListMember.ts b/src/renderer/store/TimelineSpace/Modals/AddListMember.ts index f55eef75..ddf74e94 100644 --- a/src/renderer/store/TimelineSpace/Modals/AddListMember.ts +++ b/src/renderer/store/TimelineSpace/Modals/AddListMember.ts @@ -1,10 +1,10 @@ -import Mastodon, { Account, Response } from 'megalodon' +import generator, { Entity } from 'megalodon' import { Module, MutationTree, ActionTree } from 'vuex' import { RootState } from '@/store' export type AddListMemberState = { modalOpen: boolean - accounts: Array + accounts: Array targetListId: string | null } @@ -24,7 +24,7 @@ const mutations: MutationTree = { [MUTATION_TYPES.CHANGE_MODAL]: (state, value: boolean) => { state.modalOpen = value }, - [MUTATION_TYPES.UPDATE_ACCOUNTS]: (state, accounts: Array) => { + [MUTATION_TYPES.UPDATE_ACCOUNTS]: (state, accounts: Array) => { state.accounts = accounts }, [MUTATION_TYPES.SET_LIST_ID]: (state, id: string) => { @@ -36,30 +36,27 @@ const actions: ActionTree = { changeModal: ({ commit }, value: boolean) => { commit(MUTATION_TYPES.CHANGE_MODAL, value) }, - search: async ({ commit, rootState }, name: string): Promise> => { - const client = new Mastodon( - rootState.TimelineSpace.account.accessToken!, - rootState.TimelineSpace.account.baseURL + '/api/v1', + search: async ({ commit, rootState }, name: string): Promise> => { + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response> = await client.get>('/accounts/search', { - q: name, - following: true - }) + const res = await client.searchAccount(name, { following: true }) commit(MUTATION_TYPES.UPDATE_ACCOUNTS, res.data) 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 = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response<{}> = await client.post<{}>(`/lists/${state.targetListId}/accounts`, { - account_ids: [account.id] - }) + const res = await client.addAccountsToList(state.targetListId!, [account.id]) return res.data } } diff --git a/src/renderer/store/TimelineSpace/Modals/ImageViewer.ts b/src/renderer/store/TimelineSpace/Modals/ImageViewer.ts index 99e24f70..05ddaaf5 100644 --- a/src/renderer/store/TimelineSpace/Modals/ImageViewer.ts +++ b/src/renderer/store/TimelineSpace/Modals/ImageViewer.ts @@ -1,11 +1,11 @@ import { Module, MutationTree, ActionTree, GetterTree } from 'vuex' -import { Attachment } from 'megalodon' +import { Entity } from 'megalodon' import { RootState } from '@/store' export type ImageViewerState = { modalOpen: boolean currentIndex: number - mediaList: Array + mediaList: Array loading: boolean } @@ -32,7 +32,7 @@ const mutations: MutationTree = { [MUTATION_TYPES.CHANGE_CURRENT_INDEX]: (state, currentIndex: number) => { state.currentIndex = currentIndex }, - [MUTATION_TYPES.CHANGE_MEDIA_LIST]: (state, mediaList: Array) => { + [MUTATION_TYPES.CHANGE_MEDIA_LIST]: (state, mediaList: Array) => { state.mediaList = mediaList }, [MUTATION_TYPES.INCREMENT_INDEX]: state => { @@ -50,7 +50,7 @@ const actions: ActionTree = { openModal: ({ commit }, { currentIndex, mediaList }) => { commit(MUTATION_TYPES.CHANGE_MODAL, true) commit(MUTATION_TYPES.CHANGE_CURRENT_INDEX, currentIndex as number) - commit(MUTATION_TYPES.CHANGE_MEDIA_LIST, mediaList as Array) + commit(MUTATION_TYPES.CHANGE_MEDIA_LIST, mediaList as Array) commit(MUTATION_TYPES.CHANGE_LOADING, true) }, closeModal: ({ commit }) => { diff --git a/src/renderer/store/TimelineSpace/Modals/Jump.ts b/src/renderer/store/TimelineSpace/Modals/Jump.ts index a5f7aae6..b194e99e 100644 --- a/src/renderer/store/TimelineSpace/Modals/Jump.ts +++ b/src/renderer/store/TimelineSpace/Modals/Jump.ts @@ -1,7 +1,7 @@ import router from '@/router' import i18n from '~/src/config/i18n' import { Module, MutationTree, ActionTree } from 'vuex' -import { List } from 'megalodon' +import { Entity } from 'megalodon' import { LocalTag } from '~/src/types/localTag' import { RootState } from '@/store' @@ -86,7 +86,7 @@ const mutations: MutationTree = { [MUTATION_TYPES.CHANGE_SELECTED]: (state, channel: Channel) => { state.selectedChannel = channel }, - [MUTATION_TYPES.UPDATE_LIST_CHANNEL]: (state, lists: Array) => { + [MUTATION_TYPES.UPDATE_LIST_CHANNEL]: (state, lists: Array) => { state.listChannelList = lists.map(l => { const channel: Channel = { name: `#${l.title}`, diff --git a/src/renderer/store/TimelineSpace/Modals/ListMembership.ts b/src/renderer/store/TimelineSpace/Modals/ListMembership.ts index 086775b4..ee4daf93 100644 --- a/src/renderer/store/TimelineSpace/Modals/ListMembership.ts +++ b/src/renderer/store/TimelineSpace/Modals/ListMembership.ts @@ -1,13 +1,13 @@ -import Mastodon, { Account, List, Response } from 'megalodon' +import generator, { Entity } from 'megalodon' import lodash from 'lodash' import { Module, MutationTree, ActionTree } from 'vuex' import { RootState } from '@/store' export type ListMembershipState = { modalOpen: boolean - account: Account | null - lists: Array - belongToLists: Array + account: Entity.Account | null + lists: Array + belongToLists: Array } const state = (): ListMembershipState => ({ @@ -28,13 +28,13 @@ const mutations: MutationTree = { [MUTATION_TYPES.CHANGE_MODAL]: (state, value: boolean) => { state.modalOpen = value }, - [MUTATION_TYPES.CHANGE_ACCOUNT]: (state, account: Account) => { + [MUTATION_TYPES.CHANGE_ACCOUNT]: (state, account: Entity.Account) => { state.account = account }, - [MUTATION_TYPES.CHANGE_BELONG_TO_LISTS]: (state, lists: Array) => { + [MUTATION_TYPES.CHANGE_BELONG_TO_LISTS]: (state, lists: Array) => { state.belongToLists = lists }, - [MUTATION_TYPES.CHANGE_LISTS]: (state, lists: Array) => { + [MUTATION_TYPES.CHANGE_LISTS]: (state, lists: Array) => { state.lists = lists } } @@ -43,51 +43,53 @@ const actions: ActionTree = { changeModal: ({ commit }, value: boolean) => { commit(MUTATION_TYPES.CHANGE_MODAL, value) }, - setAccount: ({ commit }, account: Account) => { + setAccount: ({ commit }, account: Entity.Account) => { 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', + fetchListMembership: async ({ commit, rootState }, account: Entity.Account) => { + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response> = await client.get>(`/accounts/${account.id}/lists`) - commit(MUTATION_TYPES.CHANGE_BELONG_TO_LISTS, res.data.map(l => l.id)) + const res = await client.getAccountLists(account.id) + 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 = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response> = await client.get>('/lists') + const res = await client.getLists() commit(MUTATION_TYPES.CHANGE_LISTS, res.data) return res.data }, - changeBelongToLists: async ({ rootState, commit, state }, belongToLists: Array) => { + changeBelongToLists: async ({ rootState, commit, state }, belongToLists: Array) => { // Calcurate diff 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 = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const removedPromise = removedLists.map(id => { - return client.del<{}>(`/lists/${id}/accounts`, { - account_ids: [state.account!.id] - }) + const removedPromise = removedLists.map(list => { + return client.deleteAccountsFromList(list.id, [state.account!.id]) }) - const addedPromise = addedLists.map(id => { - return client.post<{}>(`/lists/${id}/accounts`, { - account_ids: [state.account!.id] - }) + const addedPromise = addedLists.map(list => { + return client.addAccountsToList(list.id, [state.account!.id]) }) const res = await Promise.all(removedPromise.concat(addedPromise)) return res diff --git a/src/renderer/store/TimelineSpace/Modals/MuteConfirm.ts b/src/renderer/store/TimelineSpace/Modals/MuteConfirm.ts index b173656c..a1d1258e 100644 --- a/src/renderer/store/TimelineSpace/Modals/MuteConfirm.ts +++ b/src/renderer/store/TimelineSpace/Modals/MuteConfirm.ts @@ -1,4 +1,4 @@ -import Mastodon, { Account, Response, Relationship } from 'megalodon' +import generator from 'megalodon' import { Module, MutationTree, ActionTree } from 'vuex' import { RootState } from '@/store' @@ -34,15 +34,14 @@ const actions: ActionTree = { 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 = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response = await client.post(`/accounts/${state.account!.id}/mute`, { - notifications: notify - }) + const res = await client.muteAccount(state.account!.id, notify) // Reload relationship dispatch('TimelineSpace/Contents/SideBar/AccountProfile/fetchRelationship', state.account, { root: true }) return res.data diff --git a/src/renderer/store/TimelineSpace/Modals/NewToot.ts b/src/renderer/store/TimelineSpace/Modals/NewToot.ts index bc603ea6..4071a024 100644 --- a/src/renderer/store/TimelineSpace/Modals/NewToot.ts +++ b/src/renderer/store/TimelineSpace/Modals/NewToot.ts @@ -1,4 +1,4 @@ -import Mastodon, { Status, Attachment, Tag, Response, Account } from 'megalodon' +import generator, { Entity } from 'megalodon' import Visibility, { VisibilityType } from '~/src/constants/visibility' import TootStatus, { StatusState } from './NewToot/Status' import { Module, MutationTree, ActionTree, GetterTree } from 'vuex' @@ -34,15 +34,15 @@ export type NewTootState = { modalOpen: boolean initialStatus: string initialSpoiler: string - replyToMessage: Status | null + replyToMessage: Entity.Status | null blockSubmit: boolean - attachedMedias: Array + attachedMedias: Array mediaDescriptions: { [key: string]: string | null } visibility: number sensitive: boolean attachedMediaCount: number pinedHashtag: boolean - hashtags: Array + hashtags: Array loading: boolean } @@ -92,7 +92,7 @@ const mutations: MutationTree = { [MUTATION_TYPES.CHANGE_MODAL]: (state, value: boolean) => { state.modalOpen = value }, - [MUTATION_TYPES.SET_REPLY_TO]: (state, message: Status) => { + [MUTATION_TYPES.SET_REPLY_TO]: (state, message: Entity.Status) => { state.replyToMessage = message }, [MUTATION_TYPES.UPDATE_INITIAL_STATUS]: (state, status: string) => { @@ -104,13 +104,13 @@ const mutations: MutationTree = { [MUTATION_TYPES.CHANGE_BLOCK_SUBMIT]: (state, value: boolean) => { state.blockSubmit = value }, - [MUTATION_TYPES.APPEND_ATTACHED_MEDIAS]: (state, media: Attachment) => { + [MUTATION_TYPES.APPEND_ATTACHED_MEDIAS]: (state, media: Entity.Attachment) => { state.attachedMedias = state.attachedMedias.concat([media]) }, [MUTATION_TYPES.CLEAR_ATTACHED_MEDIAS]: state => { state.attachedMedias = [] }, - [MUTATION_TYPES.REMOVE_MEDIA]: (state, media: Attachment) => { + [MUTATION_TYPES.REMOVE_MEDIA]: (state, media: Entity.Attachment) => { state.attachedMedias = state.attachedMedias.filter(m => m.id !== media.id) }, [MUTATION_TYPES.UPDATE_MEDIA_DESCRIPTION]: (state, value: MediaDescription) => { @@ -142,7 +142,7 @@ const mutations: MutationTree = { [MUTATION_TYPES.CHANGE_PINED_HASHTAG]: (state, value: boolean) => { state.pinedHashtag = value }, - [MUTATION_TYPES.UPDATE_HASHTAGS]: (state, tags: Array) => { + [MUTATION_TYPES.UPDATE_HASHTAGS]: (state, tags: Array) => { state.hashtags = tags }, [MUTATION_TYPES.CHANGE_LOADING]: (state, value: boolean) => { @@ -174,15 +174,16 @@ const actions: ActionTree = { if (rootState.TimelineSpace.account.accessToken === undefined || rootState.TimelineSpace.account.accessToken === null) { throw new AuthenticationError() } - const client = new Mastodon( + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, 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(`/media/${id}`, { description: mediaDescription[id] }) + return client.updateMedia(id, { description: mediaDescription[id] }) } else { return Promise.resolve({}) } @@ -192,7 +193,7 @@ const actions: ActionTree = { throw err }) }, - postToot: async ({ state, commit, rootState, dispatch }, params: TootForm): Promise => { + postToot: async ({ state, commit, rootState, dispatch }, params: TootForm): Promise => { if (!state.modalOpen) { throw new NewTootModalOpen() } @@ -204,13 +205,12 @@ const actions: ActionTree = { const visibilityKey: string | undefined = Object.keys(Visibility).find(key => { return Visibility[key].value === state.visibility }) - let specifiedVisibility: string = Visibility.Public.key + let specifiedVisibility: 'public' | 'unlisted' | 'private' | 'direct' = Visibility.Public.key if (visibilityKey !== undefined) { specifiedVisibility = Visibility[visibilityKey].key } let form = { - status: params.status, visibility: specifiedVisibility, sensitive: state.sensitive, spoiler_text: params.spoiler @@ -260,15 +260,16 @@ const actions: ActionTree = { } commit(MUTATION_TYPES.CHANGE_BLOCK_SUBMIT, true) - const client = new Mastodon( + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, rootState.TimelineSpace.account.accessToken, - rootState.TimelineSpace.account.baseURL + '/api/v1', rootState.App.userAgent, rootState.App.proxyConfiguration ) return client - .post('/statuses', form) - .then((res: Response) => { + .postStatus(params.status, form) + .then(res => { win.ipcRenderer.send('toot-action-sound') return res.data }) @@ -276,7 +277,7 @@ const actions: ActionTree = { commit(MUTATION_TYPES.CHANGE_BLOCK_SUBMIT, false) }) }, - openReply: ({ commit, rootState }, message: Status) => { + openReply: ({ commit, rootState }, message: Entity.Status) => { commit(MUTATION_TYPES.SET_REPLY_TO, message) const mentionAccounts = [message.account.acct] .concat(message.mentions.map(a => a.acct)) @@ -317,16 +318,15 @@ const actions: ActionTree = { if (rootState.TimelineSpace.account.accessToken === undefined || rootState.TimelineSpace.account.accessToken === null) { throw new AuthenticationError() } - const client = new Mastodon( + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, 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 - .post('/media', formData) + .uploadMedia(image) .then(res => { commit(MUTATION_TYPES.CHANGE_BLOCK_SUBMIT, false) if (res.data.type === 'unknown') throw new NewTootUnknownType() @@ -348,24 +348,25 @@ const actions: ActionTree = { resetMediaCount: ({ commit }) => { commit(MUTATION_TYPES.UPDATE_MEDIA_COUNT, 0) }, - removeMedia: ({ commit, dispatch }, media: Attachment) => { + removeMedia: ({ commit, dispatch }, media: Entity.Attachment) => { commit(MUTATION_TYPES.REMOVE_MEDIA, media) commit(MUTATION_TYPES.REMOVE_MEDIA_DESCRIPTION, media.id) dispatch('decrementMediaCount') }, - updateHashtags: ({ commit, state }, tags: Array) => { + updateHashtags: ({ commit, state }, tags: Array) => { if (state.pinedHashtag && tags.length > 0) { commit(MUTATION_TYPES.UPDATE_HASHTAGS, tags) } }, fetchVisibility: async ({ commit, rootState }) => { - const client = new Mastodon( - rootState.TimelineSpace.account.accessToken!, - rootState.TimelineSpace.account.baseURL + '/api/v1', + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response = await client.get('/accounts/verify_credentials') + const res = await client.verifyAccountCredentials() const visibility: VisibilityType | undefined = (Object.values(Visibility) as Array).find(v => { return v.key === res.data.source!.privacy }) diff --git a/src/renderer/store/TimelineSpace/Modals/NewToot/Status.ts b/src/renderer/store/TimelineSpace/Modals/NewToot/Status.ts index cea49c5e..66bbc1ae 100644 --- a/src/renderer/store/TimelineSpace/Modals/NewToot/Status.ts +++ b/src/renderer/store/TimelineSpace/Modals/NewToot/Status.ts @@ -1,5 +1,5 @@ import emojilib from 'emojilib' -import Mastodon, { Account, Response, Results } from 'megalodon' +import generator, { MegalodonInterface } from 'megalodon' import { Module, MutationTree, ActionTree, GetterTree } from 'vuex' import { RootState } from '@/store/index' import { LocalTag } from '~/src/types/localTag' @@ -29,7 +29,7 @@ export type StatusState = { openSuggest: boolean startIndex: number | null matchWord: string | null - client: Mastodon | null + client: MegalodonInterface | null } const state = (): StatusState => ({ @@ -131,7 +131,7 @@ const mutations: MutationTree = { [MUTATION_TYPES.CLEAR_FILTERED_SUGGESTION]: state => { state.filteredSuggestion = [] }, - [MUTATION_TYPES.SET_CLIENT]: (state, client: Mastodon) => { + [MUTATION_TYPES.SET_CLIENT]: (state, client: MegalodonInterface) => { state.client = client }, [MUTATION_TYPES.CLEAR_CLIENT]: state => { @@ -167,14 +167,15 @@ const actions: ActionTree = { }) } const searchAPI = async () => { - const client = new Mastodon( - rootState.TimelineSpace.account.accessToken!, - rootState.TimelineSpace.account.baseURL + '/api/v1', + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) commit(MUTATION_TYPES.SET_CLIENT, client) - const res: Response> = await client.get>('/accounts/search', { q: word, resolve: false }) + const res = await client.searchAccount(word) if (res.data.length === 0) throw new Error('Empty') commit( MUTATION_TYPES.APPEND_FILTERED_ACCOUNTS, @@ -214,14 +215,15 @@ const actions: ActionTree = { }) } const searchAPI = async () => { - const client = new Mastodon( - rootState.TimelineSpace.account.accessToken!, - rootState.TimelineSpace.account.baseURL + '/api/v2', + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) commit(MUTATION_TYPES.SET_CLIENT, client) - const res: Response = await client.get('/search', { q: word }) + const res = await client.search(word, 'hashtags') if (res.data.hashtags.length === 0) throw new Error('Empty') commit( MUTATION_TYPES.APPEND_FILTERED_HASHTAGS, diff --git a/src/renderer/store/TimelineSpace/Modals/Report.ts b/src/renderer/store/TimelineSpace/Modals/Report.ts index f78d5c99..ad5caff5 100644 --- a/src/renderer/store/TimelineSpace/Modals/Report.ts +++ b/src/renderer/store/TimelineSpace/Modals/Report.ts @@ -1,10 +1,10 @@ -import Mastodon, { Status } from 'megalodon' +import generator, { Entity } from 'megalodon' import { Module, MutationTree, ActionTree } from 'vuex' import { RootState } from '@/store' export type ReportState = { modalOpen: boolean - message: Status | null + message: Entity.Status | null } const state = (): ReportState => ({ @@ -21,28 +21,25 @@ const mutations: MutationTree = { [MUTATION_TYPES.CHANGE_MODAL_OPEN]: (state, value: boolean) => { state.modalOpen = value }, - [MUTATION_TYPES.CHANGE_MESSAGE]: (state, message: Status) => { + [MUTATION_TYPES.CHANGE_MESSAGE]: (state, message: Entity.Status) => { state.message = message } } const actions: ActionTree = { - openReport: ({ commit }, message: Status) => { + openReport: ({ commit }, message: Entity.Status) => { commit(MUTATION_TYPES.CHANGE_MESSAGE, message) 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 = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - return client.post<{}>(`/reports`, { - account_id: account_id, - status_ids: [status_id], - comment: comment - }) + return client.report(account_id, comment, { status_ids: [status_id] }) } } diff --git a/src/renderer/store/TimelineSpace/SideMenu.ts b/src/renderer/store/TimelineSpace/SideMenu.ts index 70519cac..3f32205f 100644 --- a/src/renderer/store/TimelineSpace/SideMenu.ts +++ b/src/renderer/store/TimelineSpace/SideMenu.ts @@ -1,4 +1,4 @@ -import Mastodon, { List, Response, Account } from 'megalodon' +import generator, { Entity } from 'megalodon' import { Module, MutationTree, ActionTree } from 'vuex' import { LocalTag } from '~/src/types/localTag' import { LocalAccount } from '~/src/types/localAccount' @@ -15,7 +15,7 @@ export type SideMenuState = { unreadDirectMessagesTimeline: boolean unreadPublicTimeline: boolean unreadFollowRequests: boolean - lists: Array + lists: Array tags: Array collapse: boolean } @@ -68,7 +68,7 @@ const mutations: MutationTree = { [MUTATION_TYPES.CHANGE_UNREAD_FOLLOW_REQUESTS]: (state, value: boolean) => { state.unreadFollowRequests = value }, - [MUTATION_TYPES.UPDATE_LISTS]: (state, lists: Array) => { + [MUTATION_TYPES.UPDATE_LISTS]: (state, lists: Array) => { state.lists = lists }, [MUTATION_TYPES.CHANGE_COLLAPSE]: (state, collapse: boolean) => { @@ -80,27 +80,29 @@ const mutations: MutationTree = { } const actions: ActionTree = { - fetchLists: async ({ commit, rootState }, account: LocalAccount | null = null): Promise> => { + fetchLists: async ({ commit, rootState }, account: LocalAccount | null = null): Promise> => { if (account === null) account = rootState.TimelineSpace.account - const client = new Mastodon( - account!.accessToken!, - account!.baseURL + '/api/v1', + const client = generator( + rootState.TimelineSpace.sns, + account.baseURL, + account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response> = await client.get>('/lists') + const res = await client.getLists() commit(MUTATION_TYPES.UPDATE_LISTS, res.data) return res.data }, - fetchFollowRequests: async ({ commit, rootState }, account: LocalAccount | null = null): Promise> => { + fetchFollowRequests: async ({ commit, rootState }, account: LocalAccount | null = null): Promise> => { if (account === null) account = rootState.TimelineSpace.account - const client = new Mastodon( - account!.accessToken!, - account!.baseURL + '/api/v1', + const client = generator( + rootState.TimelineSpace.sns, + account.baseURL, + account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response> = await client.get>('/follow_requests') + const res = await client.getFollowRequests() commit(MUTATION_TYPES.CHANGE_UNREAD_FOLLOW_REQUESTS, res.data.length > 0) return res.data }, diff --git a/src/renderer/store/organisms/Toot.ts b/src/renderer/store/organisms/Toot.ts index 0e1b4cd4..171f2f75 100644 --- a/src/renderer/store/organisms/Toot.ts +++ b/src/renderer/store/organisms/Toot.ts @@ -1,4 +1,4 @@ -import Mastodon, { Response, Status, Account, Poll } from 'megalodon' +import generator, { Entity } from 'megalodon' import { Module, ActionTree } from 'vuex' import { RootState } from '@/store' import { MyWindow } from '~/src/types/global' @@ -7,7 +7,7 @@ const win = window as MyWindow type VoteParam = { id: string - choices: Array + choices: Array } export type TootState = {} @@ -15,14 +15,15 @@ export type TootState = {} const state = (): TootState => ({}) const actions: ActionTree = { - reblog: async ({ rootState, dispatch }, message: Status) => { - const client = new Mastodon( - rootState.TimelineSpace.account.accessToken!, - rootState.TimelineSpace.account.baseURL + '/api/v1', + reblog: async ({ rootState, dispatch }, message: Entity.Status) => { + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response = await client.post(`/statuses/${message.id}/reblog`) + const res = await client.reblogStatus(message.id) // API returns new status when reblog. // Reblog target status is in the data.reblog. // So I send data.reblog as status for update local timeline. @@ -30,79 +31,84 @@ const actions: ActionTree = { dispatch('TimelineSpace/updateTootForAllTimelines', res.data.reblog, { root: true }) return res.data.reblog }, - unreblog: async ({ rootState, dispatch }, message: Status) => { - const client = new Mastodon( - rootState.TimelineSpace.account.accessToken!, - rootState.TimelineSpace.account.baseURL + '/api/v1', + unreblog: async ({ rootState, dispatch }, message: Entity.Status) => { + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response = await client.post(`/statuses/${message.id}/unreblog`) + const res = await client.unreblogStatus(message.id) 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', + addFavourite: async ({ rootState, dispatch }, message: Entity.Status) => { + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response = await client.post(`/statuses/${message.id}/favourite`) + const res = await client.favouriteStatus(message.id) win.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', + removeFavourite: async ({ rootState, dispatch }, message: Entity.Status) => { + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res: Response = await client.post(`/statuses/${message.id}/unfavourite`) + const res = await client.unfavouriteStatus(message.id) 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', + deleteToot: async ({ rootState }, message: Entity.Status) => { + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - await client.del(`/statuses/${message.id}`) + await client.deleteStatus(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 = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - return client.post(`/accounts/${account.id}/block`) + return client.blockAccount(account.id) }, - vote: async ({ rootState }, params: VoteParam): Promise => { - const client = new Mastodon( - rootState.TimelineSpace.account.accessToken!, - rootState.TimelineSpace.account.baseURL + '/api/v1', + vote: async ({ rootState }, params: VoteParam): Promise => { + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res = await client.post(`/polls/${params.id}/votes`, { - choices: params.choices - }) + const res = await client.votePoll(params.id, params.choices) return res.data }, - refresh: async ({ rootState }, id: string): Promise => { - const client = new Mastodon( - rootState.TimelineSpace.account.accessToken!, - rootState.TimelineSpace.account.baseURL + '/api/v1', + refresh: async ({ rootState }, id: string): Promise => { + const client = generator( + rootState.TimelineSpace.sns, + rootState.TimelineSpace.account.baseURL, + rootState.TimelineSpace.account.accessToken, rootState.App.userAgent, rootState.App.proxyConfiguration ) - const res = await client.get(`/polls/${id}`) + const res = await client.getPoll(id) return res.data } } diff --git a/src/renderer/types/loadPosition.ts b/src/renderer/types/loadPosition.ts index c8c4895b..20f1fe95 100644 --- a/src/renderer/types/loadPosition.ts +++ b/src/renderer/types/loadPosition.ts @@ -1,11 +1,11 @@ -import { Status, Account } from 'megalodon' +import { Entity } from 'megalodon' export type LoadPosition = { - status: Status + status: Entity.Status } export type LoadPositionWithAccount = LoadPosition & { - account: Account + account: Entity.Account } export type LoadPositionWithList = LoadPosition & { diff --git a/src/renderer/types/removeAccountFromList.ts b/src/renderer/types/removeAccountFromList.ts index 98a29e3a..6d0bdb0d 100644 --- a/src/renderer/types/removeAccountFromList.ts +++ b/src/renderer/types/removeAccountFromList.ts @@ -1,6 +1,6 @@ -import { Account } from 'megalodon' +import { Entity } from 'megalodon' export type RemoveAccountFromList = { - account: Account + account: Entity.Account listId: string } diff --git a/src/types/accountNotification.ts b/src/types/accountNotification.ts index 20c48b6c..61ceea58 100644 --- a/src/types/accountNotification.ts +++ b/src/types/accountNotification.ts @@ -1,6 +1,6 @@ -import { Notification } from 'megalodon' +import { Entity } from 'megalodon' export type AccountNotification = { id: string - notification: Notification + notification: Entity.Notification }