refs #62 Update favourited status in homeTimeline and notifications

This commit is contained in:
AkiraFukushima 2018-03-14 17:55:29 +09:00
parent 6c90e40a06
commit d313f93dfe
2 changed files with 23 additions and 2 deletions

View File

@ -47,6 +47,27 @@ const TimelineSpace = {
},
changeNewTootModal (state, modal) {
state.newTootModal = modal
},
updateToot (state, message) {
// Replace target message in homeTimeline and notifications
state.homeTimeline = state.homeTimeline.map((toot) => {
if (toot.id === message.id) {
return message
} else {
return toot
}
})
state.notifications = state.notifications.map((notification) => {
if (notification.type === 'mention' && notification.status.id === message.id) {
const status = {
status: message
}
return Object.assign(notification, status)
} else {
return notification
}
})
}
},
actions: {

View File

@ -15,7 +15,7 @@ const Toot = {
)
client.post(`/statuses/${message.id}/favourite`, {}, (err, data, res) => {
if (err) return reject(err)
// TODO: update toot data
commit('TimelineSpace/updateToot', data, { root: true })
resolve(res)
})
})
@ -30,7 +30,7 @@ const Toot = {
)
client.post(`/statuses/${message.id}/unfavourite`, {}, (err, data, res) => {
if (err) return reject(err)
// TODO: update toot data
commit('TimelineSpace/updateToot', data, { root: true })
resolve(res)
})
})