Merge pull request #621 from StCyr/StCyr_fix617

[WIP] Add a like button
pull/624/head
Maxence Lange 2019-07-11 13:24:32 -01:00 zatwierdzone przez GitHub
commit b3e1c5a50c
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
4 zmienionych plików z 65 dodań i 5 usunięć

Wyświetl plik

@ -261,7 +261,7 @@ class LocalController extends Controller {
/**
* Create a new boost.
* Like a post.
*
* @NoAdminRequired
*
@ -287,7 +287,7 @@ class LocalController extends Controller {
/**
* Delete a boost.
* unlike a post.
*
* @NoAdminRequired
*

Wyświetl plik

@ -129,9 +129,9 @@ class LikeService {
throw new StreamNotFoundException('Stream is not a Note');
}
if (!$note->isPublic()) {
throw new StreamNotFoundException('Stream is not Public');
}
// if (!$note->isPublic()) {
// throw new StreamNotFoundException('Stream is not Public');
// }
$like->setObjectId($note->getId());
$this->assignInstance($like, $actor, $note);

Wyświetl plik

@ -29,6 +29,7 @@
<a v-if="item.actor_info.account !== cloudId" v-tooltip.bottom="t('social', 'Boost')"
:class="(isBoosted) ? 'icon-boosted' : 'icon-boost'"
@click.prevent="boost" />
<a v-tooltip.bottom="t('social', 'Like')" :class="(isLiked) ? 'icon-starred' : 'icon-favorite'" @click.prevent="like" />
<div v-if="popoverMenu.length > 0" v-tooltip.bottom="menuOpened ? '' : t('social', 'More actions')" class="post-actions-more">
<a class="icon-more" @click.prevent="togglePopoverMenu" />
<div :class="{open: menuOpened}" class="popovermenu menu-center">
@ -122,6 +123,12 @@ export default {
return false
}
return !!this.item.action.values.boosted
},
isLiked() {
if (typeof this.item.action === 'undefined') {
return false
}
return !!this.item.action.values.liked
}
},
methods: {
@ -141,6 +148,17 @@ export default {
} else {
this.$store.dispatch('postBoost', params)
}
},
like() {
let params = {
post: this.item,
parentAnnounce: this.parentAnnounce
}
if (this.isLiked) {
this.$store.dispatch('postUnlike', params)
} else {
this.$store.dispatch('postLike', params)
}
}
}
}
@ -184,6 +202,8 @@ export default {
.icon-reply,
.icon-boost,
.icon-boosted,
.icon-starred,
.icon-favorite,
.icon-more {
display: inline-block;
width: 44px;

Wyświetl plik

@ -54,6 +54,22 @@ const mutations = {
setAccount(state, account) {
state.account = account
},
likePost(state, { post, parentAnnounce }) {
if (typeof state.timeline[post.id] !== 'undefined') {
Vue.set(state.timeline[post.id].action.values, 'liked', true)
}
if (typeof parentAnnounce.id !== 'undefined') {
Vue.set(state.timeline[parentAnnounce.id].cache[parentAnnounce.object].object.action.values, 'liked', true)
}
},
unlikePost(state, { post, parentAnnounce }) {
if (typeof state.timeline[post.id] !== 'undefined') {
Vue.set(state.timeline[post.id].action.values, 'liked', false)
}
if (typeof parentAnnounce.id !== 'undefined') {
Vue.set(state.timeline[parentAnnounce.id].cache[parentAnnounce.object].object.action.values, 'liked', false)
}
},
boostPost(state, { post, parentAnnounce }) {
if (typeof state.timeline[post.id] !== 'undefined') {
Vue.set(state.timeline[post.id].action.values, 'boosted', true)
@ -113,6 +129,30 @@ const actions = {
console.error('Failed to delete the post', error)
})
},
postLike(context, { post, parentAnnounce }) {
return new Promise((resolve, reject) => {
axios.post(OC.generateUrl(`apps/social/api/v1/post/like?postId=${post.id}`)).then((response) => {
context.commit('likePost', { post, parentAnnounce })
// eslint-disable-next-line no-console
console.log('Post liked with token ' + response.data.result.token)
resolve(response)
}).catch((error) => {
OC.Notification.showTemporary('Failed to like post')
console.error('Failed to like post', error.response)
reject(error)
})
})
},
postUnlike(context, { post, parentAnnounce }) {
return axios.delete(OC.generateUrl(`apps/social/api/v1/post/like?postId=${post.id}`)).then((response) => {
context.commit('unlikePost', { post, parentAnnounce })
// eslint-disable-next-line no-console
console.log('Post unliked with token ' + response.data.result.token)
}).catch((error) => {
OC.Notification.showTemporary('Failed to unlike post')
console.error('Failed to unlike post', error)
})
},
postBoost(context, { post, parentAnnounce }) {
return new Promise((resolve, reject) => {
axios.post(OC.generateUrl(`apps/social/api/v1/post/boost?postId=${post.id}`)).then((response) => {