添加 activity 将用户对象添加为字符串而不是实际对象
Adding an activity adds a user object as a string instead of the actual object
我目前正在将 stream_rails
通知源集成到现有应用程序中。当一个用户关注另一个用户时,我试图添加一个 activity。非常简单,但出于某种原因,当我在 followed_user
的提要上调用 add_activity
时,它会将信息添加为字符串。
这是我的 activity_data
:
activity_data = {
actor: current_user,
verb: 'Follow',
object: followable,
to: ["notifications:#{followable.id}"]
}
这里是 activity_response
,为简洁起见缩短了:
activity_response = {"actor"=>
"{u'twitter_followers_count': 0, u'github_created_at': blahblahblah}", # other attributes removed for brevity
"duration"=>"41ms",
"foreign_id"=>nil,
"id"=>"538bc690-51df-11e7-8080-8001521ad36e",
"object"=>
"{u'twitter_followers_count': None, u'github_created_at': blahblahblah}", # other attributes removed for brevity
"origin"=>nil,
"target"=>nil,
"time"=>"2017-06-15T15:28:47.931560",
"to"=>[["notifications:301", "DVcbej_Id4IdQWHOYlA1n7RB4ps"]],
"verb"=>"Follow"}
什么时候应该更像:
activity_response = {"actor"=>
#<User:0x007fa8fae1a488>,
"duration"=>"41ms",
# etc etc
}
不太清楚为什么 actor
指向实际 ActiveRecord 对象的 return 值的字符串,object
也是如此。每个属性前还添加了一堆 'u'
。
此外,我避免使用 StreamRails.feed_manager.follow_user
,因为我只想发送通知,而不是创建提要供关注者查看。感谢任何帮助。谢谢!
没关系,想出一个解决办法;虽然我确实有更多问题...
不管怎样,回到答案。我假设 stream-ruby
gem 的 add_activity
gem 字符串内插 data
的 actor
和 object
的值。
通过在我的关注模型中添加 activity_notify
和 activity_object
方法,使用 stream-rails
发送通知允许它正确地向被关注的人发送通知。
示例:
- 安迪想跟随约翰。
- 安迪点击关注按钮。
- 跟随模型(这是一个连接 table)在 Andy 和 John 之间创建了一个新的关系。
- Follow 模型,它有
stream-rails
方法 activity_notify
和 activity_object
向 John 的通知源发送通知。
- 约翰收到通知,说安迪关注了约翰。
关注模特:
include StreamRails::Activity
as_activity
def activity_notify
[StreamRails.feed_manager.get_notification_feed(self.followable.id)]
end
def activity_object
self.followable
end
我目前正在将 stream_rails
通知源集成到现有应用程序中。当一个用户关注另一个用户时,我试图添加一个 activity。非常简单,但出于某种原因,当我在 followed_user
的提要上调用 add_activity
时,它会将信息添加为字符串。
这是我的 activity_data
:
activity_data = {
actor: current_user,
verb: 'Follow',
object: followable,
to: ["notifications:#{followable.id}"]
}
这里是 activity_response
,为简洁起见缩短了:
activity_response = {"actor"=>
"{u'twitter_followers_count': 0, u'github_created_at': blahblahblah}", # other attributes removed for brevity
"duration"=>"41ms",
"foreign_id"=>nil,
"id"=>"538bc690-51df-11e7-8080-8001521ad36e",
"object"=>
"{u'twitter_followers_count': None, u'github_created_at': blahblahblah}", # other attributes removed for brevity
"origin"=>nil,
"target"=>nil,
"time"=>"2017-06-15T15:28:47.931560",
"to"=>[["notifications:301", "DVcbej_Id4IdQWHOYlA1n7RB4ps"]],
"verb"=>"Follow"}
什么时候应该更像:
activity_response = {"actor"=>
#<User:0x007fa8fae1a488>,
"duration"=>"41ms",
# etc etc
}
不太清楚为什么 actor
指向实际 ActiveRecord 对象的 return 值的字符串,object
也是如此。每个属性前还添加了一堆 'u'
。
此外,我避免使用 StreamRails.feed_manager.follow_user
,因为我只想发送通知,而不是创建提要供关注者查看。感谢任何帮助。谢谢!
没关系,想出一个解决办法;虽然我确实有更多问题...
不管怎样,回到答案。我假设 stream-ruby
gem 的 add_activity
gem 字符串内插 data
的 actor
和 object
的值。
通过在我的关注模型中添加 activity_notify
和 activity_object
方法,使用 stream-rails
发送通知允许它正确地向被关注的人发送通知。
示例:
- 安迪想跟随约翰。
- 安迪点击关注按钮。
- 跟随模型(这是一个连接 table)在 Andy 和 John 之间创建了一个新的关系。
- Follow 模型,它有
stream-rails
方法activity_notify
和activity_object
向 John 的通知源发送通知。 - 约翰收到通知,说安迪关注了约翰。
关注模特:
include StreamRails::Activity
as_activity
def activity_notify
[StreamRails.feed_manager.get_notification_feed(self.followable.id)]
end
def activity_object
self.followable
end