base/app/models/actor.rb in social_stream-2.1.1 vs base/app/models/actor.rb in social_stream-2.2.0

- old
+ new

@@ -26,11 +26,13 @@ acts_as_avatarable :default_url => "/assets/:attachment/:style/:subtype_class.png" acts_as_messageable acts_as_url :name, :url_attribute => :slug - + + serialize :notification_settings + has_one :profile, dependent: :destroy, inverse_of: :actor has_many :sent_contacts, @@ -130,10 +132,16 @@ scope :contacted_from, lambda { |a| joins(:received_contacts).merge(Contact.active.sent_by(a)) } + scope :not_contacted_from, lambda { |a| + if a.present? + where(arel_table[:id].not_in(a.sent_active_contact_ids + [a.id])) + end + } + scope :followed, joins(:activity_object).merge(ActivityObject.followed) scope :followed_by, lambda { |a| select("DISTINCT actors.*"). joins(:received_ties => { :relation => :permissions }). @@ -141,11 +149,11 @@ merge(Permission.follow) } scope :subject_type, lambda { |t| if t.present? - where(subject_type: t.classify) + where(subject_type: t.split(',').map(&:classify)) end } scope :recent, -> { order('actors.updated_at DESC') } @@ -215,19 +223,34 @@ # The relations that will appear in privacy forms # # They usually include {Relation::Custom} but may also include other system-defined # relations that are not editable but appear in add contact buttons def relations_list - Relation.extra_list(subject) + relation_customs + Relation.system_list(subject) + relation_customs end # The relations offered in the "Add contact" button when subjects # add new contacts - def relations_for_button + def relations_for_select relations_list end + # Return an object of choices suitable for the contact add button or modal + def options_for_contact_select + relations_for_select.map{ |r| [ r.name, r.id ] } + end + + # Options for contact select are simple + def options_for_contact_select_simple? + relations_list.count == 1 + end + + # Returns the type for contact select, :simple or :multiple + def options_for_contact_select_type + options_for_contact_select_simple? ? :simple : :multiple + end + # All the {Actor Actors} this one has ties with: # # actor.contact_actors #=> array of actors that sent and receive ties from actor # # @@ -291,11 +314,11 @@ end if options[:relations].present? as = as.merge(Tie.related_by(options[:relations])) else - as = as.merge(Relation.where(:type => ['Relation::Custom', 'Relation::Public'])) + as = as.merge(Relation.positive) end as end @@ -326,11 +349,11 @@ end # Return a contact to subject. Create it if it does not exist def contact_to!(subject) contact_to(subject) || - sent_contacts.create!(:receiver => Actor.normalize(subject)) + sent_contacts.create!(receiver_id: Actor.normalize_id(subject)) end # The {Contact} of this {Actor} to self (totally close!) def self_contact contact_to!(self) @@ -432,15 +455,25 @@ any? end # The default {Relation Relations} for sharing an {Activity} owned # by this {Actor} + # + # Activities are shared with all the contacts by default. + # + # You can change this behaviour with a decorator, overwriting this method. + # For example, if you want the activities shared publicly by default, create + # a decorator in app/decorators/actor_decorator.rb with + # Actor.class_eval do + # def activity_relations + # [ Relation::Public.instance ] + # end + # end + # def activity_relations - SocialStream.relation_model == :custom ? - relations. - allowing('read', 'activity') : - [ Relation::Public.instance ] + relations. + allowing('read', 'activity') end # The ids of the default {Relation Relations} for sharing an {Activity} # owned by this {Actor} def activity_relation_ids @@ -514,10 +547,15 @@ image: { url: options[:helper].root_url + logo.url(:small) } } end - + + def notification_settings + self.update_attribute(:notification_settings, SocialStream.default_notification_settings) unless super + super + end + private # After create callback def create_initial_relations Relation::Custom.defaults_for(self)