Sha256: a400f8957a38bf90dd22b56116bb591df09bd2d805806f1c89528f35b73d9036

Contents?: true

Size: 1.47 KB

Versions: 8

Compression:

Stored size: 1.47 KB

Contents

class Group < ActiveRecord::Base
  include SocialStream::Models::Subject

  attr_accessor :_participants

  delegate :description, :description=, :to => :profile!

  after_create :create_ties

  def profile!
    actor!.profile || actor!.build_profile
  end
 
  def recent_groups
    contact_subjects(:type => :group, :direction => :sent) do |q|
      q.select("contacts.created_at").
        merge(Contact.recent)
    end
  end

  private

  # Creates ties from founder to the group, based on _relation_ids,
  # and ties from the group to founder and participants.
  def create_ties
    create_ties_from_founder
    create_ties_to_participants
  end

  # Creates the ties from the founder to the group
  def create_ties_from_founder
    author.sent_contacts.create! :receiver_id  => actor_id,
                                 :relation_ids => _relation_ids

    if represented_author?
      user_author.sent_contacts.create! :receiver_id  => actor_id,
                                        :relation_ids => _relation_ids
    end
  end
  
  # Creates the ties from the group to the participants
  def create_ties_to_participants
    participant_ids = ([ author_id, user_author_id ] | Array.wrap(@_participants)).uniq

    participant_ids.each do |a|
      sent_contacts.create! :receiver_id  => a,
                            :user_author  => user_author,
                            :relation_ids => Array(relation_customs.sort.first.id)
    end
  end
end

ActiveSupport.run_load_hooks(:group, Group)

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
social_stream-0.25.1 base/app/models/group.rb
social_stream-base-0.19.1 app/models/group.rb
social_stream-0.25.0 base/app/models/group.rb
social_stream-base-0.19.0 app/models/group.rb
social_stream-0.24.1 base/app/models/group.rb
social_stream-base-0.18.1 app/models/group.rb
social_stream-0.24.0 base/app/models/group.rb
social_stream-base-0.18.0 app/models/group.rb