From c559275cca5b0816c8af49d5f3efb1264e5cf0b6 Mon Sep 17 00:00:00 2001
From: AkiraFukushima
Date: Tue, 13 Mar 2018 19:18:02 +0900
Subject: [PATCH 1/3] refs #16 Provide callback function when use mastodon-api
---
package-lock.json | 6 +--
package.json | 2 +-
src/renderer/components/TimelineSpace.vue | 18 ++++++++
src/renderer/store/TimelineSpace.js | 50 +++++++++--------------
4 files changed, 42 insertions(+), 34 deletions(-)
diff --git a/package-lock.json b/package-lock.json
index dd3884ad..6ba56779 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -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"
diff --git a/package.json b/package.json
index 6562e0d4..2e4241ff 100644
--- a/package.json
+++ b/package.json
@@ -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",
diff --git a/src/renderer/components/TimelineSpace.vue b/src/renderer/components/TimelineSpace.vue
index e1820bf0..223e007a 100644
--- a/src/renderer/components/TimelineSpace.vue
+++ b/src/renderer/components/TimelineSpace.vue
@@ -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(() => {
diff --git a/src/renderer/store/TimelineSpace.js b/src/renderer/store/TimelineSpace.js
index 83fd067d..e3f115ff 100644
--- a/src/renderer/store/TimelineSpace.js
+++ b/src/renderer/store/TimelineSpace.js
@@ -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) {
From 4c227b2dfaa14184cd19303076f5c70b0af420ed Mon Sep 17 00:00:00 2001
From: AkiraFukushima
Date: Tue, 13 Mar 2018 22:25:31 +0900
Subject: [PATCH 2/3] refs #16 Error message when authorize
---
src/renderer/components/Authorize.vue | 6 ++++++
src/renderer/store/Authorize.js | 3 +--
src/renderer/store/TimelineSpace.js | 4 ++--
3 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/src/renderer/components/Authorize.vue b/src/renderer/components/Authorize.vue
index 70773123..2f89072b 100644
--- a/src/renderer/components/Authorize.vue
+++ b/src/renderer/components/Authorize.vue
@@ -27,6 +27,12 @@ export default {
.then((id) => {
this.$router.push({ path: `/${id}/home` })
})
+ .catch(() => {
+ this.$message({
+ message: 'Could not authorize the code',
+ type: 'error'
+ })
+ })
}
}
}
diff --git a/src/renderer/store/Authorize.js b/src/renderer/store/Authorize.js
index 128b8377..4745185a 100644
--- a/src/renderer/store/Authorize.js
+++ b/src/renderer/store/Authorize.js
@@ -9,11 +9,10 @@ const Authorize = {
return new Promise((resolve, reject) => {
ipcRenderer.send('get-access-token', code)
ipcRenderer.once('response-get-access-token', (event, id) => {
- console.log(id)
resolve(id)
})
ipcRenderer.once('error-get-access-token', (event, err) => {
- console.log(err)
+ reject(err)
})
})
}
diff --git a/src/renderer/store/TimelineSpace.js b/src/renderer/store/TimelineSpace.js
index e3f115ff..e0baab10 100644
--- a/src/renderer/store/TimelineSpace.js
+++ b/src/renderer/store/TimelineSpace.js
@@ -46,8 +46,6 @@ const TimelineSpace = {
return new Promise((resolve, reject) => {
ipcRenderer.send('get-local-account', id)
ipcRenderer.once('error-get-local-account', (event, err) => {
- // TODO: handle error
- console.log(err)
reject(err)
})
ipcRenderer.once('response-get-local-account', (event, account) => {
@@ -73,6 +71,7 @@ const TimelineSpace = {
startUserStreaming ({ commit }, account) {
ipcRenderer.send('start-user-streaming', account)
ipcRenderer.once('error-start-userstreaming', (event, err) => {
+ // handle error
console.log(err)
})
ipcRenderer.on('update-start-user-streaming', (event, update) => {
@@ -94,6 +93,7 @@ const TimelineSpace = {
commit('changeNewTootModal', true)
})
ipcRenderer.on('CmdOrCtrl+R', () => {
+ // TODO: reply window
console.log('reply')
})
},
From 0dc1788a89cfaa802f7ba453d95af3114e96e375 Mon Sep 17 00:00:00 2001
From: AkiraFukushima
Date: Tue, 13 Mar 2018 22:35:04 +0900
Subject: [PATCH 3/3] refs #16 Handle error when could not start user stream
---
src/renderer/components/TimelineSpace.vue | 6 ++++++
src/renderer/store/TimelineSpace.js | 12 +++++++-----
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/src/renderer/components/TimelineSpace.vue b/src/renderer/components/TimelineSpace.vue
index 223e007a..05c6e69b 100644
--- a/src/renderer/components/TimelineSpace.vue
+++ b/src/renderer/components/TimelineSpace.vue
@@ -26,6 +26,12 @@ export default {
})
})
this.$store.dispatch('TimelineSpace/startUserStreaming', account)
+ .catch(() => {
+ this.$message({
+ message: 'Could not start user streaming',
+ type: 'error'
+ })
+ })
this.$store.dispatch('TimelineSpace/username', account)
.catch(() => {
this.$message({
diff --git a/src/renderer/store/TimelineSpace.js b/src/renderer/store/TimelineSpace.js
index e0baab10..055cd3a9 100644
--- a/src/renderer/store/TimelineSpace.js
+++ b/src/renderer/store/TimelineSpace.js
@@ -69,11 +69,6 @@ const TimelineSpace = {
})
},
startUserStreaming ({ commit }, account) {
- ipcRenderer.send('start-user-streaming', account)
- ipcRenderer.once('error-start-userstreaming', (event, err) => {
- // handle error
- console.log(err)
- })
ipcRenderer.on('update-start-user-streaming', (event, update) => {
commit('appendHomeTimeline', update)
})
@@ -84,6 +79,13 @@ const TimelineSpace = {
}
commit('appendNotifications', notification)
})
+
+ return new Promise((resolve, reject) => {
+ ipcRenderer.send('start-user-streaming', account)
+ ipcRenderer.once('error-start-userstreaming', (event, err) => {
+ reject(err)
+ })
+ })
},
stopUserStreaming ({ commit }) {
ipcRenderer.send('stop-user-streaming')