Sha256: 24e95c014044d270b58573c7ce42a221ce5460aa403388cdc7bdeb54fba45219

Contents?: true

Size: 1.18 KB

Versions: 2

Compression:

Stored size: 1.18 KB

Contents

class Group < ActiveRecord::Base
  attr_accessor :_founder
  attr_accessor :_participants

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

  after_create :create_founder
  after_create :create_participants

  def profile!
    actor!.profile || actor!.build_profile
  end

  def followers
    subjects(:subject_type => :user, :direction => :senders)
  end
  
  def recent_groups
    subjects(:subject_type => :group, :direction => :receivers) do |q|
      q.select("ties.created_at").
        merge(Tie.recent)
    end
  end
 
  private

  #Creates the ties between the group and the founder
  def create_founder
    founder =
      Actor.find_by_slug(_founder) || raise("Cannot create group without founder")

    sent_ties.create! :receiver => founder,
                      :relation => relations.sort.first
  end
  
  #Creates the ties betwbeen the group and the participants
  def create_participants
    
     return if @_participants.blank?
    
     @_participants.each do |participant|
      
      participant_actor = Actor.find_by_id(participant.to_i)

      sent_ties.create! :receiver => participant_actor,
                        :relation => relations.sort.first
     end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
social_stream-0.4.1 app/models/group.rb
social_stream-0.4.0 app/models/group.rb