Search code examples
rubygetstream-io

getstram.io update activity does not move it up the feed


Assuming I have a music app (like the example) using GetStream.io feeds, where I have user feeds and band feeds (user being able to follow other users, or bands). I am using the stram-ruby gem.

Now, say I am posting as a user to a band feed, doing something like:

user_feed = @client.feed('user', user_id)
activity_data = {
    :actor => "User:#{user_id}",
    :verb => 'post',
    :object => "Post:#{post.id}",
    :target => "Band:#{band_id}",
    :foreign_id => "Post:#{post.id}",
    :time => post.created_at.as_json,
    :comment => 'comment 1',
    :to => ["band:#{band_id}"]
}
user_feed.add_activity(activity_data)

This works fine, and retrieving the band feed, I can see that post:

@client.feed('band', band_id).get()

Now, I am attempting to update this entry (using the comment field just to see something changes):

activity_data = {
    :actor => "User:#{user_id}",
    :verb => 'post',
    :object => "Post:#{post.id}",
    :target => "Band:#{band_id}",
    :foreign_id => "Post:#{post.id}",
    :time => post.created_at.as_json,
    :comment => 'comment 2',
    :to => ["band:#{band_id}"]
}
@client.update_activity(activity_data)

getting the band feed will show correctly the new comment ('comment 2'), but my problem is this:

  1. I am using the created_at field of my post (to ensure my ability to update it as GetStream docs say this is part of the unique key)
  2. I use the same created_at time on the update
  3. When fetching the band feed, I would expect this activity to be the top one - as the feed should be sorted chronologically. But it remains where it was before based on the created_at time.

What to do?

I can try using the updated_at field of the post, but then, if for any reason the post in my DB changes without me updating the GetStream feed, I will no longer be able to update it in GetStream.

Am I missing anything?


Solution

  • There are 2 ways in which you can achieve this.

    1.) You could use aggregated feeds. They are sorted based on the last update to the aggregated item. (assuming this fits your use case of course)

    2.) You could send a field to Stream called updated_at. Next you enable ranked feeds and simply tell Stream to sort by updated_at instead of the regular chronological sort.

    In general, creating a ranking method gives you full control over the ranking of your feed. (paid plans only though) https://getstream.io/docs/#custom_ranking