Skip to content
Snippets Groups Projects
Commit 73a61471 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms
Browse files

use store and jsonapi to set following state of a blubber thread, fixes #2800

Closes #2800

Merge request studip/studip!1889
parent abf5a85a
Branches
No related tags found
No related merge requests found
Pipeline #13604 passed
...@@ -35,12 +35,21 @@ class ThreadsUpdate extends JsonApiController ...@@ -35,12 +35,21 @@ class ThreadsUpdate extends JsonApiController
throw new AuthorizationFailedException(); throw new AuthorizationFailedException();
} }
$visitedAt = self::arrayGet($json, 'data.attributes.visited-at'); if (self::arrayHas($json, 'data.attributes.visited-at')) {
if ($visitedAt) { $visitedAt = self::arrayGet($json, 'data.attributes.visited-at');
$visitedDate = self::fromISO8601($visitedAt)->getTimestamp(); $visitedDate = self::fromISO8601($visitedAt)->getTimestamp();
$GLOBALS['user']->cfg->store('BLUBBERTHREAD_VISITED_' . $thread->getId(), $visitedDate); $GLOBALS['user']->cfg->store('BLUBBERTHREAD_VISITED_' . $thread->getId(), $visitedDate);
} }
if (self::arrayHas($json, 'data.attributes.is-followed')) {
$isFollowed = self::arrayGet($json, 'data.attributes.is-followed');
if ($isFollowed) {
$thread->addFollowingByUser($user->id);
} else {
$thread->removeFollowingByUser($user->id);
}
}
return $this->getContentResponse($thread); return $this->getContentResponse($thread);
} }
...@@ -52,5 +61,12 @@ class ThreadsUpdate extends JsonApiController ...@@ -52,5 +61,12 @@ class ThreadsUpdate extends JsonApiController
return '`visited-at` is not an ISO 8601 timestamp.'; return '`visited-at` is not an ISO 8601 timestamp.';
} }
} }
if (self::arrayHas($json, 'data.attributes.is-followed')) {
$isFollowed = self::arrayGet($json, 'data.attributes.is-followed');
if (!is_bool($isFollowed)) {
return '`is-followed` is not a boolean value.';
}
}
} }
} }
...@@ -41,19 +41,16 @@ const Blubber = { ...@@ -41,19 +41,16 @@ const Blubber = {
} }
elements.addClass('loading'); elements.addClass('loading');
const promise = follow return STUDIP.Vue.load().then(async ({ store }) => {
? STUDIP.api.POST(`blubber/threads/${thread_id}/follow`) return store.dispatch('studip/blubber/changeThreadSubscription', {
: STUDIP.api.DELETE(`blubber/threads/${thread_id}/follow`); id: thread_id,
subscribe: follow,
return promise });
.then(() => { }).then(() => {
elements.toggleClass('unfollowed', !follow); elements.toggleClass('unfollowed', !follow);
return follow; }).finally(() => {
}) elements.removeClass('loading');
.always(() => { });
elements.removeClass('loading');
})
.promise();
}, },
Composer: { Composer: {
vue: null, vue: null,
......
...@@ -119,12 +119,9 @@ export default { ...@@ -119,12 +119,9 @@ export default {
}, },
actions: { actions: {
changeThreadSubscription({ dispatch, rootGetters }, { id, subscribe }) { changeThreadSubscription({ dispatch, rootGetters }, { id, subscribe }) {
return STUDIP.Blubber.followunfollow(id, subscribe).done((state) => { const thread = rootGetters['blubber-threads/byId']({ id });
const thread = rootGetters['blubber-threads/byId']({ id }); thread.attributes['is-followed'] = subscribe;
thread.attributes['is-followed'] = state; return dispatch('blubber-threads/update', thread, { root: true });
return dispatch('blubber-threads/storeRecord', thread, { root: true });
});
}, },
createComment({ dispatch, rootGetters }, { id, content }) { createComment({ dispatch, rootGetters }, { id, content }) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment