refs #53 Reblog on toot

This commit is contained in:
AkiraFukushima 2018-03-14 22:38:42 +09:00
parent 3d248ec1ad
commit 7d143104c8
2 changed files with 64 additions and 3 deletions

View File

@ -14,9 +14,15 @@
</div>
<div class="content" v-html="message.content" @click.capture.prevent="tootClick"></div>
<div class="tool-box">
<el-button type="text" @click="openReply(message)"><icon name="reply" scale="0.9"></icon></el-button>
<el-button type="text"><icon name="retweet" scale="0.9"></icon></el-button>
<el-button type="text" @click="changeFavourite(message)" :class="message.favourited ? 'favourited' : ''"><icon name="star" scale="0.9"></icon></el-button>
<el-button type="text" @click="openReply(message)">
<icon name="reply" scale="0.9"></icon>
</el-button>
<el-button type="text" @click="changeReblog(message)">
<icon name="retweet" scale="0.9"></icon>
</el-button>
<el-button type="text" @click="changeFavourite(message)" :class="message.favourited ? 'favourited' : ''">
<icon name="star" scale="0.9"></icon>
</el-button>
</div>
</div>
<div class="clearfix"></div>
@ -44,6 +50,31 @@ export default {
openReply (message) {
this.$store.dispatch('TimelineSpace/NewTootModal/openReply', message)
},
changeReblog (message) {
if (message.reblogged) {
this.$store.dispatch('TimelineSpace/Cards/Toot/unreblog', message)
.then((data) => {
this.$emit('update', data)
})
.catch(() => {
this.$message({
message: 'Faild to unreblog',
type: 'error'
})
})
} else {
this.$store.dispatch('TimelineSpace/Cards/Toot/reblog', message)
.then((data) => {
this.$emit('update', data)
})
.catch(() => {
this.$message({
message: 'Faild to reblog',
type: 'error'
})
})
}
},
changeFavourite (message) {
if (message.favourited) {
this.$store.dispatch('TimelineSpace/Cards/Toot/removeFavourite', message)

View File

@ -5,6 +5,36 @@ const Toot = {
state: {},
mutations: {},
actions: {
reblog ({ state, commit, rootState }, message) {
return new Promise((resolve, reject) => {
const client = new Mastodon(
{
access_token: rootState.TimelineSpace.account.accessToken,
api_url: rootState.TimelineSpace.account.baseURL + '/api/v1'
}
)
client.post(`/statuses/${message.id}/reblog`, {}, (err, data, res) => {
if (err) return reject(err)
commit('TimelineSpace/updateToot', data, { root: true })
resolve(data)
})
})
},
unreblog ({ state, commit, rootState }, message) {
return new Promise((resolve, reject) => {
const client = new Mastodon(
{
access_token: rootState.TimelineSpace.account.accessToken,
api_url: rootState.TimelineSpace.account.baseURL + '/api/v1'
}
)
client.post(`/statuses/${message.id}/unreblog`, {}, (err, data, res) => {
if (err) return reject(err)
commit('TimelineSpace/updateToot', data, { root: true })
resolve(data)
})
})
},
addFavourite ({ state, commit, rootState }, message) {
return new Promise((resolve, reject) => {
const client = new Mastodon(