mirror of
https://github.com/h3poteto/whalebird-desktop
synced 2025-02-04 11:17:32 +01:00
Merge pull request #109 from h3poteto/iss-105
closes #105 Get recent timeline in local and public
This commit is contained in:
commit
b5b97d554e
@ -15,17 +15,39 @@ export default {
|
|||||||
components: { Toot },
|
components: { Toot },
|
||||||
computed: {
|
computed: {
|
||||||
...mapState({
|
...mapState({
|
||||||
account: state => state.TimelineSpace.account,
|
|
||||||
timeline: state => state.TimelineSpace.Local.timeline
|
timeline: state => state.TimelineSpace.Local.timeline
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
created () {
|
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 () {
|
beforeDestroy () {
|
||||||
this.$store.dispatch('TimelineSpace/Local/stopLocalStreaming')
|
this.$store.dispatch('TimelineSpace/Local/stopLocalStreaming')
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
async initialize () {
|
||||||
|
try {
|
||||||
|
await this.$store.dispatch('TimelineSpace/Local/fetchLocalTimeline')
|
||||||
|
} catch (err) {
|
||||||
|
this.$message({
|
||||||
|
message: 'Could not fetch timeline',
|
||||||
|
type: 'error'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.$store.dispatch('TimelineSpace/Local/startLocalStreaming')
|
||||||
|
},
|
||||||
updateToot (message) {
|
updateToot (message) {
|
||||||
this.$store.commit('TimelineSpace/Local/updateToot', message)
|
this.$store.commit('TimelineSpace/Local/updateToot', message)
|
||||||
}
|
}
|
||||||
|
@ -15,17 +15,39 @@ export default {
|
|||||||
components: { Toot },
|
components: { Toot },
|
||||||
computed: {
|
computed: {
|
||||||
...mapState({
|
...mapState({
|
||||||
account: state => state.TimelineSpace.account,
|
|
||||||
timeline: state => state.TimelineSpace.Public.timeline
|
timeline: state => state.TimelineSpace.Public.timeline
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
created () {
|
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 () {
|
beforeDestroy () {
|
||||||
this.$store.dispatch('TimelineSpace/Public/stopPublicStreaming')
|
this.$store.dispatch('TimelineSpace/Public/stopPublicStreaming')
|
||||||
},
|
},
|
||||||
methods: {
|
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) {
|
updateToot (message) {
|
||||||
this.$store.commit('TimelineSpace/Public/updateToot', message)
|
this.$store.commit('TimelineSpace/Public/updateToot', message)
|
||||||
}
|
}
|
||||||
|
@ -42,11 +42,11 @@ const TimelineSpace = {
|
|||||||
appendNotifications (state, notifications) {
|
appendNotifications (state, notifications) {
|
||||||
state.notifications = [notifications].concat(state.notifications)
|
state.notifications = [notifications].concat(state.notifications)
|
||||||
},
|
},
|
||||||
insertHomeTimeline (state, messages) {
|
updateHomeTimeline (state, messages) {
|
||||||
state.homeTimeline = state.homeTimeline.concat(messages)
|
state.homeTimeline = messages
|
||||||
},
|
},
|
||||||
insertNotifications (state, notifications) {
|
updateNotifications (state, notifications) {
|
||||||
state.notifications = state.notifications.concat(notifications)
|
state.notifications = notifications
|
||||||
},
|
},
|
||||||
updateToot (state, message) {
|
updateToot (state, message) {
|
||||||
// Replace target message in homeTimeline and notifications
|
// Replace target message in homeTimeline and notifications
|
||||||
@ -163,7 +163,7 @@ const TimelineSpace = {
|
|||||||
)
|
)
|
||||||
client.get('/timelines/home', { limit: 40 }, (err, data, res) => {
|
client.get('/timelines/home', { limit: 40 }, (err, data, res) => {
|
||||||
if (err) return reject(err)
|
if (err) return reject(err)
|
||||||
commit('insertHomeTimeline', data)
|
commit('updateHomeTimeline', data)
|
||||||
resolve(res)
|
resolve(res)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -178,7 +178,7 @@ const TimelineSpace = {
|
|||||||
)
|
)
|
||||||
client.get('/notifications', { limit: 30 }, (err, data, res) => {
|
client.get('/notifications', { limit: 30 }, (err, data, res) => {
|
||||||
if (err) return reject(err)
|
if (err) return reject(err)
|
||||||
commit('insertNotifications', data)
|
commit('updateNotifications', data)
|
||||||
resolve(res)
|
resolve(res)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -6,7 +6,7 @@ const Favourites = {
|
|||||||
favourites: []
|
favourites: []
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
insertFavourites (state, favourites) {
|
updateFavourites (state, favourites) {
|
||||||
state.favourites = favourites
|
state.favourites = favourites
|
||||||
},
|
},
|
||||||
updateToot (state, message) {
|
updateToot (state, message) {
|
||||||
@ -37,7 +37,7 @@ const Favourites = {
|
|||||||
)
|
)
|
||||||
client.get('/favourites', { limit: 40 }, (err, data, res) => {
|
client.get('/favourites', { limit: 40 }, (err, data, res) => {
|
||||||
if (err) return reject(err)
|
if (err) return reject(err)
|
||||||
commit('insertFavourites', data)
|
commit('updateFavourites', data)
|
||||||
resolve(res)
|
resolve(res)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { ipcRenderer } from 'electron'
|
import { ipcRenderer } from 'electron'
|
||||||
|
import Mastodon from 'mastodon-api'
|
||||||
|
|
||||||
const Local = {
|
const Local = {
|
||||||
namespaced: true,
|
namespaced: true,
|
||||||
@ -9,6 +10,9 @@ const Local = {
|
|||||||
appendTimeline (state, update) {
|
appendTimeline (state, update) {
|
||||||
state.timeline = [update].concat(state.timeline)
|
state.timeline = [update].concat(state.timeline)
|
||||||
},
|
},
|
||||||
|
updateTimeline (state, messages) {
|
||||||
|
state.timeline = messages
|
||||||
|
},
|
||||||
updateToot (state, message) {
|
updateToot (state, message) {
|
||||||
state.timeline = state.timeline.map((toot) => {
|
state.timeline = state.timeline.map((toot) => {
|
||||||
if (toot.id === message.id) {
|
if (toot.id === message.id) {
|
||||||
@ -27,12 +31,27 @@ const Local = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
startLocalStreaming ({ commit }, account) {
|
fetchLocalTimeline ({ 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, local: true }, (err, data, res) => {
|
||||||
|
if (err) return reject(err)
|
||||||
|
commit('updateTimeline', data)
|
||||||
|
resolve(res)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
startLocalStreaming ({ state, commit, rootState }) {
|
||||||
ipcRenderer.on('update-start-local-streaming', (event, update) => {
|
ipcRenderer.on('update-start-local-streaming', (event, update) => {
|
||||||
commit('appendTimeline', update)
|
commit('appendTimeline', update)
|
||||||
})
|
})
|
||||||
return new Promise((resolve, reject) => {
|
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) => {
|
ipcRenderer.once('error-start-local-streaming', (event, err) => {
|
||||||
reject(err)
|
reject(err)
|
||||||
})
|
})
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { ipcRenderer } from 'electron'
|
import { ipcRenderer } from 'electron'
|
||||||
|
import Mastodon from 'mastodon-api'
|
||||||
|
|
||||||
const Public = {
|
const Public = {
|
||||||
namespaced: true,
|
namespaced: true,
|
||||||
@ -9,6 +10,9 @@ const Public = {
|
|||||||
appendTimeline (state, update) {
|
appendTimeline (state, update) {
|
||||||
state.timeline = [update].concat(state.timeline)
|
state.timeline = [update].concat(state.timeline)
|
||||||
},
|
},
|
||||||
|
updateTimeline (state, messages) {
|
||||||
|
state.timeline = messages
|
||||||
|
},
|
||||||
updateToot (state, message) {
|
updateToot (state, message) {
|
||||||
state.timeline = state.timeline.map((toot) => {
|
state.timeline = state.timeline.map((toot) => {
|
||||||
if (toot.id === message.id) {
|
if (toot.id === message.id) {
|
||||||
@ -27,12 +31,27 @@ const Public = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
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) => {
|
ipcRenderer.on('update-start-public-streaming', (event, update) => {
|
||||||
commit('appendTimeline', update)
|
commit('appendTimeline', update)
|
||||||
})
|
})
|
||||||
return new Promise((resolve, reject) => {
|
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) => {
|
ipcRenderer.once('error-start-public-streaming', (event, err) => {
|
||||||
reject(err)
|
reject(err)
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user