diff options
| author | Marcus Eibrink-Lunzenauer <lunzenauer@elan-ev.de> | 2025-01-15 09:18:17 +0000 |
|---|---|---|
| committer | Marcus Eibrink-Lunzenauer <lunzenauer@elan-ev.de> | 2025-01-15 09:18:17 +0000 |
| commit | daa242a4c5f25f47b5f104ba4cbe2eeb2909d6d3 (patch) | |
| tree | addc510cca07b257035088bb07a1162801314441 | |
| parent | 58ca2df83f308e8acf8cddfbae68c3cf6abdd316 (diff) | |
Only load a course's blubber threads in a course context.
Closes #4546
Merge request studip/studip!3836
| -rw-r--r-- | lib/classes/JsonApi/Routes/Blubber/FilterTrait.php | 2 | ||||
| -rw-r--r-- | lib/classes/JsonApi/Routes/Blubber/ThreadsIndex.php | 45 | ||||
| -rw-r--r-- | resources/vue/components/blubber/CommunityPage.vue | 8 | ||||
| -rw-r--r-- | resources/vue/composables/context.js | 9 | ||||
| -rw-r--r-- | resources/vue/store/blubber.js | 6 |
5 files changed, 44 insertions, 26 deletions
diff --git a/lib/classes/JsonApi/Routes/Blubber/FilterTrait.php b/lib/classes/JsonApi/Routes/Blubber/FilterTrait.php index 2d74f9c..c336016 100644 --- a/lib/classes/JsonApi/Routes/Blubber/FilterTrait.php +++ b/lib/classes/JsonApi/Routes/Blubber/FilterTrait.php @@ -30,6 +30,8 @@ trait FilterTrait $filters['since'] = isset($filtering['since']) ? self::fromISO8601($filtering['since'])->getTimestamp() : null; $filters['before'] = isset($filtering['before']) ? self::fromISO8601($filtering['before'])->getTimestamp() : null; $filters['search'] = $filtering['search'] ?? null; + $filters['context-type'] = $filtering['context-type'] ?? null; + $filters['context-id'] = $filtering['context-id'] ?? null; return $filters; } diff --git a/lib/classes/JsonApi/Routes/Blubber/ThreadsIndex.php b/lib/classes/JsonApi/Routes/Blubber/ThreadsIndex.php index 91cfa89..5d4cf33 100644 --- a/lib/classes/JsonApi/Routes/Blubber/ThreadsIndex.php +++ b/lib/classes/JsonApi/Routes/Blubber/ThreadsIndex.php @@ -16,7 +16,7 @@ class ThreadsIndex extends JsonApiController { use TimestampTrait, FilterTrait; - protected $allowedFilteringParameters = ['since', 'before', 'search']; + protected $allowedFilteringParameters = ['since', 'before', 'search', 'context-type', 'context-id']; protected $allowedIncludePaths = ['author', 'comments', 'context', 'mentions']; protected $allowedPagingParameters = ['offset', 'limit']; @@ -25,34 +25,31 @@ class ThreadsIndex extends JsonApiController */ public function __invoke(Request $request, Response $response, $args) { + $this->validateFilters(); + $filters = $this->getFilters(); $contextType = $args['type']; + $contextId = isset($args['id']) ? $args['id'] : null; + + if ($contextType === 'all') { + if (isset($filters['context-type'])) { + $contextType = $filters['context-type']; + } + if (isset($filters['context-id'])) { + $contextId = $filters['context-id']; + } + } + if (!in_array($contextType, ['all', 'public', 'private', 'course', 'institute'])) { throw new BadRequestException('Wrong context type.'); } - switch ($contextType) { - case 'all': - $this->validateFilters(); - $filters = $this->getFilters(); - list($threads, $total) = $this->getAllThreads($filters, $this->getUser($request)); - break; - - case 'public': - list($threads, $total) = $this->getPublicThreads($this->getUser($request)); - break; - - case 'private': - list($threads, $total) = $this->getPrivateThreads($this->getUser($request), $args['id']); - break; - - case 'course': - list($threads, $total) = $this->getCourseThreads($this->getUser($request), $args['id']); - break; - - case 'institute': - list($threads, $total) = $this->getInstituteThreads($this->getUser($request), $args['id']); - break; - } + [$threads, $total] = match ($contextType) { + 'all' => $this->getAllThreads($filters, $this->getUser($request)), + 'public' => $this->getPublicThreads($this->getUser($request)), + 'private' => $this->getPrivateThreads($this->getUser($request), $contextId), + 'course' => $this->getCourseThreads($this->getUser($request), $contextId), + 'institute' => $this->getInstituteThreads($this->getUser($request), $contextId), + }; return $this->getPaginatedContentResponse($threads, $total); } diff --git a/resources/vue/components/blubber/CommunityPage.vue b/resources/vue/components/blubber/CommunityPage.vue index bd937e0..4dee22a 100644 --- a/resources/vue/components/blubber/CommunityPage.vue +++ b/resources/vue/components/blubber/CommunityPage.vue @@ -18,11 +18,17 @@ <script> import { mapActions, mapGetters } from 'vuex'; +import { useContext } from '../../composables/context.js'; import BlubberPanel from './Panel.vue'; import BlubberSearchWidget from './SearchWidget.vue'; import BlubberThreadsWidget from './ThreadsWidget.vue'; export default { + setup() { + const { id, isCourse } = useContext(); + + return { cid: id, isCourse }; + }, props: { initialThreadId: { type: String, @@ -64,7 +70,7 @@ export default { }, }, async beforeMount() { - await this.fetchThreads({ search: this.search }); + await this.fetchThreads({ search: this.search, course: this.isCourse ? this.cid : null }); this.onSelectThread(this.initialThreadId, false); this.handleSelectBlubberThread = (threadId) => { diff --git a/resources/vue/composables/context.js b/resources/vue/composables/context.js new file mode 100644 index 0000000..06a50b8 --- /dev/null +++ b/resources/vue/composables/context.js @@ -0,0 +1,9 @@ +import { computed } from "vue"; + +export function useContext() { + const id = computed(() => (isCourse.value ? window.STUDIP.URLHelper.parameters.cid : null)); + const isCourse = computed(() => "cid" in window.STUDIP.URLHelper.parameters); + const userId = computed(() => window.STUDIP.USER_ID); + + return { id, isCourse, userId }; +} diff --git a/resources/vue/store/blubber.js b/resources/vue/store/blubber.js index 2ae514e..db58333 100644 --- a/resources/vue/store/blubber.js +++ b/resources/vue/store/blubber.js @@ -171,7 +171,7 @@ export default { }); }, - async fetchThreads({ commit, dispatch, getters, rootGetters }, { search, more = false }) { + async fetchThreads({ commit, dispatch, getters, rootGetters }, { search, course = false, more = false }) { if (getters.isLoadingThreads) { return; } @@ -185,6 +185,10 @@ export default { if (search) { filter['search'] = search; } + if (course) { + filter['context-type'] = 'course'; + filter['context-id'] = course; + } if (more) { const earliestDate = rootGetters['blubber-threads/all'].reduce((earliest, thread) => { const activityDate = new Date(thread.attributes['latest-activity']); |
