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
No related branches found
No related tags found
No related merge requests found
Pipeline #13604 passed
......@@ -35,12 +35,21 @@ class ThreadsUpdate extends JsonApiController
throw new AuthorizationFailedException();
}
$visitedAt = self::arrayGet($json, 'data.attributes.visited-at');
if ($visitedAt) {
if (self::arrayHas($json, 'data.attributes.visited-at')) {
$visitedAt = self::arrayGet($json, 'data.attributes.visited-at');
$visitedDate = self::fromISO8601($visitedAt)->getTimestamp();
$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);
}
......@@ -52,5 +61,12 @@ class ThreadsUpdate extends JsonApiController
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 = {
}
elements.addClass('loading');
const promise = follow
? STUDIP.api.POST(`blubber/threads/${thread_id}/follow`)
: STUDIP.api.DELETE(`blubber/threads/${thread_id}/follow`);
return promise
.then(() => {
elements.toggleClass('unfollowed', !follow);
return follow;
})
.always(() => {
elements.removeClass('loading');
})
.promise();
return STUDIP.Vue.load().then(async ({ store }) => {
return store.dispatch('studip/blubber/changeThreadSubscription', {
id: thread_id,
subscribe: follow,
});
}).then(() => {
elements.toggleClass('unfollowed', !follow);
}).finally(() => {
elements.removeClass('loading');
});
},
Composer: {
vue: null,
......
......@@ -119,12 +119,9 @@ export default {
},
actions: {
changeThreadSubscription({ dispatch, rootGetters }, { id, subscribe }) {
return STUDIP.Blubber.followunfollow(id, subscribe).done((state) => {
const thread = rootGetters['blubber-threads/byId']({ id });
thread.attributes['is-followed'] = state;
return dispatch('blubber-threads/storeRecord', thread, { root: true });
});
const thread = rootGetters['blubber-threads/byId']({ id });
thread.attributes['is-followed'] = subscribe;
return dispatch('blubber-threads/update', thread, { root: true });
},
createComment({ dispatch, rootGetters }, { id, content }) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment