summaryrefslogtreecommitdiffstats
path: root/src/store/timeline.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/store/timeline.js')
-rw-r--r--src/store/timeline.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/store/timeline.js b/src/store/timeline.js
index accf5a7b..3146a194 100644
--- a/src/store/timeline.js
+++ b/src/store/timeline.js
@@ -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) => {