Use megalodon instead of mastodon-api as mastodon api client in render process

This commit is contained in:
AkiraFukushima 2018-06-10 12:25:39 +09:00
parent a46eb5ab07
commit 5d549618ee
20 changed files with 522 additions and 1046 deletions

762
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -96,7 +96,6 @@
"hawk": "^7.0.7",
"hoek": "^5.0.3",
"is-empty": "^1.2.0",
"mastodon-api": "github:h3poteto/mastodon-api#lib",
"megalodon": "^0.1.0",
"moment": "^2.21.0",
"mousetrap": "^1.6.2",

View File

@ -165,26 +165,19 @@ export default class Account {
}
refresh (account) {
return new Promise((resolve, reject) => {
const client = new Mastodon(
account.accessToken,
account.baseURL + '/api/v1'
)
client.get('/accounts/verify_credentials')
.then(data => {
console.log(data)
const json = {
username: data.username,
accountId: data.id,
avatar: data.avatar
}
this.updateAccount(account._id, json)
.then(ac => resolve(ac))
})
.catch(err => {
return reject(err)
})
})
const client = new Mastodon(
account.accessToken,
account.baseURL + '/api/v1'
)
return client.get('/accounts/verify_credentials')
.then(data => {
const json = {
username: data.username,
accountId: data.id,
avatar: data.avatar
}
return this.updateAccount(account._id, json)
})
}
}

View File

@ -1,4 +1,4 @@
import Mastodon from 'mastodon-api'
import Mastodon from 'megalodon'
import { ipcRenderer } from 'electron'
const Toot = {
@ -7,79 +7,53 @@ const Toot = {
mutations: {},
actions: {
reblog ({ state, commit, rootState }, message) {
return new Promise((resolve, reject) => {
const client = new Mastodon(
{
access_token: rootState.TimelineSpace.account.accessToken,
api_url: rootState.TimelineSpace.account.baseURL + '/api/v1'
}
)
client.post(`/statuses/${message.id}/reblog`, {}, (err, data, res) => {
if (err) return reject(err)
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.post(`/statuses/${message.id}/reblog`)
.then(data => {
// 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.
ipcRenderer.send('fav-rt-action-sound')
resolve(data.reblog)
return data.reblog
})
})
},
unreblog ({ state, commit, rootState }, message) {
return new Promise((resolve, reject) => {
const client = new Mastodon(
{
access_token: rootState.TimelineSpace.account.accessToken,
api_url: rootState.TimelineSpace.account.baseURL + '/api/v1'
}
)
client.post(`/statuses/${message.id}/unreblog`, {}, (err, data, res) => {
if (err) return reject(err)
resolve(data)
})
})
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.post(`/statuses/${message.id}/unreblog`)
},
addFavourite ({ state, commit, rootState }, message) {
return new Promise((resolve, reject) => {
const client = new Mastodon(
{
access_token: rootState.TimelineSpace.account.accessToken,
api_url: rootState.TimelineSpace.account.baseURL + '/api/v1'
}
)
client.post(`/statuses/${message.id}/favourite`, {}, (err, data, res) => {
if (err) return reject(err)
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.post(`/statuses/${message.id}/favourite`)
.then(data => {
ipcRenderer.send('fav-rt-action-sound')
resolve(data)
return data
})
})
},
removeFavourite ({ state, commit, rootState }, message) {
return new Promise((resolve, reject) => {
const client = new Mastodon(
{
access_token: rootState.TimelineSpace.account.accessToken,
api_url: rootState.TimelineSpace.account.baseURL + '/api/v1'
}
)
client.post(`/statuses/${message.id}/unfavourite`, {}, (err, data, res) => {
if (err) return reject(err)
resolve(data)
})
})
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.post(`/statuses/${message.id}/unfavourite`)
},
deleteToot ({ state, commit, rootState }, message) {
return new Promise((resolve, reject) => {
const client = new Mastodon(
{
access_token: rootState.TimelineSpace.account.accessToken,
api_url: rootState.TimelineSpace.account.baseURL + '/api/v1'
}
)
client.delete(`/statuses/${message.id}`, {}, (err, data, res) => {
if (err) return reject(err)
resolve(message)
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.del(`/statuses/${message.id}`)
.then(() => {
return message
})
})
}
}
}

View File

@ -1,4 +1,4 @@
import Mastodon from 'mastodon-api'
import Mastodon from 'megalodon'
const Favourites = {
namespaced: true,
@ -44,44 +44,41 @@ const Favourites = {
},
actions: {
fetchFavourites ({ commit }, account) {
return new Promise((resolve, reject) => {
const client = new Mastodon(
{
access_token: account.accessToken,
api_url: account.baseURL + '/api/v1'
}
)
client.get('/favourites', { limit: 40 }, (err, data, res) => {
if (err) return reject(err)
const client = new Mastodon(
account.accessToken,
account.baseURL + '/api/v1'
)
return client.get('/favourites', { limit: 40 })
.then(data => {
commit('updateFavourites', data)
resolve(res)
return data
})
})
},
lazyFetchFavourites ({ state, commit, rootState }, last) {
if (last === undefined || last === null) {
return null
return Promise.resolve(null)
}
return new Promise((resolve, reject) => {
if (state.lazyLoading) {
return resolve()
}
commit('changeLazyLoading', true)
const client = new Mastodon(
{
access_token: rootState.TimelineSpace.account.accessToken,
api_url: rootState.TimelineSpace.account.baseURL + '/api/v1'
})
// Note: Now this API's explanation and implementation are reversed.
// So if the bug has resolved, please use max_id instead of since_id.
// https://github.com/tootsuite/documentation/blob/master/Using-the-API/API.md#favourites
client.get('/favourites', { since_id: last.id, limit: 40 }, (err, data, res) => {
if (err) return reject(err)
commit('insertFavourites', data)
if (state.lazyLoading) {
return Promise.resolve(null)
}
commit('changeLazyLoading', true)
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
// Note: Now this API's explanation and implementation are reversed.
// So if the bug has resolved, please use max_id instead of since_id.
// https://github.com/tootsuite/documentation/blob/master/Using-the-API/API.md#favourites
return client.get('/favourites', { since_id: last.id, limit: 40 })
.then(data => {
commit('changeLazyLoading', false)
resolve(res)
commit('insertFavourites', data)
return data
})
.catch(err => {
commit('changeLazyLoading', false)
throw err
})
})
}
}
}

View File

@ -1,5 +1,5 @@
import { ipcRenderer } from 'electron'
import Mastodon from 'mastodon-api'
import Mastodon from 'megalodon'
const Tag = {
namespaced: true,
@ -68,19 +68,14 @@ const Tag = {
},
actions: {
fetch ({ commit, rootState }, tag) {
return new Promise((resolve, reject) => {
const client = new Mastodon(
{
access_token: rootState.TimelineSpace.account.accessToken,
api_url: rootState.TimelineSpace.account.baseURL + '/api/v1'
}
)
client.get(`/timelines/tag/${tag}`, { limit: 40 }, (err, data, res) => {
if (err) return reject(err)
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.get(`/timelines/tag/${tag}`, { limit: 40 })
.then(data => {
commit('updateTimeline', data)
resolve(res)
})
})
},
startStreaming ({ state, commit, rootState }, tag) {
ipcRenderer.on('update-start-tag-streaming', (event, update) => {
@ -108,22 +103,24 @@ const Tag = {
})
},
lazyFetchTimeline ({ state, commit, rootState }, obj) {
return new Promise((resolve, reject) => {
if (state.lazyLoading) {
return resolve()
}
commit('changeLazyLoading', true)
const client = new Mastodon(
{
access_token: rootState.TimelineSpace.account.accessToken,
api_url: rootState.TimelineSpace.account.baseURL + '/api/v1'
})
client.get(`/timelines/tag/${obj.tag}`, { max_id: obj.last.id, limit: 40 }, (err, data, res) => {
if (err) return reject(err)
if (state.lazyLoading) {
return Promise.resolve(null)
}
commit('changeLazyLoading', true)
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.get(`/timelines/tag/${obj.tag}`, { max_id: obj.last.id, limit: 40 })
.then(data => {
commit('insertTimeline', data)
commit('changeLazyLoading', false)
return data
})
.catch(err => {
commit('changeLazyLoading', false)
throw err
})
})
}
}
}

View File

@ -1,4 +1,4 @@
import Mastodon from 'mastodon-api'
import Mastodon from 'megalodon'
const Home = {
namespaced: true,
@ -68,40 +68,38 @@ const Home = {
},
actions: {
fetchTimeline ({ state, commit, rootState }, account) {
return new Promise((resolve, reject) => {
const client = new Mastodon(
{
access_token: rootState.TimelineSpace.account.accessToken,
api_url: rootState.TimelineSpace.account.baseURL + '/api/v1'
}
)
client.get('/timelines/home', { limit: 40 }, (err, data, res) => {
if (err) return reject(err)
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.get('/timelines/home', { limit: 40 })
.then(data => {
commit('updateTimeline', data)
resolve(res)
return data
})
})
},
lazyFetchTimeline ({ state, commit, rootState }, last) {
if (last === undefined || last === null) {
return null
return Promise.resolve(null)
}
return new Promise((resolve, reject) => {
if (state.lazyLoading) {
return resolve()
}
commit('changeLazyLoading', true)
const client = new Mastodon(
{
access_token: rootState.TimelineSpace.account.accessToken,
api_url: rootState.TimelineSpace.account.baseURL + '/api/v1'
})
client.get('/timelines/home', { max_id: last.id, limit: 40 }, (err, data, res) => {
if (state.lazyLoading) {
return Promise.resolve(null)
}
commit('changeLazyLoading', true)
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.get('/timelines/home', { max_id: last.id, limit: 40 })
.then(data => {
commit('changeLazyLoading', false)
if (err) return reject(err)
commit('insertTimeline', data)
return data
})
.catch(err => {
commit('changeLazyLoading', false)
throw err
})
})
}
}
}

View File

@ -1,5 +1,5 @@
import { ipcRenderer } from 'electron'
import Mastodon from 'mastodon-api'
import Mastodon from 'megalodon'
const Lists = {
namespaced: true,
@ -68,18 +68,15 @@ const Lists = {
},
actions: {
fetchTimeline ({ state, commit, rootState }, listID) {
return new Promise((resolve, reject) => {
const client = new Mastodon(
{
access_token: rootState.TimelineSpace.account.accessToken,
api_url: rootState.TimelineSpace.account.baseURL + '/api/v1'
})
client.get(`/timelines/list/${listID}`, { limit: 40 }, (err, data, res) => {
if (err) return reject(err)
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.get(`/timelines/list/${listID}`, { limit: 40 })
.then(data => {
commit('updateTimeline', data)
resolve(res)
return data
})
})
},
startStreaming ({ state, commit, rootState }, listID) {
ipcRenderer.on('update-start-list-streaming', (event, update) => {
@ -107,22 +104,24 @@ const Lists = {
})
},
lazyFetchTimeline ({ state, commit, rootState }, obj) {
return new Promise((resolve, reject) => {
if (state.lazyLoading) {
return resolve()
}
commit('changeLazyLoading', true)
const client = new Mastodon(
{
access_token: rootState.TimelineSpace.account.accessToken,
api_url: rootState.TimelineSpace.account.baseURL + '/api/v1'
})
client.get(`/timelines/list/${obj.list_id}`, { max_id: obj.last.id, limit: 40 }, (err, data, res) => {
if (err) return reject(err)
if (state.lazyLoading) {
return Promise.resolve(null)
}
commit('changeLazyLoading', true)
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.get(`/timelines/list/${obj.list_id}`, { max_id: obj.last.id, limit: 40 })
.then(data => {
commit('insertTimeline', data)
commit('changeLazyLoading', false)
return data
})
.catch(err => {
commit('changeLazyLoading', false)
throw err
})
})
}
}
}

View File

@ -1,4 +1,4 @@
import Mastodon from 'mastodon-api'
import Mastodon from 'megalodon'
const Local = {
namespaced: true,
@ -67,40 +67,38 @@ const Local = {
},
actions: {
fetchLocalTimeline ({ commit }, account) {
return new Promise((resolve, reject) => {
const client = new Mastodon(
{
access_token: account.accessToken,
api_url: account.baseURL + '/api/v1'
}
)
client.get('/timelines/public', { limit: 40, local: true }, (err, data, res) => {
if (err) return reject(err)
const client = new Mastodon(
account.accessToken,
account.baseURL + '/api/v1'
)
return client.get('/timelines/public', { limit: 40, local: true })
.then(data => {
commit('updateTimeline', data)
resolve(res)
return data
})
})
},
lazyFetchTimeline ({ state, commit, rootState }, last) {
if (last === undefined || last === null) {
return null
return Promise.resolve(null)
}
return new Promise((resolve, reject) => {
if (state.lazyLoading) {
return resolve()
}
commit('changeLazyLoading', true)
const client = new Mastodon(
{
access_token: rootState.TimelineSpace.account.accessToken,
api_url: rootState.TimelineSpace.account.baseURL + '/api/v1'
})
client.get('/timelines/public', { max_id: last.id, limit: 40, local: true }, (err, data, res) => {
if (err) return reject(err)
commit('insertTimeline', data)
if (state.lazyLoading) {
return Promise.resolve(null)
}
commit('changeLazyLoading', true)
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.get('/timelines/public', { max_id: last.id, limit: 40, local: true })
.then(data => {
commit('changeLazyLoading', false)
commit('insertTimeline', data)
return data
})
.catch(err => {
commit('changeLazyLoading', false)
throw err
})
})
}
}
}

View File

@ -1,4 +1,4 @@
import Mastodon from 'mastodon-api'
import Mastodon from 'megalodon'
const Notifications = {
namespaced: true,
@ -55,40 +55,38 @@ const Notifications = {
},
actions: {
fetchNotifications ({ commit }, account) {
return new Promise((resolve, reject) => {
const client = new Mastodon(
{
access_token: account.accessToken,
api_url: account.baseURL + '/api/v1'
}
)
client.get('/notifications', { limit: 30 }, (err, data, res) => {
if (err) return reject(err)
const client = new Mastodon(
account.accessToken,
account.baseURL + '/api/v1'
)
return client.get('/notifications', { limit: 30 })
.then(data => {
commit('updateNotifications', data)
resolve(res)
return data
})
})
},
lazyFetchNotifications ({ state, commit, rootState }, last) {
if (last === undefined || last === null) {
return null
return Promise.resolve(null)
}
return new Promise((resolve, reject) => {
if (state.lazyLoading) {
return resolve()
}
commit('changeLazyLoading', true)
const client = new Mastodon(
{
access_token: rootState.TimelineSpace.account.accessToken,
api_url: rootState.TimelineSpace.account.baseURL + '/api/v1'
})
client.get('/notifications', { max_id: last.id, limit: 30 }, (err, data, res) => {
if (err) return reject(err)
commit('insertNotifications', data)
if (state.lazyLoading) {
return Promise.resolve(null)
}
commit('changeLazyLoading', true)
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.get('/notifications', { max_id: last.id, limit: 30 })
.then(data => {
commit('changeLazyLoading', false)
commit('insertNotifications', data)
return data
})
.catch(err => {
commit('changeLazyLoading', false)
throw err
})
})
}
}
}

View File

@ -1,5 +1,5 @@
import { ipcRenderer } from 'electron'
import Mastodon from 'mastodon-api'
import Mastodon from 'megalodon'
const Public = {
namespaced: true,
@ -68,19 +68,14 @@ const Public = {
},
actions: {
fetchPublicTimeline ({ state, commit, rootState }) {
return new Promise((resolve, reject) => {
const client = new Mastodon(
{
access_token: rootState.TimelineSpace.account.accessToken,
api_url: rootState.TimelineSpace.account.baseURL + '/api/v1'
}
)
client.get('/timelines/public', { limit: 40 }, (err, data, res) => {
if (err) return reject(err)
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.get('/timelines/public', { limit: 40 })
.then(data => {
commit('updateTimeline', data)
resolve(res)
})
})
},
startPublicStreaming ({ state, commit, rootState }) {
ipcRenderer.on('update-start-public-streaming', (event, update) => {
@ -103,24 +98,26 @@ const Public = {
},
lazyFetchTimeline ({ state, commit, rootState }, last) {
if (last === undefined || last === null) {
return null
return Promise.resolve(null)
}
return new Promise((resolve, reject) => {
if (state.lazyLoading) {
return resolve()
}
commit('changeLazyLoading', true)
const client = new Mastodon(
{
access_token: rootState.TimelineSpace.account.accessToken,
api_url: rootState.TimelineSpace.account.baseURL + '/api/v1'
})
client.get('/timelines/public', { max_id: last.id, limit: 40 }, (err, data, res) => {
if (err) return reject(err)
if (state.lazyLoading) {
return Promise.resolve(null)
}
commit('changeLazyLoading', true)
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.get('/timelines/public', { max_id: last.id, limit: 40 })
.then(data => {
commit('insertTimeline', data)
commit('changeLazyLoading', false)
return data
})
.catch(err => {
commit('changeLazyLoading', false)
throw err
})
})
}
}
}

View File

@ -1,4 +1,4 @@
import Mastodon from 'mastodon-api'
import Mastodon from 'megalodon'
const Account = {
namespaced: true,
@ -12,20 +12,21 @@ const Account = {
},
actions: {
search ({ state, commit, rootState }, query) {
return new Promise((resolve, reject) => {
commit('TimelineSpace/Contents/Search/changeLoading', true, { root: true })
const client = new Mastodon(
{
access_token: rootState.TimelineSpace.account.accessToken,
api_url: rootState.TimelineSpace.account.baseURL + '/api/v1'
})
client.get('/search', { q: query }, (err, data, res) => {
if (err) return reject(err)
commit('TimelineSpace/Contents/Search/changeLoading', true, { root: true })
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.get('/search', { q: query })
.then(data => {
commit('updateResults', data.accounts)
commit('TimelineSpace/Contents/Search/changeLoading', false, { root: true })
resolve(res)
return data
})
.catch(err => {
commit('TimelineSpace/Contents/Search/changeLoading', false, { root: true })
throw err
})
})
}
}
}

View File

@ -1,4 +1,4 @@
import Mastodon from 'mastodon-api'
import Mastodon from 'megalodon'
import Timeline from './AccountProfile/Timeline'
import Follows from './AccountProfile/Follows'
import Followers from './AccountProfile/Followers'
@ -28,70 +28,65 @@ const AccountProfile = {
},
actions: {
searchAccount ({ commit, rootState }, accountURL) {
return new Promise((resolve, reject) => {
const client = new Mastodon(
{
access_token: rootState.TimelineSpace.account.accessToken,
api_url: rootState.TimelineSpace.account.baseURL + '/api/v1'
}
)
client.get('/search', { q: accountURL }, (err, data, res) => {
if (err) return reject(err)
if (data.accounts.length <= 0) return reject(new AccountNotFound('not found'))
resolve(data.accounts[0])
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.get('/search', { q: accountURL })
.then(data => {
if (data.accounts.length <= 0) throw new AccountNotFound('not found')
return data.accounts[0]
})
})
},
changeAccount ({ commit, dispatch }, account) {
dispatch('fetchRelationship', account)
commit('changeAccount', account)
},
fetchRelationship ({ state, commit, rootState }, account) {
return new Promise((resolve, reject) => {
commit('changeRelationship', null)
const client = new Mastodon(
{
access_token: rootState.TimelineSpace.account.accessToken,
api_url: rootState.TimelineSpace.account.baseURL + '/api/v1'
})
client.get('/accounts/relationships', { id: [account.id] }, (err, data, res) => {
if (err) return reject(err)
commit('changeRelationship', null)
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.get('/accounts/relationships', { id: [account.id] })
.then(data => {
commit('changeRelationship', data[0])
resolve(res)
return data
})
})
},
follow ({ state, commit, rootState }, account) {
return new Promise((resolve, reject) => {
commit('changeLoading', true)
const client = new Mastodon(
{
access_token: rootState.TimelineSpace.account.accessToken,
api_url: rootState.TimelineSpace.account.baseURL + '/api/v1'
})
client.post(`/accounts/${account.id}/follow`, {}, (err, data, res) => {
commit('changeLoading', true)
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.post(`/accounts/${account.id}/follow`)
.then(data => {
commit('changeLoading', false)
if (err) return reject(err)
commit('changeRelationship', data)
resolve(res)
return data
})
.catch(err => {
commit('changeLoading', false)
throw err
})
})
},
unfollow ({ state, commit, rootState }, account) {
return new Promise((resolve, reject) => {
commit('changeLoading', true)
const client = new Mastodon(
{
access_token: rootState.TimelineSpace.account.accessToken,
api_url: rootState.TimelineSpace.account.baseURL + '/api/v1'
})
client.post(`/accounts/${account.id}/unfollow`, {}, (err, data, res) => {
commit('changeLoading', true)
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.post(`/accounts/${account.id}/unfollow`)
.then(data => {
commit('changeLoading', false)
if (err) return reject(err)
commit('changeRelationship', data)
resolve(res)
return data
})
.catch(err => {
commit('changeLoading', false)
throw err
})
})
},
close ({ commit }) {
commit('changeAccount', null)

View File

@ -1,4 +1,4 @@
import Mastodon from 'mastodon-api'
import Mastodon from 'megalodon'
const Followers = {
namespaced: true,
@ -12,20 +12,17 @@ const Followers = {
},
actions: {
fetchFollowers ({ state, commit, rootState }, account) {
return new Promise((resolve, reject) => {
commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', true, { root: true })
const client = new Mastodon(
{
access_token: rootState.TimelineSpace.account.accessToken,
api_url: rootState.TimelineSpace.account.baseURL + '/api/v1'
})
client.get(`/accounts/${account.id}/followers`, { limit: 80 }, (err, data, res) => {
if (err) return reject(err)
commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', true, { root: true })
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.get(`/accounts/${account.id}/followers`, { limit: 80 })
.then(data => {
commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', false, { root: true })
commit('updateFollowers', data)
resolve(res)
return data
})
})
}
}
}

View File

@ -1,4 +1,4 @@
import Mastodon from 'mastodon-api'
import Mastodon from 'megalodon'
const Follows = {
namespaced: true,
@ -12,20 +12,17 @@ const Follows = {
},
actions: {
fetchFollows ({ state, commit, rootState }, account) {
return new Promise((resolve, reject) => {
commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', true, { root: true })
const client = new Mastodon(
{
access_token: rootState.TimelineSpace.account.accessToken,
api_url: rootState.TimelineSpace.account.baseURL + '/api/v1'
})
client.get(`/accounts/${account.id}/following`, { limit: 80 }, (err, data, res) => {
if (err) return reject(err)
commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', true, { root: true })
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.get(`/accounts/${account.id}/following`, { limit: 80 })
.then(data => {
commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', false, { root: true })
commit('updateFollows', data)
resolve(res)
return data
})
})
}
}
}

View File

@ -1,4 +1,4 @@
import Mastodon from 'mastodon-api'
import Mastodon from 'megalodon'
const Timeline = {
namespaced: true,
@ -45,42 +45,41 @@ const Timeline = {
},
actions: {
fetchTimeline ({ state, commit, rootState }, account) {
return new Promise((resolve, reject) => {
commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', true, { root: true })
const client = new Mastodon(
{
access_token: rootState.TimelineSpace.account.accessToken,
api_url: rootState.TimelineSpace.account.baseURL + '/api/v1'
})
client.get(`/accounts/${account.id}/statuses`, { limit: 40 }, (err, data, res) => {
if (err) return reject(err)
commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', true, { root: true })
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.get(`/accounts/${account.id}/statuses`, { limit: 40 })
.then(data => {
commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', false, { root: true })
commit('updateTimeline', data)
resolve(res)
return data
})
})
},
lazyFetchTimeline ({ state, commit, rootState }, info) {
const last = info.last
if (last === undefined || last === null) {
return null
return Promise.resolve(null)
}
return new Promise((resolve, reject) => {
if (state.lazyLoading) {
return resolve()
}
commit('changeLazyLoading', true)
const client = new Mastodon(
{
access_token: rootState.TimelineSpace.account.accessToken,
api_url: rootState.TimelineSpace.account.baseURL + '/api/v1'
})
client.get(`/accounts/${info.account.id}/statuses`, { max_id: last.id, limit: 40 }, (err, data, res) => {
if (state.lazyLoading) {
return Promise.resolve(null)
}
commit('changeLazyLoading', true)
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.get(`/accounts/${info.account.id}/statuses`, { max_id: last.id, limit: 40 })
.then(data => {
commit('changeLazyLoading', false)
if (err) return reject(err)
commit('insertTimeline', data)
return data
})
.catch(err => {
commit('changeLazyLoading', false)
throw err
})
})
}
}
}

View File

@ -1,4 +1,4 @@
import Mastodon from 'mastodon-api'
import Mastodon from 'megalodon'
const TootDetail = {
namespaced: true,
@ -92,19 +92,16 @@ const TootDetail = {
commit('changeToot', message)
},
fetchToot ({ state, commit, rootState }, message) {
return new Promise((resolve, reject) => {
const client = new Mastodon(
{
access_token: rootState.TimelineSpace.account.accessToken,
api_url: rootState.TimelineSpace.account.baseURL + '/api/v1'
})
client.get(`/statuses/${message.id}/context`, { limit: 40 }, (err, data, res) => {
if (err) return reject(err)
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.get(`/statuses/${message.id}/context`, { limit: 40 })
.then(data => {
commit('updateAncestors', data.ancestors)
commit('updateDescendants', data.descendants)
resolve(res)
return data
})
})
}
}
}

View File

@ -1,4 +1,4 @@
import Mastodon from 'mastodon-api'
import Mastodon from 'megalodon'
const HeaderMenu = {
namespaced: true,
@ -12,19 +12,15 @@ const HeaderMenu = {
},
actions: {
fetchList ({ state, commit, rootState }, listID) {
return new Promise((resolve, reject) => {
const client = new Mastodon(
{
access_token: rootState.TimelineSpace.account.accessToken,
api_url: rootState.TimelineSpace.account.baseURL + '/api/v1'
}
)
client.get(`/lists/${listID}`, {}, (err, data, res) => {
if (err) return reject(err)
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.get(`/lists/${listID}`)
.then(data => {
commit('updateTitle', `#${data.title}`)
resolve(res)
return data
})
})
}
}
}

View File

@ -1,6 +1,5 @@
import Mastodon from 'mastodon-api'
import Mastodon from 'megalodon'
import { ipcRenderer } from 'electron'
import fs from 'fs'
const NewToot = {
namespaced: true,
@ -48,22 +47,18 @@ const NewToot = {
},
actions: {
postToot ({ state, commit, rootState }, form) {
return new Promise((resolve, reject) => {
if (rootState.TimelineSpace.account.accessToken === undefined || rootState.TimelineSpace.account.accessToken === null) {
return reject(new AuthenticationError())
}
const client = new Mastodon(
{
access_token: rootState.TimelineSpace.account.accessToken,
api_url: rootState.TimelineSpace.account.baseURL + '/api/v1'
}
)
client.post('/statuses', form, (err, data, res) => {
if (err) return reject(err)
if (rootState.TimelineSpace.account.accessToken === undefined || rootState.TimelineSpace.account.accessToken === null) {
throw new AuthenticationError()
}
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.post('/statuses', form)
.then(data => {
ipcRenderer.send('toot-action-sound')
resolve(res)
return data
})
})
},
openReply ({ commit, rootState }, message) {
commit('setReplyTo', message)
@ -85,25 +80,28 @@ const NewToot = {
}
},
uploadImage ({ state, commit, rootState }, image) {
return new Promise((resolve, reject) => {
commit('changeBlockSubmit', true)
if (rootState.TimelineSpace.account.accessToken === undefined || rootState.TimelineSpace.account.accessToken === null) {
return reject(new AuthenticationError())
}
const client = new Mastodon(
{
access_token: rootState.TimelineSpace.account.accessToken,
api_url: rootState.TimelineSpace.account.baseURL + '/api/v1'
}
)
client.post('/media', { file: fs.createReadStream(image.path) }, (err, data, res) => {
commit('changeBlockSubmit', true)
if (rootState.TimelineSpace.account.accessToken === undefined || rootState.TimelineSpace.account.accessToken === null) {
throw new AuthenticationError()
}
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
const formData = new FormData()
formData.append('file', image)
return client.post('/media', formData)
.then(data => {
commit('changeBlockSubmit', false)
if (err) return reject(err)
if (data.type !== 'image') reject(new UnknownTypeError())
if (data.type !== 'image') throw new UnknownTypeError()
commit('appendAttachedMedias', data)
resolve(res)
return data
})
.catch(err => {
commit('changeBlockSubmit', false)
console.error(err)
throw err
})
})
}
}
}

View File

@ -1,4 +1,4 @@
import Mastodon from 'mastodon-api'
import Mastodon from 'megalodon'
const SideMenu = {
namespaced: true,
@ -28,19 +28,15 @@ const SideMenu = {
},
actions: {
fetchLists ({ commit }, account) {
return new Promise((resolve, reject) => {
const client = new Mastodon(
{
access_token: account.accessToken,
api_url: account.baseURL + '/api/v1'
}
)
client.get('/lists', {}, (err, data, res) => {
if (err) return reject(err)
const client = new Mastodon(
account.accessToken,
account.baseURL + '/api/v1'
)
return client.get('/lists')
.then(data => {
commit('updateLists', data)
resolve(res)
return data
})
})
},
clearUnread ({ commit }) {
commit('changeUnreadHomeTimeline', false)