How to build a news feed with aggregate and flat types?

后端 未结 1 544
面向向阳花
面向向阳花 2020-12-20 23:44

A simple feature on Facebook is to show posts from your friends, but also posts that your friends shared. In the case of shared posts, it\'s titled as \"Kelly and 4 others\

相关标签:
1条回答
  • 2020-12-21 00:22

    You can achieve this by using a single aggregated feed and tweak the aggregation rule. In your case it seems like what you need is:

    • Group shares for the same posts together
    • Keep posts on single activities
    • Group likes for the same posts together

    An aggregation rule like the following should work (not tested):

    {% if verb.infinitive == 'like' %}
        "likes"-{{ object }}
    {% elif verb.infinitive == 'share' %}
        "share"-{{ object }}
    {% elif verb.infinitive == 'post' %}
        "post"-{{ object }}
    {% else %}
        {{ actor }}-{{ verb.infinitive }}-{{ time.strftime('%H') }}
    {% endif %}
    

    A quick explanation of how this work is due. Aggregation rules are used to determine how activities are grouped together. You can see them as functions that are executed with an activity as parameter. In practice aggregation rules are similar to Jinja2 templates that outputs a string.

    If the output for two activities is the same, then they will belong to the same aggregation activity.

    For example: the activities Tom likes post "xyz" and James likes post "xyz" will both output likes-xyz and therefore are going to be grouped together. On the other hand, the activity Sam posts "xyz" will output post-xyz and assuming there is only one post called xyz, it will never get grouped with other activities.

    My suggestion is to send some sample data to a feed and tweak your aggregation rule using the preview functionality available in Stream's dashboard.

    0 讨论(0)
提交回复
热议问题