refs #286 Update toot status in AccountProfile's timeline

This commit is contained in:
AkiraFukushima 2018-05-10 00:04:01 +09:00
parent 5e61265fa2
commit 604f1a2723
2 changed files with 33 additions and 1 deletions

View File

@ -1,7 +1,7 @@
<template> <template>
<div id="account_timeline"> <div id="account_timeline">
<template v-for="message in timeline"> <template v-for="message in timeline">
<toot :message="message" v-bind:key="message.id"></toot> <toot :message="message" :key="message.id" v-on:update="updateToot" v-on:delete="deleteToot"></toot>
</template> </template>
</div> </div>
</template> </template>
@ -36,6 +36,12 @@ export default {
type: 'error' type: 'error'
}) })
}) })
},
updateToot (message) {
this.$store.commit('TimelineSpace/Contents/SideBar/AccountProfile/Timeline/updateToot', message)
},
deleteToot (message) {
this.$store.commit('TimelineSpace/Contents/SideBar/AccountProfile/Timeline/deleteToot', message)
} }
} }
} }

View File

@ -8,6 +8,32 @@ const Timeline = {
mutations: { mutations: {
updateTimeline (state, timeline) { updateTimeline (state, timeline) {
state.timeline = timeline state.timeline = timeline
},
updateToot (state, message) {
// Replace target message in homeTimeline and notifications
state.timeline = state.timeline.map((toot) => {
if (toot.id === message.id) {
return message
} else if (toot.reblog !== null && 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 = {
reblog: message
}
return Object.assign(toot, reblog)
} else {
return toot
}
})
},
deleteToot (state, message) {
state.timeline = state.timeline.filter((toot) => {
if (toot.reblog !== null && toot.reblog.id === message.id) {
return false
} else {
return toot.id !== message.id
}
})
} }
}, },
actions: { actions: {