club-1 / flarum-ext-cross-references

Add cross reference links when a discussion is mentioned from another one.
GNU Affero General Public License v3.0
6 stars 1 forks source link

Add back `sources` relation in the discussion's API serializer, while still respecting the permissions #13

Open n-peugnet opened 1 year ago

n-peugnet commented 1 year ago

This will should lower the network and client usage.

If I understand correctly, something similar is done in flarum/mentions in this file: https://github.com/flarum/mentions/blob/v1.6.3/src/FilterVisiblePosts.php

Which is of course wired in extend.php:

    (new Extend\ApiController(Controller\AbstractSerializeController::class))
        ->prepareDataForSerialization(FilterVisiblePosts::class),
n-peugnet commented 1 year ago

It definitely works correctly for mentions, so this may be a good example how to implement this in this extension, since the functionality is quite similar. However, I think there is one problem with current schema of discussion_reference - currently it tracks discussion-to-discussion relations. But for including data in payload it makes sense to store information also about post with link to discussion and generated EventPost. In this way you can include info about linked discussions using PostSerializer, so payload will contain info only about discussion needed to handle current page. I you useDiscussionSerializer, payload will contain all linked discussion, even if none of them is visible on current page - it could be a real problem for large discussions with lots of references.

Originally posted by @rob006 in https://github.com/club-1/flarum-ext-cross-references/issues/20#issuecomment-1435740909