GithubHelp home page GithubHelp logo

getstream / stream-rails Goto Github PK

View Code? Open in Web Editor NEW
256.0 49.0 35.0 149 KB

Rails Client - Build Activity Feeds & Streams with GetStream.io

Home Page: https://getstream.io

License: BSD 3-Clause "New" or "Revised" License

Ruby 98.18% Roff 1.82%
ruby ruby-on-rails stream-rails activity-stream getstream-io notification-feed news-feed timeline feed

stream-rails's Introduction

Stream Rails

build Gem Version

stream-rails is a Ruby on Rails client for Stream.

You can sign up for a Stream account at https://getstream.io/get_started.

Note there is also a lower level Ruby - Stream integration library which is suitable for all Ruby applications.

๐Ÿ’ก This is a library for the Feeds product. The Chat SDKs can be found here.

Activity Streams & Newsfeeds

What you can build:

  • Activity streams such as seen on Github
  • A twitter style newsfeed
  • A feed like instagram/ pinterest
  • Facebook style newsfeeds
  • A notification system

Demo

You can check out our example app built using this library on Github https://github.com/GetStream/Stream-Example-Rails

Table of Contents

Gem installation

You can install stream_rails as you would any other gem:

gem install stream_rails

or in your Gemfile:

gem 'stream_rails'

This library is tested against and fully supports the following Rails versions:

  • 5.0
  • 5.2
  • 6.0
  • 6.1

Setup

Login with Github on getstream.io and get your api_key and api_secret from your app configuration (Dashboard screen).

Then you can add the StreamRails configuration in config/initializers/stream_rails.rb

require 'stream_rails'

StreamRails.configure do |config|
  config.api_key      = "YOUR API KEY"
  config.api_secret   = "YOUR API SECRET"
  config.timeout      = 30                  # Optional, defaults to 3
  config.location     = 'us-east'           # Optional, defaults to 'us-east'
  config.api_hostname = 'stream-io-api.com' # Optional, defaults to 'stream-io-api.com'
  # If you use custom feed names, e.g.: timeline_flat, timeline_aggregated,
  # use this, otherwise omit:
  config.news_feeds = { flat: "timeline_flat", aggregated: "timeline_aggregated" }
  # Point to the notifications feed group providing the name, omit if you don't
  # have a notifications feed
  config.notification_feed = "notification"
end

Supported ORMs

ActiveRecord

The integration will look as follows:

class Pin < ActiveRecord::Base
  include StreamRails::Activity
  as_activity

  def activity_object
    self.item
  end
end

Sequel

Please, use Sequel ~5.

The integration will look as follows:

class Pin < Sequel::Model
  include StreamRails::Activity
  as_activity

  def activity_object
    self.item
  end
end

Model configuration

Include StreamRails::Activity and add as_activity to the model you want to integrate with your feeds.

class Pin < ActiveRecord::Base
  belongs_to :user
  belongs_to :item

  validates :item, presence: true
  validates :user, presence: true

  include StreamRails::Activity
  as_activity

  def activity_object
    self.item
  end

end

Everytime a Pin is created it will be stored in the feed of the user that created it. When a Pin instance is deleted, the feed will be removed as well.

Activity fields

ActiveRecord models are stored in your feeds as activities; Activities are objects that tell the story of a person performing an action on or with an object, in its simplest form, an activity consists of an actor, a verb, and an object. In order for this to happen your models need to implement these methods:

#activity_object the object of the activity (eg. an AR model instance)

#activity_actor the actor performing the activity -- this value also provides the feed name and feed ID to which the activity will be added.

For example, let's say a Pin was a polymorphic class that could belong to either a user (e.g. User ID: 1) or a company (e.g. Company ID: 1). In that instance, the below code would post the pin either to the user:1 feed or the company:1 feed based on its owner.

class Pin < ActiveRecord::Base
  belongs_to :owner, :polymorphic => true
  belongs_to :item

  include StreamRails::Activity
  as_activity

  def activity_actor
    self.owner
  end

  def activity_object
    self.item
  end

end

The activity_actor defaults to self.user

#activity_verb the string representation of the verb (defaults to model class name)

Here's a more complete example of the Pin class:

class Pin < ActiveRecord::Base
  belongs_to :author
  belongs_to :item

  include StreamRails::Activity
  as_activity

  def activity_actor
    self.author
  end

  def activity_object
    self.item
  end

end

Activity extra data

Often you'll want to store more data than just the basic fields. You achieve this by implementing #activity_extra_data in your model.

class Pin < ActiveRecord::Base
  belongs_to :author
  belongs_to :item

  include StreamRails::Activity
  as_activity

  def activity_extra_data
    {'is_retweet' => self.is_retweet}
  end

  def activity_object
    self.item
  end

end

Activity creation

If you want to control when to create an activity you should implement the #activity_should_sync? method in your model.

class Pin < ActiveRecord::Base
  belongs_to :author
  belongs_to :item

  include StreamRails::Activity
  as_activity

  def activity_should_sync?
    self.published
  end

  def activity_object
    self.item
  end

end

This will create an activity only when self.published is true.

Feed manager

stream_rails comes with a Feed Manager class that helps with all common feed operations. You can get an instance of the manager with StreamRails.feed_manager.

feed = StreamRails.feed_manager.get_user_feed(current_user.id)

Feeds bundled with feed_manager

To get you started the manager has 4 feeds pre-configured. You can add more feeds if your application requires it. Feeds are divided into three categories.

User feed:

The user feed stores all activities for a user. Think of it as your personal Facebook page. You can easily get this feed from the manager.

feed = StreamRails.feed_manager.get_user_feed(current_user.id)
News feeds:

News feeds store activities from the people you follow. There is both a flat newsfeed (similar to twitter) and an aggregated newsfeed (like facebook).

feed = StreamRails.feed_manager.get_news_feeds(current_user.id)[:flat]
aggregated_feed = StreamRails.feed_manager.get_news_feeds(current_user.id)[:aggregated]
Notification feed:

The notification feed can be used to build notification functionality.

Notification feed

Below we show an example of how you can read the notification feed.

notification_feed = StreamRails.feed_manager.get_notification_feed(current_user.id)

By default the notification feed will be empty. You can specify which users to notify when your model gets created. In the case of a retweet you probably want to notify the user of the parent tweet.

class Pin < ActiveRecord::Base
  belongs_to :author
  belongs_to :item

  include StreamRails::Activity
  as_activity

  def activity_notify
    if self.is_retweet
      [StreamRails.feed_manager.get_notification_feed(self.parent.user_id)]
    end
  end

  def activity_object
    self.item
  end

end

Another example would be following a user. You would commonly want to notify the user which is being followed.

class Follow < ActiveRecord::Base
  belongs_to :user
  belongs_to :target

  validates :target_id, presence: true
  validates :user, presence: true

  include StreamRails::Activity
  as_activity

  def activity_notify
    [StreamRails.feed_manager.get_notification_feed(self.target_id)]
  end

  def activity_object
    self.target
  end

end

Follow a feed

In order to populate newsfeeds, you need to notify the system about follow relationships.

The current user's flat and aggregated feeds will follow the target_user's user feed, with the following code:

StreamRails.feed_manager.follow_user(user_id, target_id)

Showing the newsfeed

Activity enrichment

When you read data from feeds, a pin activity will look like this:

{ "actor": "User:1", "verb": "like", "object": "Item:42" }

This is far from ready for usage in your template. We call the process of loading the references from the database "enrichment." An example is shown below:

enricher = StreamRails::Enrich.new

feed = StreamRails.feed_manager.get_news_feeds(current_user.id)[:flat]
results = feed.get()['results']
activities = enricher.enrich_activities(results)

A similar method called enrich_aggregated_activities is available for aggregated feeds.

enricher = StreamRails::Enrich.new

feed = StreamRails.feed_manager.get_news_feeds(current_user.id)[:aggregated]
results = feed.get()['results']
activities = enricher.enrich_aggregated_activities(results)

If you have additional metadata in your activity (by overriding activity_extra_data in the class where you add the Stream Activity mixin), you can also enrich that field's data by doing the following:

Step One: override the activity_extra_data method from our mixin:

class Pin < ActiveRecord::Base
  include StreamRails::Activity
  as_activity

  attr_accessor :extra_data

  def activity_object
    self.item
  end

  # override this method to add metadata to your activity
  def activity_extra_data
    @extra_data
  end
end

Now we'll create a 'pin' object which has a location metadata field. In this example, we will also have a location table and model, and we set up our metadata in the extra_data field. It is important that the symbol of the metadata as well as the value of the meta data match this pattern. The left half of the string:string metadata value when split on : must also match the name of the model.

We must also tell the enricher to also fetch locations when looking through our activities

boulder = Location.new
boulder.name = "Boulder, CO"
boulder.save!

# tell the enricher to also do a lookup on the `location` model
enricher.add_fields([:location])

pin = Pin.new
pin.user = @tom
pin.extra_data = {:location => "location:#{boulder.id}"}

When we retrieve the activity later, the enrichment process will include our location model as well, giving us access to attributes and methods of the location model:

place = activity[:location].name
# Boulder, CO

Templating

Now that you've enriched the activities you can render them in a view. For convenience we include a basic view:

<div class="container">
    <div class="container-pins">
        <% for activity in @activities %>
            <%= render_activity activity %>
        <% end %>
    </div>
</div>

The render_activity view helper will render the activity by picking the partial activity/_pin for a pin activity, aggregated_activity/_follow for an aggregated activity with verb follow.

The helper will automatically send activity to the local scope of the partial; additional parameters can be sent as well as use different layouts, and prefix the name

e.g. renders the activity partial using the small_activity layout:

<%= render_activity activity, :layout => "small_activity" %>

e.g. prefixes the name of the template with "notification_":

<%= render_activity activity, :prefix => "notification_" %>

e.g. adds the extra_var to the partial scope:

<%= render_activity activity, :locals => {:extra_var => 42} %>

e.g. renders the activity partial using the notifications partial root, which will render the partial with the path notifications/#{ACTIVITY_VERB}

<%= render_activity activity, :partial_root => "notifications" %>

Pagination

For simple pagination you can use the stream-ruby API, as follows in your controller:

  StreamRails.feed_manager.get_news_feeds(current_user.id)[:flat] # Returns a Stream::Feed object
  results = feed.get(limit: 5, offset: 5)['results']

Disable model tracking

You can disable model tracking (eg. when you run tests) via StreamRails.configure

require 'stream_rails'

StreamRails.enabled = false

Running specs

From the project root directory:

./bin/run_tests.sh

Full documentation and Low level APIs access

When needed you can also use the low level Ruby API directly. Documentation is available at the Stream website.

Copyright and License Information

Copyright (c) 2014-2021 Stream.io Inc, and individual contributors. All rights reserved.

See the file "LICENSE" for information on the history of this software, terms & conditions for usage, and a DISCLAIMER OF ALL WARRANTIES.

stream-rails's People

Contributors

aaronklaassen avatar deraru avatar dwightgunning avatar ferhatelmas avatar iandouglas avatar jfrux avatar joshmenden avatar kennym avatar maestromac avatar marco-ulge avatar peterdeme avatar pieterbeulque avatar rromanchuk avatar ruggi avatar tbarbugli avatar tschellenbach avatar victorfgs avatar yo-gen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stream-rails's Issues

activity_owner_id not found for a particular model on destroy

I have setup a following follower relationship just as mentioned in Michael Hartl's Rail Tutorial.
And I am using getstream to generate notifications whenever a user gets followed

class Relationship < ApplicationRecord
  belongs_to :follower, class_name: "User"
  belongs_to :followed, class_name: "User"
  validates :follower_id, presence: true
  validates :followed_id, presence: true

  default_scope { order(created_at: :desc) }

  include StreamRails::Activity
  as_activity

  def activity_actor
    self.follower
  end

  def activity_object
    self
  end

  def activity_verb
    "follow"
  end

  def activity_target
    self.followed
  end

  def activity_notify
    [StreamRails.feed_manager.get_notification_feed(self.followed.id)]
  end
end
class User < ApplicationRecord
  has_many :active_relationships,  class_name:  "Relationship",
                                   foreign_key: "follower_id",
                                   dependent:   :destroy
  has_many :passive_relationships, class_name:  "Relationship",
                                   foreign_key: "followed_id",
                                   dependent:   :destroy
  has_many :following, through: :active_relationships,  source: :followed
  has_many :followers, through: :passive_relationships, source: :follower
end

When I try to destroy a user, it destroys the associated relationships as well, because of dependent destroy.
But stream rails throws following error in destroying the notification activities for relationship

Something went wrong deleting an activity: undefined method `id' for nil:NilClass
NoMethodError: undefined method `id' for nil:NilClass
from /home/yogen/.rvm/gems/ruby-2.4.4@stormy-island/gems/stream_rails-2.5.2/lib/stream_rails/activity.rb:34:in `activity_owner_id'

It works for other dependent destroy associations, but only fails for this one.
Anyone know why?

Issue with feed enrichment

I'm running into an issue with feed enrichment, whereby it doesn't actually enrich the activity feed.

The result I'm getting from the API is this:

[{"activities"=>
   [{"actor"=>"User:3",
     "foreign_id"=>"Events::Applied:44",
     "id"=>"3ed3ae00-d148-11e7-8080-80004c5f321a",
     "object"=>"Events::Applied:44",
     "origin"=>nil,
     "target"=>"",
     "time"=>"2017-11-24T18:49:48.000000",
     "verb"=>"Events::Applied"}],
  "activity_count"=>1,
  "actor_count"=>1,
  "created_at"=>"2017-11-24T18:49:48.839288",
  "group"=>"Events::Applied_2017-11-24",
  "id"=>"3f53beb9-d148-11e7-8080-80012cf2ee2d",
  "is_read"=>false,
  "is_seen"=>false,
  "updated_at"=>"2017-11-24T18:49:48.839288",
  "verb"=>"Events::Applied"}]

This is an array of hashes with each hash containing the key activities and StreamRails::Enrich#collect_references accepts this array, however it loops through each hash in the array looking for the keys [:actor, :object, :target], which aren't in the top-level hash but instead nested under the activities key. This results in nothing being enriched.

Did the API change at all? It seems like collect_references should take each hash and loop through activity["activities"] instead.

Conditional Follow?

We have a slightly different feed system, where a single feed is represented as a specific object (imagine a forum thread) and users can follow that thread for all activity on it.

We want users to receive activities into their notification feeds, but do not want them to receive activities that they created themselves (where actor == self)

Is there a way to conditionally follow in this manner, or do we have to do the filtering on our end? I feel like it would work, but returning activities could take multiple calls.

Activity Actor System?

We have some actions that are performed by the system or global. It appears that this implementation requires a user/actor. Is there a clean way around this that Stream will accept?

Create activities manually?

Is there a way to use this gem if the verb/activity isn't a separate model? We have a state machine and state attribute on a model that defines "activities".

StreamRails::Activity overwrites activity_object method, breaks generic approach to Activity Objects

Our current approach to handle a generic activity type is to use STI with the base model ActivityObject and specific child models. It would be used as:

class Activity < ApplicationRecord
  include StreamRails::Activity
  as_activity

  belongs_to :user
  has_one :activity_object

  # ...
end

This approach, however, doesn't work because stream-rails overwrites methods such as activity_object.

I understand the recommended approach is to create specific Activity models and reference specific Activity Objects, however, it seems to us that the generic method would work just fine as well.

Is there a specific reason why stream-rails doesn't support this approach? Are there any possible issues we're missing with this approach?

Would you consider changing this behavior or accepting a PR?

callbacks and Mongoid compatibility

I'm curious as to why you're using after_commit instead of after_create and after_destroy here: https://github.com/GetStream/stream-rails/blob/master/lib/stream_rails/sync_policies.rb.

Using after_commit will cause data discrepancies if the call to the Stream API fails because it does not roll back the DB transaction.

Using after_create and after_destroy would not only allow ActiveRecord to roll back the transactions to keep the local data consistent with what's in Stream, but it would also make the callbacks compatible with Mongoid (Mongoid doesn't use after_commit because it has no transactions).

undefined method 'enriched?' for #<Hash:0x007fcbd9ea2bd8>

So, I get the following error when trying to load my notification_feed:

undefined method `key?' for #Array:0x007fcdf7bf0118

Where it is erroring in the gem:

stream_rails (2.4.0) lib/stream_rails/renderable.rb:28:in `block in render_aggregated'
stream_rails (2.4.0) lib/stream_rails/renderable.rb:28:in `map'
stream_rails (2.4.0) lib/stream_rails/renderable.rb:28:in `render_aggregated'
stream_rails (2.4.0) lib/stream_rails/renderable.rb:12:in `render'
stream_rails (2.4.0) lib/stream_rails/utils/view_helpers.rb:7:in `render_activity'

My Code:
notifications.html.erb:

<div>
    <h1>Notifications</h1>
    <div class="row">
      <div class="col-md-8">
            <% @activities.each do |activity| %>
        <%= render_activity activity %>
      <% end %>
        </div>
    </div>
</div>

notifications_controller.rb:

def notifications
    @user = current_user
    enricher = StreamRails::Enrich.new
    feed = StreamRails.feed_manager.get_notification_feed(@user.id)
    results = feed.get()['results']
    @activities = enricher.enrich_activities(results)
  end

Removing Fields from Enriched Data

Hi guys,

Just wondering if anyone has found an easy way to strip fields out from the Actor property to remove sensitive information (like email etc)

Ideally would prefer to whitelist available properties - anyone had any luck?

Thanks!

More than one activities per model?

I have a model called BookList, and we have two situations where we would want to create an activity for it.

  1. When it is first published. (Is not equal to creation - we call a separate method publish on the instance at some point to publish the list)
  2. When it is updated.

We can't do either, because the code implies that we create an activity after an object is created. How can I solve this?

Sequel ORM compatibility

This project seems to be compatible with ActiveRecord only at first glance, but we're on a Rails project which uses Sequel as the ORM. Bummer.

What are the plans for adding Sequel support? Pull requests welcome?

No feed results for news feeds

I don't see any results in any feeds other than user and notification feeds.
Any thoughts? I am using the stream-example-rails app to test this.

StreamRails.feed_manager.get_user_feed(current_user.id).get
=> {"duration"=>"16ms",
 "next"=>"",
 "results"=>
  [{"actor"=>"User:1",
    "foreign_id"=>"Follow:8",
    "id"=>"25be4280-58f0-11e6-8080-8000652ee02c",
    "object"=>"User:3",
    "origin"=>nil,
    "target"=>nil,
    "time"=>"2016-08-02T20:31:53.000000",
    "to"=>["notification:3"],
    "verb"=>"Follow"},
   {"actor"=>"User:1",
    "foreign_id"=>"Pin:1",
    "id"=>"c8498080-5500-11e6-8080-800018e5b57d",
    "object"=>"Item:113629430",
    "origin"=>nil,
    "target"=>nil,
    "time"=>"2016-07-28T20:20:53.000000",
    "to"=>[],
    "verb"=>"Pin"}
....
}]
StreamRails.feed_manager.get_news_feeds(current_user.id)[:aggregated].get
=> {"duration"=>"14ms", "next"=>"", "results"=>[]}

StreamRails.feed_manager.get_news_feeds(current_user.id)[:flat].get
=> {"duration"=>"11ms", "next"=>"", "results"=>[]}

Pagination

I am currently working-up a GetStream.io implementation into our product and debating how much of the stream-rails gem to use vs going direct to stream-ruby. I get that I can use the Enricher regardless, and that's super helpful (though I am overriding #retrieve_objects to get the serialization I want), but it looks like I'll not be able to use the feed_manager as I need pagination. Is there any plans to add that capacity to stream-rails or would you advise I just use stream-ruby directly for getting the feed?

Best practice for updated_at, created_at timestamp strings?

I'm noticing my client side date formatter is failing because my timestamps aren't being rendered the same way rails is formatting my active record created_at, updated_at columns. Since i'm getting these back as strings from the getstream enricher, should i run them through some normalization process like Time.parse("2018-05-09T03:32:41.997959").iso8601?

{"created_at"=>"2018-05-09T00:54:06.123351", 
"updated_at"=>"2018-05-09T05:40:06.526624"}

The format string on the client i'm using is:

public init() {
        
  let formatter = DateFormatter()
  formatter.locale = Locale(identifier: "en_US_POSIX")
  formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
        
  super.init(dateFormatter: formatter)
}

I'll do some investigation, probably a user error, i don't know what is what anymore.

FeedConfigException following readme

Hi guys,

I've set up the 4 standard feeds as expected (user,timeline,notification,timeline_aggregated) then proceeded to try and build out the code, but it keeps erroring out on me.

feed = StreamRails.feed_manager.get_news_feeds(current_user.id)[:flat]
results = feed.get()['results']

Seems to be the issue - [:flat] doesn't seem to work. I tried even making a feed called flat and still no dice.

Error message is as follows:

GET https://api.getstream.io/api/v1.0/feed/flat/1/?api_key=zas8wfdv6eyt: 400: FeedConfigException details: The following feeds are not configured: 'flat'. This could be the cause of a typo, but otherwise you should configure them on the dashboard of this app.

Any idea what could be causing this?

Net::OpenTimeout: execution expired

We keep getting timeout issues sporadically when using your service. Our stream app is in the us-east datacenter. Our own application runs on local dev environments (where we see it a lot) in NC and we've seen it 3 times in our staging environment now that runs out of a Digital Ocean datacenter in NYC.

Any ideas why this might be happening? Or should we just wrap it and deal with it (not ideal).

Overview:

Occurred at Jul 12, 2015 20:33:26
First seen at   Jul 07, 2015 17:59:00
Occurrences 3 (1 since last deploy on Jul 10, 2015 08:54:59)
URL <our server>
File    /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/http.rb:879
Hostname    <our server>
Error type  Net::OpenTimeout
Error message   Net::OpenTimeout: execution expired
Where   app/dashboard#index
Remote address  <our server>
User agent  
Safari 8.0

Backtrace:

/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/http.rb:879 in initialize
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/http.rb:879 in open
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/http.rb:879 in block in connect
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/timeout.rb:89 in block in timeout
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/timeout.rb:99 in call
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/timeout.rb:99 in timeout
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/http.rb:878 in connect
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/http.rb:863 in do_start
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/http.rb:852 in start
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/http.rb:1375 in request
/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/instrumentation/net.rb:27 in block (2 levels) in request_with_newrelic_trace
/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent.rb:426 in disable_all_tracing
/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/instrumentation/net.rb:26 in block in request_with_newrelic_trace
/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/cross_app_tracing.rb:48 in tl_trace_http_request
/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/instrumentation/net.rb:23 in request_with_newrelic_trace
/gems/httparty-0.13.5/lib/httparty/request.rb:101 in perform
/gems/httparty-0.13.5/lib/httparty.rb:522 in perform_request
/gems/httparty-0.13.5/lib/httparty.rb:460 in get
/gems/stream-ruby-2.2.3/lib/stream/client.rb:113 in make_http_request
/gems/stream-ruby-2.2.3/lib/stream/client.rb:86 in make_request
/gems/stream-ruby-2.2.3/lib/stream/feed.rb:49 in get
app/models/concerns/feed.rb:18 in unseen_notifications_count
app/views/app/_navbar.html.haml:39 in _app_views_app__navbar_html_haml___1625534003068966513_57394340
/gems/actionview-4.2.3/lib/action_view/template.rb:145 in block in render
/gems/activesupport-4.2.3/lib/active_support/notifications.rb:164 in block in instrument
/gems/activesupport-4.2.3/lib/active_support/notifications/instrumenter.rb:20 in instrument
/gems/activesupport-4.2.3/lib/active_support/notifications.rb:164 in instrument
/gems/actionview-4.2.3/lib/action_view/template.rb:333 in instrument
/gems/actionview-4.2.3/lib/action_view/template.rb:143 in render
/gems/actionview-4.2.3/lib/action_view/renderer/partial_renderer.rb:339 in render_partial
/gems/actionview-4.2.3/lib/action_view/renderer/partial_renderer.rb:310 in block in render
/gems/actionview-4.2.3/lib/action_view/renderer/abstract_renderer.rb:39 in block in instrument
/gems/activesupport-4.2.3/lib/active_support/notifications.rb:164 in block in instrument
/gems/activesupport-4.2.3/lib/active_support/notifications/instrumenter.rb:20 in instrument
/gems/activesupport-4.2.3/lib/active_support/notifications.rb:164 in instrument
/gems/actionview-4.2.3/lib/action_view/renderer/abstract_renderer.rb:39 in instrument
/gems/actionview-4.2.3/lib/action_view/renderer/partial_renderer.rb:309 in render
/gems/actionview-4.2.3/lib/action_view/renderer/renderer.rb:47 in render_partial
/gems/actionview-4.2.3/lib/action_view/helpers/rendering_helper.rb:35 in render
/gems/haml-4.0.6/lib/haml/helpers/action_view_mods.rb:10 in block in render_with_haml
/gems/haml-4.0.6/lib/haml/helpers.rb:89 in non_haml
/gems/haml-4.0.6/lib/haml/helpers/action_view_mods.rb:10 in render_with_haml
app/views/layouts/application.html.haml:14 in _app_views_layouts_application_html_haml___4547380192297984325_56161000
/gems/actionview-4.2.3/lib/action_view/template.rb:145 in block in render
/gems/activesupport-4.2.3/lib/active_support/notifications.rb:164 in block in instrument
/gems/activesupport-4.2.3/lib/active_support/notifications/instrumenter.rb:20 in instrument
/gems/activesupport-4.2.3/lib/active_support/notifications.rb:164 in instrument
/gems/actionview-4.2.3/lib/action_view/template.rb:333 in instrument
/gems/actionview-4.2.3/lib/action_view/template.rb:143 in render
/gems/actionview-4.2.3/lib/action_view/renderer/template_renderer.rb:66 in render_with_layout
/gems/actionview-4.2.3/lib/action_view/renderer/template_renderer.rb:52 in render_template
/gems/actionview-4.2.3/lib/action_view/renderer/template_renderer.rb:14 in render
/gems/actionview-4.2.3/lib/action_view/renderer/renderer.rb:42 in render_template
/gems/actionview-4.2.3/lib/action_view/renderer/renderer.rb:23 in render
/gems/actionview-4.2.3/lib/action_view/rendering.rb:100 in _render_template
/gems/actionpack-4.2.3/lib/action_controller/metal/streaming.rb:217 in _render_template
/gems/actionview-4.2.3/lib/action_view/rendering.rb:83 in render_to_body
/gems/actionpack-4.2.3/lib/action_controller/metal/rendering.rb:32 in render_to_body
/gems/actionpack-4.2.3/lib/action_controller/metal/renderers.rb:37 in render_to_body
/gems/actionpack-4.2.3/lib/abstract_controller/rendering.rb:25 in render
/gems/actionpack-4.2.3/lib/action_controller/metal/rendering.rb:16 in render
/gems/actionpack-4.2.3/lib/action_controller/metal/instrumentation.rb:44 in block (2 levels) in render
/gems/activesupport-4.2.3/lib/active_support/core_ext/benchmark.rb:12 in block in ms
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/benchmark.rb:303 in realtime
/gems/activesupport-4.2.3/lib/active_support/core_ext/benchmark.rb:12 in ms
/gems/actionpack-4.2.3/lib/action_controller/metal/instrumentation.rb:44 in block in render
/gems/actionpack-4.2.3/lib/action_controller/metal/instrumentation.rb:87 in cleanup_view_runtime
/gems/activerecord-4.2.3/lib/active_record/railties/controller_runtime.rb:25 in cleanup_view_runtime
/gems/actionpack-4.2.3/lib/action_controller/metal/instrumentation.rb:43 in render
/gems/remotipart-1.2.1/lib/remotipart/render_overrides.rb:14 in render_with_remotipart
/gems/actionpack-4.2.3/lib/action_controller/metal/implicit_render.rb:10 in default_render
/gems/actionpack-4.2.3/lib/action_controller/metal/implicit_render.rb:5 in send_action
/gems/actionpack-4.2.3/lib/abstract_controller/base.rb:198 in process_action
/gems/actionpack-4.2.3/lib/action_controller/metal/rendering.rb:10 in process_action
/gems/actionpack-4.2.3/lib/abstract_controller/callbacks.rb:20 in block in process_action
/gems/activesupport-4.2.3/lib/active_support/callbacks.rb:115 in call
/gems/activesupport-4.2.3/lib/active_support/callbacks.rb:115 in call
/gems/activesupport-4.2.3/lib/active_support/callbacks.rb:553 in block (2 levels) in compile
/gems/activesupport-4.2.3/lib/active_support/callbacks.rb:503 in call
/gems/activesupport-4.2.3/lib/active_support/callbacks.rb:503 in call
/gems/activesupport-4.2.3/lib/active_support/callbacks.rb:88 in run_callbacks
/gems/actionpack-4.2.3/lib/abstract_controller/callbacks.rb:19 in process_action
/gems/actionpack-4.2.3/lib/action_controller/metal/rescue.rb:29 in process_action
/gems/actionpack-4.2.3/lib/action_controller/metal/instrumentation.rb:32 in block in process_action
/gems/activesupport-4.2.3/lib/active_support/notifications.rb:164 in block in instrument
/gems/activesupport-4.2.3/lib/active_support/notifications/instrumenter.rb:20 in instrument
/gems/activesupport-4.2.3/lib/active_support/notifications.rb:164 in instrument
/gems/actionpack-4.2.3/lib/action_controller/metal/instrumentation.rb:30 in process_action
/gems/actionpack-4.2.3/lib/action_controller/metal/params_wrapper.rb:250 in process_action
/gems/activerecord-4.2.3/lib/active_record/railties/controller_runtime.rb:18 in process_action
/gems/actionpack-4.2.3/lib/abstract_controller/base.rb:137 in process
/gems/actionview-4.2.3/lib/action_view/rendering.rb:30 in process
/gems/actionpack-4.2.3/lib/action_controller/metal.rb:196 in dispatch
/gems/actionpack-4.2.3/lib/action_controller/metal/rack_delegation.rb:13 in dispatch
/gems/actionpack-4.2.3/lib/action_controller/metal.rb:237 in block in action
/gems/actionpack-4.2.3/lib/action_dispatch/routing/route_set.rb:76 in call
/gems/actionpack-4.2.3/lib/action_dispatch/routing/route_set.rb:76 in dispatch
/gems/actionpack-4.2.3/lib/action_dispatch/routing/route_set.rb:45 in serve
/gems/actionpack-4.2.3/lib/action_dispatch/journey/router.rb:43 in block in serve
/gems/actionpack-4.2.3/lib/action_dispatch/journey/router.rb:30 in each
/gems/actionpack-4.2.3/lib/action_dispatch/journey/router.rb:30 in serve
/gems/actionpack-4.2.3/lib/action_dispatch/routing/route_set.rb:821 in call
/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/newrelic_rpm-3.12.0.288/lib/new_relic/rack/agent_hooks.rb:30 in traced_call
/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/newrelic_rpm-3.12.0.288/lib/new_relic/rack/browser_monitoring.rb:32 in traced_call
/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/warden-1.2.3/lib/warden/manager.rb:35 in block in call
/gems/warden-1.2.3/lib/warden/manager.rb:34 in catch
/gems/warden-1.2.3/lib/warden/manager.rb:34 in call
/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/rack-1.6.4/lib/rack/etag.rb:24 in call
/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/rack-1.6.4/lib/rack/conditionalget.rb:25 in call
/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/rack-1.6.4/lib/rack/head.rb:13 in call
/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/remotipart-1.2.1/lib/remotipart/middleware.rb:27 in call
/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/actionpack-4.2.3/lib/action_dispatch/middleware/params_parser.rb:27 in call
/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/actionpack-4.2.3/lib/action_dispatch/middleware/flash.rb:260 in call
/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/rack-1.6.4/lib/rack/session/abstract/id.rb:225 in context
/gems/rack-1.6.4/lib/rack/session/abstract/id.rb:220 in call
/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/actionpack-4.2.3/lib/action_dispatch/middleware/cookies.rb:560 in call
/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/activerecord-4.2.3/lib/active_record/query_cache.rb:36 in call
/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:653 in call
/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/actionpack-4.2.3/lib/action_dispatch/middleware/callbacks.rb:29 in block in call
/gems/activesupport-4.2.3/lib/active_support/callbacks.rb:84 in run_callbacks
/gems/actionpack-4.2.3/lib/action_dispatch/middleware/callbacks.rb:27 in call
/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/actionpack-4.2.3/lib/action_dispatch/middleware/remote_ip.rb:78 in call
/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/actionpack-4.2.3/lib/action_dispatch/middleware/debug_exceptions.rb:17 in call
/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/actionpack-4.2.3/lib/action_dispatch/middleware/show_exceptions.rb:30 in call
/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/railties-4.2.3/lib/rails/rack/logger.rb:38 in call_app
/gems/railties-4.2.3/lib/rails/rack/logger.rb:20 in block in call
/gems/activesupport-4.2.3/lib/active_support/tagged_logging.rb:68 in block in tagged
/gems/activesupport-4.2.3/lib/active_support/tagged_logging.rb:26 in tagged
/gems/activesupport-4.2.3/lib/active_support/tagged_logging.rb:68 in tagged
/gems/railties-4.2.3/lib/rails/rack/logger.rb:20 in call
/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/actionpack-4.2.3/lib/action_dispatch/middleware/request_id.rb:21 in call
/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/rack-1.6.4/lib/rack/methodoverride.rb:22 in call
/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/rack-1.6.4/lib/rack/runtime.rb:18 in call
/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/activesupport-4.2.3/lib/active_support/cache/strategy/local_cache_middleware.rb:28 in call
/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/rack-1.6.4/lib/rack/sendfile.rb:113 in call
/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/rack-timeout-0.2.4/lib/rack/timeout.rb:108 in call
/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/railties-4.2.3/lib/rails/engine.rb:518 in call
/gems/railties-4.2.3/lib/rails/application.rb:165 in call
/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67 in call
/gems/unicorn-4.9.0/lib/unicorn/http_server.rb:580 in process_client
/gems/unicorn-4.9.0/lib/unicorn/http_server.rb:674 in worker_loop
/gems/unicorn-4.9.0/lib/unicorn/http_server.rb:529 in spawn_missing_workers
/gems/unicorn-4.9.0/lib/unicorn/http_server.rb:140 in start
/gems/unicorn-4.9.0/bin/unicorn:126 in <top (required)>
[GEM_ROOT]/bin/unicorn:23 in load
[GEM_ROOT]/bin/unicorn:23 in <main>

Enriching namespaced classes is broken

The token for classes is based on ':', however a namespaced model will have ':' in the class name, and so enrichment will fail.

I have a fork where in enrich.rb, instead of splitting the string on ':', I split on:

/(?<!:):(?!:)/

However, I don't have a spec for it, it I get to I'll try and write that and submit a pull sometime this week.

And, it's probably not the best solution - it would be better to use a splitting token is not ':', but something more unique, probably more than one character. But this would cause compatibility issues with existing users, so probably not a good way to do that.

Notification feed needs configuring?

I've followed the basic instructions in my rails application and am current stuck on this line of code.

def activity_notify
    [StreamRails.feed_manager.get_notification_feed(self.parent.user.id)]
end

It seems everytime I try to push an event into the target's notification feed, I get the error:
FeedConfigException details: The following feeds are not configured: 'user'

I have the following configuration inside the initializer:

config.news_feeds = { 
   flat: 'timeline_flat', 
   aggregated: 'timeline_aggregated'
}
config.notification_feed = 'Notification'

On the dashboard, I've created a notification feed called:
image

I'm not sure why I need to configure/create a user feed when that has nothing to do with my notification feed. Or maybe I need to create a new notification feed called "user"? If so, then what was the point of setting this configuration: config.notification_feed = 'Notification' and what does it do? Thanks for your help.

Enricher breaks down if, in certain activities, an enriched field is not available

In some of my activities I have a target, in others, I don't. This is how I'm currently doing it:

enricher = StreamRails::Enrich.new([:actor, :object, :target])

# other code removed for legibility

feed = StreamRails.feed_manager.get_feed(type, params[:stream_feed_id]).get(limit: limit, offset: offset)

mapped = enricher.enrich_activities(updatedFeedWithHints)  

For the activity items that don't have a target, ruby errors out on the split method when attempting to split the field_value.

Am I doing this correctly?

Here's the trace:

stream_rails (2.2.0) lib/stream_rails/enrich.rb:39:in `model_field?'
stream_rails (2.2.0) lib/stream_rails/enrich.rb:75:in `block (2 levels) in collect_references'
stream_rails (2.2.0) lib/stream_rails/enrich.rb:74:in `each'
stream_rails (2.2.0) lib/stream_rails/enrich.rb:74:in `block in collect_references'
stream_rails (2.2.0) lib/stream_rails/enrich.rb:73:in `each'
stream_rails (2.2.0) lib/stream_rails/enrich.rb:73:in `collect_references'
stream_rails (2.2.0) lib/stream_rails/enrich.rb:53:in `enrich_activities'

undefined method `enriched?' for #<Hash:0x000000069cebf8>

I have following code in my controller and views respectively. The feed is returned correctly in the controller. But template rendering throws this error.
undefined method `enriched?' for #Hash:0x000000069cebf8
Anyone has any idea?

class NotificationsController < ApplicationController
  before_action :authenticate_user!

  def index
  	@enricher = StreamRails::Enrich.new
	@feed = StreamRails.feed_manager.get_notification_feed(current_user.id)
	@results = @feed.get()['results']
	@activities = @enricher.enrich_activities(@results)
  end

end

Following is the view code

<div class="container">
    <div class="container-pins">
    	<% byebug %>
      <% for activity in @activities %>
          <%= render_activity activity %>
      <% end %>
    </div>
</div>

Activity Callback to send an email

I have to send an email for each notification. Is there a callback method or a built-in method to do that?
Can I aggregated more notifications in only one email?

Can't send multiple activities with different verbs at the same time

Hey, I'm doing an implementation in which an action triggers two activities (with different verbs), but when I create them, somehow it only detects one of the verbs.

I've included added a custom after_commit callback that manually creates activities

Example:

feed = StreamRails.feed_manager.get_owner_feed(self)
feed.add_activities([{
    :actor=>"User:2",
    :verb=>"verb_1",
    :object=>"User:62922",
    :foreign_id=>"MyModel:73891",
    :target=>"MyModel:73891",
    :time=>"2018-10-05T11:33:49-03:00",
    :to=>["notification:62922"]
  },
  {
    :actor=>"User:2",
    :verb=>"verb_2",
    :object=>"User:62922",
    :foreign_id=>"MyModel:73891",
    :target=>"MyModel:73891",
    :time=>"2018-10-05T11:33:49-03:00",
    :to=>["notification:69930", "notification:76850", "notification:3", "notification:12", "notification:74564"]
  }])

I get a correct response:

{
  "activities"=>[{
    "actor"=>"User:2",
    "foreign_id"=>"MyModel:73891",
    "id"=>"xxxxxx",
    "object"=>"User:62922",
    "origin"=>nil,
    "target"=>"MyModel:73891",
    "time"=>"2018-10-05T14:33:49.000000",
    "to"=>["notification:62922"],
    "verb"=>"verb_1"
  },
  {
    "actor"=>"User:2",
    "foreign_id"=>"MyModel:73891",
    "id"=>"xxxxxxx",
    "object"=>"User:62922",
    "origin"=>nil,
    "target"=>"MyModel:73891",
    "time"=>"2018-10-05T14:33:49.000000",
    "to"=>["notification:69930", "notification:76850", "notification:3", "notification:12", "notification:74564"],
    "verb"=>"verb_2"
  }],
  "duration"=>"14.48ms"
}

But when I get User 62922 notifications, it is saved as a verb_2 activity:

StreamRails.feed_manager.get_notification_feed(62922).get

returns:

{
  "results"=>[{
    "activities"=>[{
      "actor"=>"User:2",
      "foreign_id"=>"MyModel:73891",
      "id"=>"xxxxxx",
      "object"=>"User:62922",
      "origin"=>nil,
      "target"=>"MyModel:73891",
      "time"=>"2018-10-05T14:33:49.000000",
      "verb"=>"verb_2"
    }]
  }]
}

How to use StreamRails.config.news_feeds with custom feed names?

I have the following slugs for my feeds:

  • timeline_flat (instead of flat)
  • timeline_aggregated (instead of aggregated)

set like this:

StreamRails.configure do |config|
  config.news_feeds = { flat: "timeline_flat", aggregated: "timeline_aggregated" }
end

However, upon trying to call the news feed like this:

StreamRails.feed_manager.get_news_feeds(current_user.id)[:flat]

I get an error. Also with this:

StreamRails.feed_manager.get_news_feeds(current_user.id)[:timeline_flat]

Any ideas what I might be doing wrong?

How would I represent this activity...

John Smith commented on Susy Smith's post entitled "Things I love".
"I love your things I love list!" <--- this would be john's comment

So I would need:

  • Actor (John Smith)
  • Owner (Susy Smith)
  • Post (title: "Things I love")
  • Comment (message: "I love your things I love list!")

Right? Maybe this is out of the scope of stream-rails?
Maybe question for stream-ruby?

Error when saving comment

I'm using acts_as_commentable.

My comment model looks like this:

class Comment < ActiveRecord::Base

  include ActsAsCommentable::Comment

  belongs_to :user
  belongs_to :commentable, :polymorphic => true
  include StreamRails::Activity
  as_activity
  default_scope -> { order('created_at ASC') }

  def activity_notify
    if self.commentable_type == 'Archive'
      [
        StreamRails.feed_manager.get_notification_feed(self.commentable.host_id),
        StreamRails.feed_manager.get_notification_feed(self.commentable.peer_id)
      ]
    end
  end

  def activity_object
    self.commentable
  end
end

For some reason, everytime I save I'm getting error:
user_id can only contain alphanumeric characters plus underscores and dashes

Having issues with namespace using public_activity gem

I'm getting a #1089 ArgumentError: wrong number of arguments (given 2, expected 1) in a method unrelated to this project, and i noticed it looks like a name space collision /lib/stream_rails/utils/view_helpers.rb" line 7 in render_activity

Looks like an unfortunate collision between public_activity and stream_rails
https://github.com/chaps-io/public_activity/blob/master/lib/public_activity/utility/view_helpers.rb#L6

https://github.com/GetStream/stream-rails/blob/master/lib/stream_rails/utils/view_helpers.rb#L6

Enrichment doesn't work with namespaced models

Enrichment works by storing a reference to the model name in the format Name:ID, e.g. User:5. This doesn't work when the model name is namespaced, such as Namespaced::Model:5 -- splitting on :, results in ["Namespaced", "", "Model", "5"], which isn't what we want.

This should work, although I'm sure there's a more elegant way:

parts = value.split(":")
id = parts.pop
model = parts.reject(&:blank?).join("::")

enriched? error

Im getting this error

Missing partial activity/_click

im trying to do this as a realtime feed

Displaying grouped[:aggregated] feeds

Hello @tbarbugli

I have configured activity feeds and it's all working except the display of Aggregated feeds.

How to display aggregated feeds so that it displays like -

You followed Tom, Jessica and 2 more people
You followed Tom and Jessica

Do I have to alter the partials to respond if a feed is flat or aggregated?

Thanks,
Gaurav

Enhancing feed_manager to follow a few models

Using Stream-rails, I noticed that feed_manager allows users follow just other users.

However, nowadays people follow communities not less than users and it would be awesome to make the current feed_manager more flexible to use custom models for dealing with feeds.

Enricher possible to use my model method instead of the model attributes?

My models have a "serialize" method that returns a basic object containing exactly the formatted data I want to be sent to the clients from my api.

I tried changing my model to be like this:

def activity_actor
    follower.user.serialize
  end

  def activity_object
    followable.user.serialize
  end

But it's still sending the entire user model...?

Caching feeds - slow page load

Hi @tbarbugli,

Great project for activity streams.

  1. One problem I am seeing is slow page load - basically mini profiler is reporting it's taking about 1 second to load the page which has activity feed. Is there a way to cache the feeds into a rails app and only query when a feed is created/destroyed?
  2. Is there a way to get all user feeds without restricting to current_user ?

Thanks,
Gaurav

activity_notify not working

I've tested this getting the target feed to see if it is notified, but it returns no results.

    def activity_notify
      [StreamRails.feed_manager.get_notification_feed(self.target_id)]
    end

feed = StreamRails.feed_manager.get_user_feed(@target.id)

Group aggregate feeds by object instead of actor

Currently aggregate fields are grouped by actor (ben liked 5 photos).

I would like to group aggregate fields by the object (24 people liked this photo)

Is this possible? My like model looks like this:

class Like < ActiveRecord::Base
	belongs_to :user
	belongs_to :photo
	include StreamRails::Activity
	as_activity

	def activity_notify
		[StreamRails.feed_manager.get_notification_feed(self.photo.user_id)]
	end

	def activity_object
		self.photo
	end

	def activity_actor
		self.user
	end

end

Verb is always name of model

For some reason, my integration of Stream is using the name of my model (Picture) as the verb of all its activities instead of something like 'create' - I'm not sure why.

models/picture.rb (excerpt):

include StreamRails::Activity
as_activity

def activity_object
  self
end

The issue may be to do with my use of self rather than self.item - however, using self.item it throws the following error while running the picture#create action:

undefined method `item' for #<Picture:0x0000000005b1a8a0>

Not sure why this is happening, but thanks in advance for your help.

Upgrade to latest version of stream-ruby?

stream-rails is using a much older version of stream-ruby where the Stream::Client doesn't expose methods like update_activity and update_activities. Any plans of upgrading it?

feed_name and naming issue in general

automatically it becomes class.downcase

 @feed_name="user1",
 @feed_url="user/1",
 @id="user:1",

why is this and why don't we keep the rails convention of namespacing Admin::User or User::Image ?

i found out that the stream is case-sensitive so we can run into lots of problems here

i think it's a better approach to make it

 @feed_name="User1",
 @feed_url="User/1",
 @id="User:1",

or then

 @feed_name="AdminUser1",
 @feed_url="AdminUser/1",
 @id="Admin::User:1",

def timeline_object(obj)
 "#{obj.class}:#{obj.id}"
end

you write in your docs at some point
The left half of the string:string metadata value when split on : must also match the name of the model.

but the truth is, the model isnt called user, indeed its name is User. As rails follows Convention over Configuration we should follow this route and change this behaviour pretty fast, as this gem is still in an early stage

thoughts?

undefined method user_id

I'm trying to create activity using a model that doesn't have a user_id.

Below is my implementation. Am i missing something?

class UserSubscription < ActiveRecord::Base
  include StreamRails::Activity

  as_activity

  after_create :subscribe_to_activity_feed
  after_destroy :unsubscribe_to_activity_feed

  belongs_to :subscriber, class_name: 'User', counter_cache: :subscribers_count
  belongs_to :subscribe_to, class_name: 'User', counter_cache: :subscriptions_count

  def activity_actor
    subscriber
  end

  def activity_object
    subscribe_to
  end

Realtime feed update

Hey @tbarbugli,

How to retrieve realtime feeds into APP (not notification)?

For ex - If an activity is added it should update the feed with new activity

Thanks,
Gaurav

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.