Kirk
Kirk

Reputation: 513

How to avoid duplicates when an activity affects multiple feeds

I am not sure how to best approach a scenario where an activity is applicable to multiple feeds that is followed by another feed. It seems like I might get duplicates.

Take this example where there's a music app with user feed and playlist feed.

User feed - for user related activities Playlist feed - for playlist related activities

Say I am interested in userA and his playlist playlistA, so I create a feed to follow both userA and playlistA. Let's call this myFeed.

Now say userA adds a new song to his playlistA. Because this activity relates to be userA and playlistA, do I add the activity twice, to both userA and playlistA? Would this then show up twice in myFeed?

Upvotes: 1

Views: 239

Answers (2)

Daniel Zheng
Daniel Zheng

Reputation: 312

In this case, you can use to param when adding activity. It basically looks like this:

const feed = await client.feed('user', 'A', token);
activity = {
    'actor': 'User:A',
    ....
    'to': 'Playlist:A',
};
feed.addActivity(activity)

Above code will add one activity but when get activities from User:A feed and Playlist:A will both return the activity you have added.

Upvotes: 1

Tommaso Barbugli
Tommaso Barbugli

Reputation: 12031

There is an easy solution for this; send time and foreign_id values when adding activities.

Uniqueness is enforced on these two fields and solves the problem that you describe (just make sure to send always the same values for the same unique activity)

You can find more information about this on the official docs: https://getstream.io/docs/#uniqueness

Upvotes: 1

Related Questions