I am using Stream Rails to build an app with a feed. The user
has some page
which other users can follow. For that I created a page
feed group. Here is my Post
model -
class Post < ApplicationRecord
belongs_to :page
belongs_to :author, class_name: "User"
has_one :post_item, inverse_of: :post
accepts_nested_attributes_for :post_item
include StreamRails::Activity
as_activity
def activity_object
self.post_item
end
def activity_actor
self.author
end
end
However, the posts go to user's feed. How can I also make it go to the page
feed group? I looked through the github code, and I think I have to override activity_owner_feed
? But I also want the author to have a list of all the posts they have created. So the posts need to be in the user
feed too.
Here is the corresponding code from my controller -
# this method creates the post
# This puts the post in user feed
# I also want to add the post to page feed
def create
@post = current_user.posts.build post_params
@post.save
render json: { success: true }
end
# show all posts of a user
def show
feed = StreamRails.feed_manager.get_user_feed(current_user.id)
enricher = StreamRails::Enrich.new
results = feed.get()['results']
@activities = enricher.enrich_activities(results)
render json: { activity: @activities }
end
Corresponding routes -
post 'post/create'
post 'post/show'
You need to override
activity_notify
and return an array of feeds to be notified. It translates toto
target in the generated activity.