class StreamRails::FeedManager
Class used to manage feeds
Attributes
client[R]
Public Class Methods
new(client, opts = {})
click to toggle source
# File lib/stream_rails/feed_manager.rb, line 6 def initialize(client, opts = {}) @client = client @user_feed = opts[:user_feed] @news_feeds = opts[:news_feeds] @notification_feed = opts[:notification_feed] end
Public Instance Methods
created_activity(instance)
click to toggle source
# File lib/stream_rails/feed_manager.rb, line 53 def created_activity(instance) return unless StreamRails.enabled? && instance.activity_should_sync? activity = instance.create_activity feed = get_owner_feed(instance) feed.add_activity(activity) end
destroyed_activity(instance)
click to toggle source
# File lib/stream_rails/feed_manager.rb, line 61 def destroyed_activity(instance) return unless StreamRails.enabled? feed = get_owner_feed(instance) feed.remove(instance.activity_foreign_id, foreign_id: true) end
follow_user(user_id, target_id)
click to toggle source
# File lib/stream_rails/feed_manager.rb, line 29 def follow_user(user_id, target_id) return unless StreamRails.enabled? target_feed = get_user_feed(target_id) @news_feeds.each do |_, feed| news_feed = get_feed(feed, user_id) news_feed.follow(target_feed.slug, target_feed.user_id) end end
get_feed(feed_type, user_id)
click to toggle source
# File lib/stream_rails/feed_manager.rb, line 25 def get_feed(feed_type, user_id) @client.feed(feed_type, user_id) end
get_news_feeds(user_id)
click to toggle source
# File lib/stream_rails/feed_manager.rb, line 17 def get_news_feeds(user_id) @news_feeds.transform_values { |feed_slug| get_feed(feed_slug, user_id) } end
get_notification_feed(user_id)
click to toggle source
# File lib/stream_rails/feed_manager.rb, line 21 def get_notification_feed(user_id) @client.feed(@notification_feed, user_id) end
get_owner_feed(instance)
click to toggle source
# File lib/stream_rails/feed_manager.rb, line 49 def get_owner_feed(instance) get_feed(instance.activity_owner_feed, instance.activity_owner_id) end
get_user_feed(user_id)
click to toggle source
# File lib/stream_rails/feed_manager.rb, line 13 def get_user_feed(user_id) @client.feed(@user_feed, user_id) end
unfollow_user(user_id, target_id)
click to toggle source
# File lib/stream_rails/feed_manager.rb, line 39 def unfollow_user(user_id, target_id) return unless StreamRails.enabled? target_feed = get_user_feed(target_id) @news_feeds.each do |_, feed| news_feed = get_feed(feed, user_id) news_feed.unfollow(target_feed.slug, target_feed.user_id) end end