在Stream-Rails中从更新到已创建的对象创建活动?

时间:2017-06-09 22:22:44

标签: ruby-on-rails getstream-io

我正在使用Stream的高级stream-rails ROR客户端在我的网络应用上创建通知部分,专门用于朋友请求。

据我所知,当创建类似于FriendRequest模型的AR模型实例时,它会作为活动存储在Feed中。但是,我还希望在修改FriendRequest实例时将活动添加到Feed中(例如更新属性)。有没有办法做到这一点?

1 个答案:

答案 0 :(得分:0)

Your approach could differ based on what you're updating in the activity. Normally you'd send us a foreign_id and object_id that points at the object in your database. You can certainly send metadata in the activity itself of course. If it's something changing that isn't already in the activity payload then the enrichment should take care of it by pulling your update out of the database later when you fetch the feed.

If it IS metadata within the activity: save the same activity data (with whatever updated metadata you want to track) with the same foreign_id and timestamp (you could also track an updated date in a metadata field if that's important). Our addActivity API call acts as an upsert as long as the foreign_id and timestamp are the same as before and will overwrite your previous activity with any new data.