web-publisher
web-publisher copied to clipboard
Feature request: Follow author
As a reader on a Superdesk Publisher website, I would like to be able to follow my favourite authors on that website.
Possible solutions/implementations
From a templating standpoint we would need the following for it to work.
- Submit a post request to connect an Author with the current
app.user
. - List articles based on the authors that a user follows.
Let's start with the first point. Submit a POST request to a (new) Controller.
Form template
I propose that we, in templates, use forms to POST to a new "follow_author" endpoint. Similar to what we already do for user login. The receiving controller would connect the author from the form with the currently logged in user.
It might look something like this:
{% if app.user %}
<form action="{{ path('follow_author') }}" method="POST">
<input type="hidden" name="_author" value="{{ author.id }}" />
<input type="submit" value="Follow author" />
</form>
{% else %}
<button type="button" disabled>Follow Author</button>
(You must login to follow an author)
{% endif %}
List followed articles
The listing of articles might look different based on what implementation we choose for the backend. I see two primary alternatives.
Alternative A – new loader
The simplest solution of the two alternatives. A new loader that can load the followed articles. Perhaps from a new table swp_user_author
that holds the many-to-many relationship between a user and its subscribed authors.
In twig it could look something like this:
{% if app.user %}
<ul>
{% gimmelist followedArticle from followedArticles with { user: app.user } %}
<li>{{ followedArticle.article.title }}</li>
{% endgimmelist %}
</ul>
{% endif %}
Alternative B – new type of content list
A more flexible and robust solution might be to create a new type of content list. A FollowList
. Similar to the current ContentList
templating-wise. It could possibly also be cached similarly to content lists.
An added benefit to a generic FollowList
is that it isn't bound to only follow authors. In the future, a user could possibly follow keywords, routes or genres.
{% gimme followList with { user: app.user } %}
{% cache 'followed-articles' { gen: followList } %}
<ul>
{% gimmelist item from followListItems with { followList: contentList } %}
<li>{{ item.content.title }}</li> <!-- Article title -->
{% endgimmelist %}
</ul>
{% endcache %}
{% endgimme %}
@kottkrig the second solution sounds good, but not sure if you would have to extend it by adding user to it and if that won't affect existing content lists. If not, I would go for it, otherwise let's stick to alternative 1.