refs #872 Update reblogged toot in all timelines

This commit is contained in:
AkiraFukushima 2019-05-18 23:06:44 +09:00
parent a97c5feae6
commit 25c437c66b
4 changed files with 23 additions and 25 deletions

View File

@ -449,7 +449,7 @@ export default {
.then(data => {
this.$emit('update', data)
})
.catche(err => {
.catch(err => {
console.error(err)
this.$message({
message: this.$t('message.unfavourite_error'),

View File

@ -442,7 +442,7 @@ const actions: ActionTree<TimelineSpaceState, RootState> = {
stopDirectMessagesStreaming: () => {
ipcRenderer.send('stop-directmessages-streaming')
},
addFavouriteToot: ({ commit, state }, status: Status): boolean => {
updateTootForAllTimelines: ({ commit, state }, status: Status): boolean => {
commit('TimelineSpace/Contents/Home/updateToot', status, { root: true })
commit('TimelineSpace/Contents/Notifications/updateToot', status, { root: true })
commit('TimelineSpace/Contents/Mentions/updateToot', status, { root: true })

View File

@ -3,10 +3,10 @@ import { Module, MutationTree, ActionTree } from 'vuex'
import { RootState } from '@/store'
export interface PublicState {
timeline: Array<Status>,
unreadTimeline: Array<Status>,
lazyLoading: boolean,
heading: boolean,
timeline: Array<Status>
unreadTimeline: Array<Status>
lazyLoading: boolean
heading: boolean
filter: string
}
@ -46,25 +46,25 @@ const mutations: MutationTree<PublicState> = {
[MUTATION_TYPES.UPDATE_TIMELINE]: (state, messages: Array<Status>) => {
state.timeline = messages
},
[MUTATION_TYPES.MERGE_TIMELINE]: (state) => {
[MUTATION_TYPES.MERGE_TIMELINE]: state => {
state.timeline = state.unreadTimeline.slice(0, 80).concat(state.timeline)
state.unreadTimeline = []
},
[MUTATION_TYPES.INSERT_TIMELINE]: (state, messages: Array<Status>) => {
state.timeline = state.timeline.concat(messages)
},
[MUTATION_TYPES.ARCHIVE_TIMELINE]: (state) => {
[MUTATION_TYPES.ARCHIVE_TIMELINE]: state => {
state.timeline = state.timeline.slice(0, 40)
},
[MUTATION_TYPES.CLEAR_TIMELINE]: (state) => {
[MUTATION_TYPES.CLEAR_TIMELINE]: state => {
state.timeline = []
state.unreadTimeline = []
},
[MUTATION_TYPES.UPDATE_TOOT]: (state, message: Status) => {
state.timeline = state.timeline.map((toot) => {
state.timeline = state.timeline.map(toot => {
if (toot.id === message.id) {
return message
} else if (toot.reblog !== null && toot.reblog.id === message.id) {
} else if (toot.reblog && toot.reblog.id === message.id) {
// When user reblog/favourite a reblogged toot, target message is a original toot.
// So, a message which is received now is original toot.
const reblog = {
@ -77,7 +77,7 @@ const mutations: MutationTree<PublicState> = {
})
},
[MUTATION_TYPES.DELETE_TOOT]: (state, message: Status) => {
state.timeline = state.timeline.filter((toot) => {
state.timeline = state.timeline.filter(toot => {
if (toot.reblog !== null && toot.reblog.id === message.id) {
return false
} else {
@ -95,10 +95,7 @@ const mutations: MutationTree<PublicState> = {
const actions: ActionTree<PublicState, RootState> = {
fetchPublicTimeline: async ({ commit, rootState }) => {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken!,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
const res: Response<Array<Status>> = await client.get<Array<Status>>('/timelines/public', { limit: 40 })
commit(MUTATION_TYPES.UPDATE_TIMELINE, res.data)
},
@ -107,11 +104,9 @@ const actions: ActionTree<PublicState, RootState> = {
return Promise.resolve(null)
}
commit(MUTATION_TYPES.CHANGE_LAZY_LOADING, true)
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken!,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.get<Array<Status>>('/timelines/public', { max_id: lastStatus.id, limit: 40 })
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
return client
.get<Array<Status>>('/timelines/public', { max_id: lastStatus.id, limit: 40 })
.then(res => {
commit(MUTATION_TYPES.INSERT_TIMELINE, res.data)
return res.data

View File

@ -8,30 +8,33 @@ export interface TootState {}
const state = (): TootState => ({})
const actions: ActionTree<TootState, RootState> = {
reblog: async ({ rootState }, message: Status) => {
reblog: async ({ rootState, dispatch }, message: Status) => {
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
const res: Response<Status> = await client.post<Status>(`/statuses/${message.id}/reblog`)
// 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')
dispatch('TimelineSpace/updateTootForAllTimelines', res.data, { root: true })
return res.data.reblog
},
unreblog: async ({ rootState }, message: Status) => {
unreblog: async ({ rootState, dispatch }, message: Status) => {
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
const res: Response<Status> = await client.post<Status>(`/statuses/${message.id}/unreblog`)
dispatch('TimelineSpace/updateTootForAllTimelines', res.data, { root: true })
return res.data
},
addFavourite: async ({ rootState, dispatch }, message: Status) => {
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
const res: Response<Status> = await client.post<Status>(`/statuses/${message.id}/favourite`)
ipcRenderer.send('fav-rt-action-sound')
dispatch('TimelineSpace/addFavouriteToot', res.data, { root: true })
dispatch('TimelineSpace/updateTootForAllTimelines', res.data, { root: true })
return res.data
},
removeFavourite: async ({ rootState }, message: Status) => {
removeFavourite: async ({ rootState, dispatch }, message: Status) => {
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
const res: Response<Status> = await client.post<Status>(`/statuses/${message.id}/unfavourite`)
dispatch('TimelineSpace/updateTootForAllTimelines', res.data, { root: true })
return res.data
},
deleteToot: async ({ rootState }, message: Status) => {