-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
101 changed files
with
163 additions
and
1,758 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,112 +1,115 @@ | ||
# frozen_string_literal: true | ||
|
||
module User::Querying | ||
def find_visible_shareable_by_id(klass, id, opts={}) | ||
key = (opts.delete(:key) || :id) | ||
find_visible_shareable_by_id = EvilQuery::VisibleShareableById.new(self, klass, key, id, opts) | ||
find_visible_shareable_by_id.post! | ||
end | ||
class User | ||
module Querying | ||
def find_visible_shareable_by_id(klass, id, opts={}) | ||
key = (opts.delete(:key) || :id) | ||
find_visible_shareable_by_id = EvilQuery::VisibleShareableById.new(self, klass, key, id, opts) | ||
find_visible_shareable_by_id.post! | ||
end | ||
|
||
def visible_shareables(klass, opts={}) | ||
opts = prep_opts(klass, opts) | ||
shareable_ids = visible_shareable_ids(klass, opts) | ||
klass.where(id: shareable_ids).select("DISTINCT #{klass.table_name}.*") | ||
.limit(opts[:limit]).order(opts[:order_with_table]) | ||
end | ||
def visible_shareables(klass, opts={}) | ||
opts = prep_opts(klass, opts) | ||
shareable_ids = visible_shareable_ids(klass, opts) | ||
klass.where(id: shareable_ids).select("DISTINCT #{klass.table_name}.*") | ||
.limit(opts[:limit]).order(opts[:order_with_table]) | ||
end | ||
|
||
# @param [TrueClass] with_order | ||
def posts_from(person, with_order: true) | ||
base_query = Post.from_person_visible_by_user(self, person) | ||
return base_query.order("posts.created_at desc") if with_order | ||
# @param [TrueClass] with_order | ||
def posts_from(person, with_order: true) | ||
base_query = Post.from_person_visible_by_user(self, person) | ||
return base_query.order("posts.created_at desc") if with_order | ||
|
||
base_query | ||
end | ||
base_query | ||
end | ||
|
||
def photos_from(person, opts={}) | ||
opts = prep_opts(Photo, opts) | ||
Photo.from_person_visible_by_user(self, person) | ||
.limit(opts[:limit]) | ||
end | ||
def photos_from(person, opts={}) | ||
opts = prep_opts(Photo, opts) | ||
Photo.from_person_visible_by_user(self, person) | ||
.limit(opts[:limit]) | ||
end | ||
|
||
def contact_for(person) | ||
return nil unless person | ||
def contact_for(person) | ||
return nil unless person | ||
|
||
contact_for_person_id(person.id) | ||
end | ||
contact_for_person_id(person.id) | ||
end | ||
|
||
def block_for(person) | ||
return nil unless person | ||
blocks.find_by(person_id: person.id) | ||
end | ||
def block_for(person) | ||
return nil unless person | ||
|
||
def aspects_with_shareable(base_class_name_or_class, shareable_id) | ||
base_class_name = base_class_name_or_class | ||
base_class_name = base_class_name_or_class.base_class.to_s if base_class_name_or_class.is_a?(Class) | ||
self.aspects.joins(:aspect_visibilities).where(:aspect_visibilities => {:shareable_id => shareable_id, :shareable_type => base_class_name}) | ||
end | ||
blocks.find_by(person_id: person.id) | ||
end | ||
|
||
def contact_for_person_id(person_id) | ||
Contact.includes(person: :profile) | ||
.find_by(user_id: id, person_id: person_id) | ||
end | ||
def aspects_with_shareable(base_class_name_or_class, shareable_id) | ||
base_class_name = base_class_name_or_class | ||
base_class_name = base_class_name_or_class.base_class.to_s if base_class_name_or_class.is_a?(Class) | ||
aspects.joins(:aspect_visibilities).where(aspect_visibilities: {shareable_id: shareable_id, | ||
shareable_type: base_class_name}) | ||
end | ||
|
||
def contact_for_person_id(person_id) | ||
Contact.includes(person: :profile) | ||
.find_by(user_id: id, person_id: person_id) | ||
end | ||
|
||
# @param [Person] person | ||
# @return [Boolean] whether person is a contact of this user | ||
def has_contact_for?(person) | ||
Contact.exists?(:user_id => self.id, :person_id => person.id) | ||
end | ||
# @param [Person] person | ||
# @return [Boolean] whether person is a contact of this user | ||
def has_contact_for?(person) | ||
Contact.exists?(user_id: id, person_id: person.id) | ||
end | ||
|
||
def people_in_aspects(requested_aspects, opts={}) | ||
allowed_aspects = self.aspects & requested_aspects | ||
aspect_ids = allowed_aspects.map(&:id) | ||
def people_in_aspects(requested_aspects, opts={}) | ||
allowed_aspects = aspects & requested_aspects | ||
aspect_ids = allowed_aspects.map(&:id) | ||
|
||
people = Person.in_aspects(aspect_ids) | ||
people = Person.in_aspects(aspect_ids) | ||
|
||
if opts[:type] == 'remote' | ||
people = people.where(:owner_id => nil) | ||
elsif opts[:type] == 'local' | ||
people = people.where('people.owner_id IS NOT NULL') | ||
if opts[:type] == "remote" | ||
people = people.where(owner_id: nil) | ||
elsif opts[:type] == "local" | ||
people = people.where.not(people: {owner_id: nil}) | ||
end | ||
people | ||
end | ||
people | ||
end | ||
|
||
def aspects_with_person(person) | ||
contact_for(person).aspects | ||
end | ||
def aspects_with_person(person) | ||
contact_for(person).aspects | ||
end | ||
|
||
def posts_from(person, with_order=true) | ||
base_query = Post.from_person_visible_by_user(self, person) | ||
return base_query.order("posts.created_at desc") if with_order | ||
def posts_from(person, with_order=true) | ||
base_query = Post.from_person_visible_by_user(self, person) | ||
return base_query.order("posts.created_at desc") if with_order | ||
|
||
base_query | ||
end | ||
base_query | ||
end | ||
|
||
def photos_from(person, opts={}) | ||
opts = prep_opts(Photo, opts) | ||
Photo.from_person_visible_by_user(self, person) | ||
.by_max_time(opts[:max_time]) | ||
.limit(opts[:limit]) | ||
end | ||
def photos_from(person, opts={}) | ||
opts = prep_opts(Photo, opts) | ||
Photo.from_person_visible_by_user(self, person) | ||
.by_max_time(opts[:max_time]) | ||
.limit(opts[:limit]) | ||
end | ||
|
||
protected | ||
|
||
# @return [Hash] | ||
def prep_opts(klass, opts) | ||
defaults = { | ||
order: "created_at DESC", | ||
limit: 15, | ||
hidden: false | ||
} | ||
defaults[:type] = Stream::Base::TYPES_OF_POST_IN_STREAM if klass == Post | ||
opts = defaults.merge(opts) | ||
opts.delete(:limit) if opts[:limit] == :all | ||
|
||
opts[:order_field] = opts[:order].split.first.to_sym | ||
opts[:order_with_table] = "#{klass.table_name}.#{opts[:order]}" | ||
|
||
opts[:max_time] = Time.zone.at(opts[:max_time]) if opts[:max_time].is_a?(Integer) | ||
opts[:max_time] ||= Time.zone.now + 1 | ||
opts | ||
protected | ||
|
||
# @return [Hash] | ||
def prep_opts(klass, opts) | ||
defaults = { | ||
order: "created_at DESC", | ||
limit: 15, | ||
hidden: false | ||
} | ||
defaults[:type] = Stream::Base::TYPES_OF_POST_IN_STREAM if klass == Post | ||
opts = defaults.merge(opts) | ||
opts.delete(:limit) if opts[:limit] == :all | ||
|
||
opts[:order_field] = opts[:order].split.first.to_sym | ||
opts[:order_with_table] = "#{klass.table_name}.#{opts[:order]}" | ||
|
||
opts[:max_time] = Time.zone.at(opts[:max_time]) if opts[:max_time].is_a?(Integer) | ||
opts[:max_time] ||= Time.zone.now + 1 | ||
opts | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,71 @@ | ||
# frozen_string_literal: true | ||
|
||
module User::SocialActions | ||
def comment!(target, text, opts={}) | ||
Comment::Generator.new(self, target, text).create!(opts).tap do | ||
update_or_create_participation!(target) | ||
class User | ||
module SocialActions | ||
def comment!(target, text, opts={}) | ||
Comment::Generator.new(self, target, text).create!(opts).tap do | ||
update_or_create_participation!(target) | ||
end | ||
end | ||
end | ||
|
||
def participate!(target, opts={}) | ||
Participation::Generator.new(self, target).create!(opts) | ||
end | ||
def participate!(target, opts={}) | ||
Participation::Generator.new(self, target).create!(opts) | ||
end | ||
|
||
def like!(target, opts={}) | ||
Like::Generator.new(self, target).create!(opts).tap do | ||
update_or_create_participation!(target) | ||
def like!(target, opts={}) | ||
Like::Generator.new(self, target).create!(opts).tap do | ||
update_or_create_participation!(target) | ||
end | ||
end | ||
end | ||
|
||
def like_comment!(target, opts={}) | ||
Like::Generator.new(self, target).create!(opts) | ||
end | ||
def like_comment!(target, opts={}) | ||
Like::Generator.new(self, target).create!(opts) | ||
end | ||
|
||
def participate_in_poll!(target, answer, opts={}) | ||
PollParticipation::Generator.new(self, target, answer).create!(opts).tap do | ||
update_or_create_participation!(target) | ||
def participate_in_poll!(target, answer, opts={}) | ||
PollParticipation::Generator.new(self, target, answer).create!(opts).tap do | ||
update_or_create_participation!(target) | ||
end | ||
end | ||
end | ||
|
||
def reshare!(target, opts={}) | ||
raise I18n.t("reshares.create.error") if target.author.guid == guid | ||
def reshare!(target, opts={}) | ||
raise I18n.t("reshares.create.error") if target.author.guid == guid | ||
|
||
build_post(:reshare, root_guid: target.guid).tap do |reshare| | ||
reshare.text = opts[:text] | ||
reshare.save! | ||
update_or_create_participation!(target) | ||
Diaspora::Federation::Dispatcher.defer_dispatch(self, reshare) | ||
build_post(:reshare, root_guid: target.guid).tap do |reshare| | ||
reshare.text = opts[:text] | ||
reshare.save! | ||
update_or_create_participation!(target) | ||
Diaspora::Federation::Dispatcher.defer_dispatch(self, reshare) | ||
end | ||
end | ||
end | ||
|
||
def build_conversation(opts={}) | ||
Conversation.new do |c| | ||
c.author = person | ||
c.subject = opts[:subject] | ||
c.participant_ids = [*opts[:participant_ids]] | [person_id] | ||
c.messages_attributes = [ | ||
{author: person, text: opts[:message][:text]} | ||
] | ||
def build_conversation(opts={}) | ||
Conversation.new do |c| | ||
c.author = person | ||
c.subject = opts[:subject] | ||
c.participant_ids = [*opts[:participant_ids]] | [person_id] | ||
c.messages_attributes = [ | ||
{author: person, text: opts[:message][:text]} | ||
] | ||
end | ||
end | ||
end | ||
|
||
def build_message(conversation, opts={}) | ||
conversation.messages.build( | ||
text: opts[:text], | ||
author: person | ||
) | ||
end | ||
def build_message(conversation, opts={}) | ||
conversation.messages.build( | ||
text: opts[:text], | ||
author: person | ||
) | ||
end | ||
|
||
def update_or_create_participation!(target) | ||
return if target.author == person | ||
def update_or_create_participation!(target) | ||
return if target.author == person | ||
|
||
participation = participations.find_by(target_id: target) | ||
if participation.present? | ||
participation.update!(count: participation.count.next) | ||
else | ||
participate!(target) | ||
participation = participations.find_by(target_id: target) | ||
if participation.present? | ||
participation.update!(count: participation.count.next) | ||
else | ||
participate!(target) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.