refs #16 Provide callback function when use mastodon-api

This commit is contained in:
AkiraFukushima 2018-03-13 19:18:02 +09:00
parent 144ee0844c
commit c559275cca
4 changed files with 42 additions and 34 deletions

6
package-lock.json generated
View File

@ -493,9 +493,9 @@
"integrity": "sha1-g+9cqGCysy5KDe7e6MdxudtXRx4="
},
"axios": {
"version": "0.16.2",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.16.2.tgz",
"integrity": "sha1-uk+S8XFn37q0CYN4VFS5rBScPG0=",
"version": "0.18.0",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.18.0.tgz",
"integrity": "sha1-MtU+SFHv3AoRmTts0AB4nXDAUQI=",
"requires": {
"follow-redirects": "1.4.1",
"is-buffer": "1.1.6"

View File

@ -56,7 +56,7 @@
}
},
"dependencies": {
"axios": "^0.16.1",
"axios": "^0.18.0",
"element-ui": "^2.2.1",
"google-fonts-webpack-plugin": "^0.4.4",
"is-empty": "^1.2.0",

View File

@ -19,9 +19,27 @@ export default {
this.$store.dispatch('TimelineSpace/fetchAccount', this.$route.params.id)
.then((account) => {
this.$store.dispatch('TimelineSpace/fetchHomeTimeline', account)
.catch(() => {
this.$message({
message: 'Could not fetch timeline',
type: 'error'
})
})
this.$store.dispatch('TimelineSpace/startUserStreaming', account)
this.$store.dispatch('TimelineSpace/username', account)
.catch(() => {
this.$message({
message: 'Could not fetch username',
type: 'error'
})
})
this.$store.dispatch('TimelineSpace/fetchNotifications', account)
.catch(() => {
this.$message({
message: 'Could not fetch notification',
type: 'error'
})
})
this.$store.dispatch('TimelineSpace/watchShortcutEvents', account)
})
.catch(() => {

View File

@ -63,11 +63,11 @@ const TimelineSpace = {
access_token: account.accessToken,
api_url: account.baseURL + '/api/v1'
})
client.get('/accounts/verify_credentials', {})
.then((res) => {
commit('updateUsername', res.data.username)
resolve(res)
})
client.get('/accounts/verify_credentials', (err, data, res) => {
if (err) return reject(err)
commit('updateUsername', data.username)
resolve(res)
})
})
},
startUserStreaming ({ commit }, account) {
@ -105,14 +105,11 @@ const TimelineSpace = {
api_url: account.baseURL + '/api/v1'
}
)
client.get('/timelines/home', { limit: 40 })
.then((res) => {
commit('insertHomeTimeline', res.data)
resolve()
})
.catch((err) => {
reject(err)
})
client.get('/timelines/home', { limit: 40 }, (err, data, res) => {
if (err) return reject(err)
commit('insertHomeTimeline', data)
resolve(res)
})
})
},
fetchNotifications ({ commit }, account) {
@ -123,14 +120,11 @@ const TimelineSpace = {
api_url: account.baseURL + '/api/v1'
}
)
client.get('/notifications', { limit: 30 })
.then((res) => {
commit('insertNotifications', res.data)
resolve()
})
.catch((err) => {
reject(err)
})
client.get('/notifications', { limit: 30 }, (err, data, res) => {
if (err) return reject(err)
commit('insertNotifications', data)
resolve(res)
})
})
},
postToot ({ commit, state }, body) {
@ -146,14 +140,11 @@ const TimelineSpace = {
)
client.post('/statuses', {
status: body
}, (err, data, res) => {
if (err) return reject(err)
commit('changeNewTootModal', false)
resolve(res)
})
.then((res) => {
commit('changeNewTootModal', false)
resolve(res)
})
.catch((err) => {
reject(err)
})
})
}
}
@ -161,8 +152,7 @@ const TimelineSpace = {
export default TimelineSpace
class AuthenticationError {
}
class AuthenticationError {}
function buildNotification (notification) {
switch (notification.type) {