Module: Diaspora::Shareable::QueryMethods

Defined in:
lib/diaspora/shareable.rb

Instance Method Summary collapse

Instance Method Details

#by_max_time(max_time, order = "created_at") ⇒ Object


83
84
85
# File 'lib/diaspora/shareable.rb', line 83

def by_max_time(max_time, order="created_at")
  where("#{table_name}.#{order} < ?", max_time).order("#{table_name}.#{order} DESC")
end

#for_visible_shareable_sql(max_time, order, limit = 15, types = Stream::Base::TYPES_OF_POST_IN_STREAM) ⇒ Object


79
80
81
# File 'lib/diaspora/shareable.rb', line 79

def for_visible_shareable_sql(max_time, order, limit=15, types=Stream::Base::TYPES_OF_POST_IN_STREAM)
  by_max_time(max_time, order).order(table_name + ".id DESC").where(type: types).limit(limit)
end

#from_person_visible_by_user(user, person) ⇒ Object


71
72
73
74
75
76
77
# File 'lib/diaspora/shareable.rb', line 71

def from_person_visible_by_user(user, person)
  return owned_by_user(user) if person == user.person

  with_visibility.where(author_id: person.id).where(
    visible_by_user(user).or(arel_table[:public].eq(true))
  ).select("DISTINCT #{table_name}.*")
end

#owned_by_user(user) ⇒ Object


87
88
89
# File 'lib/diaspora/shareable.rb', line 87

def owned_by_user(user)
  user.person.public_send(table_name)
end

#owned_or_visible_by_user(user) ⇒ Object


64
65
66
67
68
69
# File 'lib/diaspora/shareable.rb', line 64

def owned_or_visible_by_user(user)
  with_visibility.where(
    visible_by_user(user).or(arel_table[:public].eq(true)
                               .or(arel_table[:author_id].eq(user.person_id)))
  ).select("DISTINCT #{table_name}.*")
end