[英]Create activity in two feed groups in Stream Rails
我正在使用Stream Rails構建帶有提要的應用程序。 user
有一些其他用戶可以關注的page
。 為此,我創建了一個page
提要組。 這是我的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
但是,將 go 發布到用戶的供稿中。 我怎樣才能將它設為 go 到page
提要組? 我查看了 github 代碼,我想我必須覆蓋activity_owner_feed
? 但我也希望作者擁有他們創建的所有帖子的列表。 所以帖子也需要在user
提要中。
這是我的 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
對應路線——
post 'post/create'
post 'post/show'
您需要覆蓋activity_notify
並返回要通知的提要數組。 它在生成的活動中轉換to
目標。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.