From 9c7225d493832c48ea999b906f22a816b630a8bb Mon Sep 17 00:00:00 2001
From: AkiraFukushima
Date: Sat, 24 Mar 2018 01:31:39 +0900
Subject: [PATCH 1/4] fix: Replace timeline when fetch timeline at first
---
src/renderer/store/TimelineSpace.js | 12 ++++++------
src/renderer/store/TimelineSpace/Favourites.js | 4 ++--
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/renderer/store/TimelineSpace.js b/src/renderer/store/TimelineSpace.js
index 8af31664..a1e37ade 100644
--- a/src/renderer/store/TimelineSpace.js
+++ b/src/renderer/store/TimelineSpace.js
@@ -42,11 +42,11 @@ const TimelineSpace = {
appendNotifications (state, notifications) {
state.notifications = [notifications].concat(state.notifications)
},
- insertHomeTimeline (state, messages) {
- state.homeTimeline = state.homeTimeline.concat(messages)
+ updateHomeTimeline (state, messages) {
+ state.homeTimeline = messages
},
- insertNotifications (state, notifications) {
- state.notifications = state.notifications.concat(notifications)
+ updateNotifications (state, notifications) {
+ state.notifications = notifications
},
updateToot (state, message) {
// Replace target message in homeTimeline and notifications
@@ -163,7 +163,7 @@ const TimelineSpace = {
)
client.get('/timelines/home', { limit: 40 }, (err, data, res) => {
if (err) return reject(err)
- commit('insertHomeTimeline', data)
+ commit('updateHomeTimeline', data)
resolve(res)
})
})
@@ -178,7 +178,7 @@ const TimelineSpace = {
)
client.get('/notifications', { limit: 30 }, (err, data, res) => {
if (err) return reject(err)
- commit('insertNotifications', data)
+ commit('updateNotifications', data)
resolve(res)
})
})
diff --git a/src/renderer/store/TimelineSpace/Favourites.js b/src/renderer/store/TimelineSpace/Favourites.js
index f0463f78..efce75da 100644
--- a/src/renderer/store/TimelineSpace/Favourites.js
+++ b/src/renderer/store/TimelineSpace/Favourites.js
@@ -6,7 +6,7 @@ const Favourites = {
favourites: []
},
mutations: {
- insertFavourites (state, favourites) {
+ updateFavourites (state, favourites) {
state.favourites = favourites
},
updateToot (state, message) {
@@ -37,7 +37,7 @@ const Favourites = {
)
client.get('/favourites', { limit: 40 }, (err, data, res) => {
if (err) return reject(err)
- commit('insertFavourites', data)
+ commit('updateFavourites', data)
resolve(res)
})
})
From c70251e9a984156cb4afe76e83bfcc0420c046f6 Mon Sep 17 00:00:00 2001
From: AkiraFukushima
Date: Sat, 24 Mar 2018 01:48:05 +0900
Subject: [PATCH 2/4] refs #105 Get recent timeline in local
---
.../components/TimelineSpace/Local.vue | 25 ++++++++++++++++++-
src/renderer/store/TimelineSpace/Local.js | 19 ++++++++++++++
2 files changed, 43 insertions(+), 1 deletion(-)
diff --git a/src/renderer/components/TimelineSpace/Local.vue b/src/renderer/components/TimelineSpace/Local.vue
index 83e19f14..d88124e5 100644
--- a/src/renderer/components/TimelineSpace/Local.vue
+++ b/src/renderer/components/TimelineSpace/Local.vue
@@ -20,12 +20,35 @@ export default {
})
},
created () {
- this.$store.dispatch('TimelineSpace/Local/startLocalStreaming', this.account)
+ const loading = this.$loading({
+ lock: true,
+ text: 'Loading',
+ spinner: 'el-icon-loading',
+ background: 'rgba(0, 0, 0, 0.7)'
+ })
+ this.initialize()
+ .then(() => {
+ loading.close()
+ })
+ .catch(() => {
+ loading.close()
+ })
},
beforeDestroy () {
this.$store.dispatch('TimelineSpace/Local/stopLocalStreaming')
},
methods: {
+ async initialize () {
+ try {
+ await this.$store.dispatch('TimelineSpace/Local/fetchLocalTimeline', this.account)
+ } catch (err) {
+ this.$message({
+ message: 'Could not fetch timeline',
+ type: 'error'
+ })
+ }
+ this.$store.dispatch('TimelineSpace/Local/startLocalStreaming', this.account)
+ },
updateToot (message) {
this.$store.commit('TimelineSpace/Local/updateToot', message)
}
diff --git a/src/renderer/store/TimelineSpace/Local.js b/src/renderer/store/TimelineSpace/Local.js
index 693fa55f..38f17982 100644
--- a/src/renderer/store/TimelineSpace/Local.js
+++ b/src/renderer/store/TimelineSpace/Local.js
@@ -1,4 +1,5 @@
import { ipcRenderer } from 'electron'
+import Mastodon from 'mastodon-api'
const Local = {
namespaced: true,
@@ -9,6 +10,9 @@ const Local = {
appendTimeline (state, update) {
state.timeline = [update].concat(state.timeline)
},
+ updateTimeline (state, messages) {
+ state.timeline = messages
+ },
updateToot (state, message) {
state.timeline = state.timeline.map((toot) => {
if (toot.id === message.id) {
@@ -27,6 +31,21 @@ 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)
+ commit('updateTimeline', data)
+ resolve(res)
+ })
+ })
+ },
startLocalStreaming ({ commit }, account) {
ipcRenderer.on('update-start-local-streaming', (event, update) => {
commit('appendTimeline', update)
From 1dd04b9f3c7cac7b0436f585264a8527d373ef09 Mon Sep 17 00:00:00 2001
From: AkiraFukushima
Date: Sat, 24 Mar 2018 01:50:42 +0900
Subject: [PATCH 3/4] refs #105 Get account information from rootState
---
src/renderer/components/TimelineSpace/Local.vue | 5 ++---
src/renderer/store/TimelineSpace/Local.js | 10 +++++-----
2 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/src/renderer/components/TimelineSpace/Local.vue b/src/renderer/components/TimelineSpace/Local.vue
index d88124e5..c5effa98 100644
--- a/src/renderer/components/TimelineSpace/Local.vue
+++ b/src/renderer/components/TimelineSpace/Local.vue
@@ -15,7 +15,6 @@ export default {
components: { Toot },
computed: {
...mapState({
- account: state => state.TimelineSpace.account,
timeline: state => state.TimelineSpace.Local.timeline
})
},
@@ -40,14 +39,14 @@ export default {
methods: {
async initialize () {
try {
- await this.$store.dispatch('TimelineSpace/Local/fetchLocalTimeline', this.account)
+ await this.$store.dispatch('TimelineSpace/Local/fetchLocalTimeline')
} catch (err) {
this.$message({
message: 'Could not fetch timeline',
type: 'error'
})
}
- this.$store.dispatch('TimelineSpace/Local/startLocalStreaming', this.account)
+ this.$store.dispatch('TimelineSpace/Local/startLocalStreaming')
},
updateToot (message) {
this.$store.commit('TimelineSpace/Local/updateToot', message)
diff --git a/src/renderer/store/TimelineSpace/Local.js b/src/renderer/store/TimelineSpace/Local.js
index 38f17982..7bb50d48 100644
--- a/src/renderer/store/TimelineSpace/Local.js
+++ b/src/renderer/store/TimelineSpace/Local.js
@@ -31,12 +31,12 @@ const Local = {
}
},
actions: {
- fetchLocalTimeline ({ commit }, account) {
+ fetchLocalTimeline ({ state, commit, rootState }) {
return new Promise((resolve, reject) => {
const client = new Mastodon(
{
- access_token: account.accessToken,
- api_url: account.baseURL + '/api/v1'
+ access_token: rootState.TimelineSpace.account.accessToken,
+ api_url: rootState.TimelineSpace.account.baseURL + '/api/v1'
}
)
client.get('/timelines/public', { limit: 40, local: true }, (err, data, res) => {
@@ -46,12 +46,12 @@ const Local = {
})
})
},
- startLocalStreaming ({ commit }, account) {
+ startLocalStreaming ({ state, commit, rootState }) {
ipcRenderer.on('update-start-local-streaming', (event, update) => {
commit('appendTimeline', update)
})
return new Promise((resolve, reject) => {
- ipcRenderer.send('start-local-streaming', account)
+ ipcRenderer.send('start-local-streaming', rootState.TimelineSpace.account)
ipcRenderer.once('error-start-local-streaming', (event, err) => {
reject(err)
})
From 0dcca6316d02d82c4f08e30d0d8bb73857aac7f9 Mon Sep 17 00:00:00 2001
From: AkiraFukushima
Date: Sat, 24 Mar 2018 09:33:58 +0900
Subject: [PATCH 4/4] refs #105 Get recent timeline in public
---
.../components/TimelineSpace/Public.vue | 26 +++++++++++++++++--
src/renderer/store/TimelineSpace/Public.js | 23 ++++++++++++++--
2 files changed, 45 insertions(+), 4 deletions(-)
diff --git a/src/renderer/components/TimelineSpace/Public.vue b/src/renderer/components/TimelineSpace/Public.vue
index 981a5581..99d8f765 100644
--- a/src/renderer/components/TimelineSpace/Public.vue
+++ b/src/renderer/components/TimelineSpace/Public.vue
@@ -15,17 +15,39 @@ export default {
components: { Toot },
computed: {
...mapState({
- account: state => state.TimelineSpace.account,
timeline: state => state.TimelineSpace.Public.timeline
})
},
created () {
- this.$store.dispatch('TimelineSpace/Public/startPublicStreaming', this.account)
+ const loading = this.$loading({
+ lock: true,
+ text: 'Loading',
+ spinner: 'el-icon-loading',
+ background: 'rgba(0, 0, 0, 0.7)'
+ })
+ this.initialize()
+ .then(() => {
+ loading.close()
+ })
+ .catch(() => {
+ loading.close()
+ })
},
beforeDestroy () {
this.$store.dispatch('TimelineSpace/Public/stopPublicStreaming')
},
methods: {
+ async initialize () {
+ try {
+ await this.$store.dispatch('TimelineSpace/Public/fetchPublicTimeline')
+ } catch (err) {
+ this.$message({
+ message: 'Could not fetch timeline',
+ type: 'error'
+ })
+ }
+ this.$store.dispatch('TimelineSpace/Public/startPublicStreaming')
+ },
updateToot (message) {
this.$store.commit('TimelineSpace/Public/updateToot', message)
}
diff --git a/src/renderer/store/TimelineSpace/Public.js b/src/renderer/store/TimelineSpace/Public.js
index 6174f61c..cdfa2aae 100644
--- a/src/renderer/store/TimelineSpace/Public.js
+++ b/src/renderer/store/TimelineSpace/Public.js
@@ -1,4 +1,5 @@
import { ipcRenderer } from 'electron'
+import Mastodon from 'mastodon-api'
const Public = {
namespaced: true,
@@ -9,6 +10,9 @@ const Public = {
appendTimeline (state, update) {
state.timeline = [update].concat(state.timeline)
},
+ updateTimeline (state, messages) {
+ state.timeline = messages
+ },
updateToot (state, message) {
state.timeline = state.timeline.map((toot) => {
if (toot.id === message.id) {
@@ -27,12 +31,27 @@ const Public = {
}
},
actions: {
- startPublicStreaming ({ commit }, account) {
+ 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)
+ commit('updateTimeline', data)
+ resolve(res)
+ })
+ })
+ },
+ startPublicStreaming ({ state, commit, rootState }) {
ipcRenderer.on('update-start-public-streaming', (event, update) => {
commit('appendTimeline', update)
})
return new Promise((resolve, reject) => {
- ipcRenderer.send('start-public-streaming', account)
+ ipcRenderer.send('start-public-streaming', rootState.TimelineSpace.account)
ipcRenderer.once('error-start-public-streaming', (event, err) => {
reject(err)
})