Module: Diaspora::Shareable

Included in:
Photo, Post
Defined in:
lib/diaspora/shareable.rb

Defined Under Namespace

Modules: QueryMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(model) ⇒ Object


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/diaspora/shareable.rb', line 11

def self.included(model)
  model.instance_eval do
    include Diaspora::Fields::Guid
    include Diaspora::Fields::Author

    has_many :aspect_visibilities, as: :shareable, validate: false, dependent: :delete_all
    has_many :aspects, through: :aspect_visibilities

    has_many :share_visibilities, as: :shareable, dependent: :delete_all

    delegate :id, :name, :first_name, to: :author, prefix: true

    # scopes
    scope :with_visibility, -> {
      joins("LEFT OUTER JOIN share_visibilities ON share_visibilities.shareable_id = #{table_name}.id AND "\
        "share_visibilities.shareable_type = '#{base_class}'")
    }

    scope :with_aspects, -> {
      joins("LEFT OUTER JOIN aspect_visibilities ON aspect_visibilities.shareable_id = #{table_name}.id AND "\
      " aspect_visibilities.shareable_type = '#{base_class}'")
    }
  end
  model.extend Diaspora::Shareable::QueryMethods
end

Instance Method Details

#receive(recipient_user_ids) ⇒ Object


37
38
39
40
41
# File 'lib/diaspora/shareable.rb', line 37

def receive(recipient_user_ids)
  return if recipient_user_ids.empty? || public?

  ShareVisibility.batch_import(recipient_user_ids, self)
end

#subscribed_pods_urisArray<String>

Remote pods which are known to be subscribed to the post. Must include all pods which received the post in the past.

Returns:

  • (Array<String>)

    The list of pods' URIs


59
60
61
# File 'lib/diaspora/shareable.rb', line 59

def subscribed_pods_uris
  Pod.find(subscribers.select(&:remote?).map(&:pod_id).uniq).map {|pod| pod.url_to("") }
end

#subscribersArray<Person>

The list of people that should receive this Shareable.

Returns:

  • (Array<Person>)

    The list of subscribers to this shareable


46
47
48
49
50
51
52
53
# File 'lib/diaspora/shareable.rb', line 46

def subscribers
  user = author.owner
  if public?
    [*user.contact_people, author]
  else
    user.people_in_aspects(user.aspects_with_shareable(self.class, id))
  end
end