From 0200f69e1d1ba2a83a30c0cc24a884eb6d429474 Mon Sep 17 00:00:00 2001
From: AkiraFukushima
Date: Sun, 15 Mar 2020 17:47:56 +0900
Subject: [PATCH] Fix megalodon class for 3.0.0 in renderer
---
src/constants/visibility/index.d.ts | 2 +-
src/renderer/store/Login.ts | 22 +---
src/renderer/store/Settings/General.ts | 39 +++---
src/renderer/store/TimelineSpace.ts | 52 ++++----
.../TimelineSpace/Contents/DirectMessages.ts | 40 ++++---
.../TimelineSpace/Contents/Favourites.ts | 34 +++---
.../TimelineSpace/Contents/FollowRequests.ts | 39 +++---
.../TimelineSpace/Contents/Hashtag/Tag.ts | 36 +++---
.../store/TimelineSpace/Contents/Home.ts | 34 +++---
.../TimelineSpace/Contents/Lists/Edit.ts | 30 +++--
.../TimelineSpace/Contents/Lists/Index.ts | 30 ++---
.../TimelineSpace/Contents/Lists/Show.ts | 38 +++---
.../store/TimelineSpace/Contents/Local.ts | 36 +++---
.../store/TimelineSpace/Contents/Mentions.ts | 44 ++++---
.../TimelineSpace/Contents/Notifications.ts | 40 ++++---
.../store/TimelineSpace/Contents/Public.ts | 36 +++---
.../TimelineSpace/Contents/Search/Account.ts | 13 +-
.../TimelineSpace/Contents/Search/Tag.ts | 17 +--
.../TimelineSpace/Contents/Search/Toots.ts | 17 +--
.../Contents/SideBar/AccountProfile.ts | 111 +++++++++---------
.../SideBar/AccountProfile/Followers.ts | 35 +++---
.../SideBar/AccountProfile/Follows.ts | 32 ++---
.../SideBar/AccountProfile/Timeline.ts | 41 ++++---
.../Contents/SideBar/TootDetail.ts | 40 +++----
.../store/TimelineSpace/HeaderMenu.ts | 13 +-
.../TimelineSpace/Modals/AddListMember.ts | 31 +++--
.../store/TimelineSpace/Modals/ImageViewer.ts | 8 +-
.../store/TimelineSpace/Modals/Jump.ts | 4 +-
.../TimelineSpace/Modals/ListMembership.ts | 62 +++++-----
.../store/TimelineSpace/Modals/MuteConfirm.ts | 13 +-
.../store/TimelineSpace/Modals/NewToot.ts | 61 +++++-----
.../TimelineSpace/Modals/NewToot/Status.ts | 24 ++--
.../store/TimelineSpace/Modals/Report.ts | 21 ++--
src/renderer/store/TimelineSpace/SideMenu.ts | 28 +++--
src/renderer/store/organisms/Toot.ts | 92 ++++++++-------
src/renderer/types/loadPosition.ts | 6 +-
src/renderer/types/removeAccountFromList.ts | 4 +-
src/types/accountNotification.ts | 4 +-
38 files changed, 625 insertions(+), 604 deletions(-)
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