Sha256: 6e9cb4d37565fca39f89942980d19e2d39fd83f3651302e10622dcddc3bbc6be

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 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
    contact_subjects(:subject_type => :user, :direction => :received)
  end
  
  def recent_groups
    contact_subjects(:type => :group, :direction => :sent) do |q|
      q.select("contacts.created_at").
        merge(Contact.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_contacts.create! :receiver => founder,
                          :relation_ids => Array(relation_customs.sort.first.id)
  end
  
  # Creates the ties between the group and the participants
  def create_participants
     return if @_participants.blank?
    
     @_participants.each do |participant|
      
       participant_actor = Actor.find(participant)

       sent_contacts.create! :receiver => participant_actor,
                             :relation_ids => Array(relation_customs.sort.first.id)
     end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
social_stream-base-0.6.0 app/models/group.rb