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

被刻印的时光 ゝ 提交于 2019-12-18 08:26:42

问题


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" shared XYZ post. In addition, if several of your friends shared the post, Facebook aggregates them and only shows you the post once, it won't show up several times. Facebook seems to show flat feed and aggregate feeds all in the same timeline view.

I'd like a way for a feed to show aggregate and flat feed types in a user's timeline (flat feed). I have the following feeds setup:

timeline feed (flat)

user feed (flat)

Every time user A follows user B, I call getstream to update user A's timeline feed to follow user B's user feed.

What I'd like to do in addition to the above is this as an example timeline to show to users:

Flat Post 1 (from following user A)

Flat Post 2 (from following user B)

Aggregated Post 1 (4 people you're following shared a post X)

Flat Post 3 (from following user A)

Flat Post 4 (from following user C)

Aggregated Post 2 (3 people you're following liked post Y)

It seems like the way to do this right now is that I'd have to fetch the activities in the timeline feed from getstream, then also fetch an aggregate feed and somehow mix the two on our backend?


回答1:


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.



来源:https://stackoverflow.com/questions/38923427/how-to-build-a-news-feed-with-aggregate-and-flat-types

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!