Fixed ruby 1.9.2 module issue
This commit is contained in:
parent
0be85dff2d
commit
6e4b4bc81b
1 changed files with 90 additions and 90 deletions
|
|
@ -29,104 +29,104 @@ module Diaspora
|
||||||
xml_attr :public
|
xml_attr :public
|
||||||
xml_attr :created_at
|
xml_attr :created_at
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def diaspora_handle
|
def diaspora_handle
|
||||||
read_attribute(:diaspora_handle) || self.author.diaspora_handle
|
read_attribute(:diaspora_handle) || self.author.diaspora_handle
|
||||||
|
end
|
||||||
|
|
||||||
|
def diaspora_handle= nd
|
||||||
|
self.author = Person.where(:diaspora_handle => nd).first
|
||||||
|
write_attribute(:diaspora_handle, nd)
|
||||||
|
end
|
||||||
|
|
||||||
|
def user_refs
|
||||||
|
if AspectVisibility.exists?(:shareable_id => self.id, :shareable_type => self.class.base_class.to_s)
|
||||||
|
self.share_visibilities.count + 1
|
||||||
|
else
|
||||||
|
self.share_visibilities.count
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def diaspora_handle= nd
|
# @param [User] user The user that is receiving this shareable.
|
||||||
self.author = Person.where(:diaspora_handle => nd).first
|
# @param [Person] person The person who dispatched this shareable to the
|
||||||
write_attribute(:diaspora_handle, nd)
|
# @return [void]
|
||||||
end
|
def receive(user, person)
|
||||||
|
#exists locally, but you dont know about it
|
||||||
|
#does not exsist locally, and you dont know about it
|
||||||
|
#exists_locally?
|
||||||
|
#you know about it, and it is mutable
|
||||||
|
#you know about it, and it is not mutable
|
||||||
|
self.class.transaction do
|
||||||
|
local_shareable = persisted_shareable
|
||||||
|
|
||||||
|
if local_shareable && verify_persisted_shareable(local_shareable)
|
||||||
|
self.receive_persisted(user, person, local_shareable)
|
||||||
|
|
||||||
|
elsif !local_shareable
|
||||||
|
self.receive_non_persisted(user, person)
|
||||||
|
|
||||||
def user_refs
|
|
||||||
if AspectVisibility.exists?(:shareable_id => self.id, :shareable_type => self.class.base_class.to_s)
|
|
||||||
self.share_visibilities.count + 1
|
|
||||||
else
|
else
|
||||||
self.share_visibilities.count
|
Rails.logger.info("event=receive payload_type=#{self.class} update=true status=abort sender=#{self.diaspora_handle} reason='update not from shareable owner' existing_shareable=#{self.id}")
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# @param [User] user The user that is receiving this shareable.
|
|
||||||
# @param [Person] person The person who dispatched this shareable to the
|
|
||||||
# @return [void]
|
|
||||||
def receive(user, person)
|
|
||||||
#exists locally, but you dont know about it
|
|
||||||
#does not exsist locally, and you dont know about it
|
|
||||||
#exists_locally?
|
|
||||||
#you know about it, and it is mutable
|
|
||||||
#you know about it, and it is not mutable
|
|
||||||
self.class.transaction do
|
|
||||||
local_shareable = persisted_shareable
|
|
||||||
|
|
||||||
if local_shareable && verify_persisted_shareable(local_shareable)
|
|
||||||
self.receive_persisted(user, person, local_shareable)
|
|
||||||
|
|
||||||
elsif !local_shareable
|
|
||||||
self.receive_non_persisted(user, person)
|
|
||||||
|
|
||||||
else
|
|
||||||
Rails.logger.info("event=receive payload_type=#{self.class} update=true status=abort sender=#{self.diaspora_handle} reason='update not from shareable owner' existing_shareable=#{self.id}")
|
|
||||||
false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# The list of people that should receive this Shareable.
|
|
||||||
#
|
|
||||||
# @param [User] user The context, or dispatching user.
|
|
||||||
# @return [Array<Person>] The list of subscribers to this shareable
|
|
||||||
def subscribers(user)
|
|
||||||
if self.public?
|
|
||||||
user.contact_people
|
|
||||||
else
|
|
||||||
user.people_in_aspects(user.aspects_with_shareable(self.class, self.id))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
protected
|
|
||||||
|
|
||||||
# @return [Shareable,void]
|
|
||||||
def persisted_shareable
|
|
||||||
self.class.where(:guid => self.guid).first
|
|
||||||
end
|
|
||||||
|
|
||||||
# @return [Boolean]
|
|
||||||
def verify_persisted_shareable(persisted_shareable)
|
|
||||||
persisted_shareable.author_id == self.author_id
|
|
||||||
end
|
|
||||||
|
|
||||||
def receive_persisted(user, person, local_shareable)
|
|
||||||
known_shareable = user.find_visible_shareable_by_id(self.class.base_class, self.guid, :key => :guid)
|
|
||||||
if known_shareable
|
|
||||||
if known_shareable.mutable?
|
|
||||||
known_shareable.update_attributes(self.attributes)
|
|
||||||
true
|
|
||||||
else
|
|
||||||
Rails.logger.info("event=receive payload_type=#{self.class} update=true status=abort sender=#{self.diaspora_handle} reason=immutable") #existing_shareable=#{known_shareable.id}")
|
|
||||||
false
|
|
||||||
end
|
|
||||||
else
|
|
||||||
user.contact_for(person).receive_shareable(local_shareable)
|
|
||||||
user.notify_if_mentioned(local_shareable)
|
|
||||||
Rails.logger.info("event=receive payload_type=#{self.class} update=true status=complete sender=#{self.diaspora_handle}") #existing_shareable=#{local_shareable.id}")
|
|
||||||
true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def receive_non_persisted(user, person)
|
|
||||||
if self.save
|
|
||||||
user.contact_for(person).receive_shareable(self)
|
|
||||||
user.notify_if_mentioned(self)
|
|
||||||
Rails.logger.info("event=receive payload_type=#{self.class} update=false status=complete sender=#{self.diaspora_handle}")
|
|
||||||
true
|
|
||||||
else
|
|
||||||
Rails.logger.info("event=receive payload_type=#{self.class} update=false status=abort sender=#{self.diaspora_handle} reason=#{self.errors.full_messages}")
|
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# The list of people that should receive this Shareable.
|
||||||
|
#
|
||||||
|
# @param [User] user The context, or dispatching user.
|
||||||
|
# @return [Array<Person>] The list of subscribers to this shareable
|
||||||
|
def subscribers(user)
|
||||||
|
if self.public?
|
||||||
|
user.contact_people
|
||||||
|
else
|
||||||
|
user.people_in_aspects(user.aspects_with_shareable(self.class, self.id))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
# @return [Shareable,void]
|
||||||
|
def persisted_shareable
|
||||||
|
self.class.where(:guid => self.guid).first
|
||||||
|
end
|
||||||
|
|
||||||
|
# @return [Boolean]
|
||||||
|
def verify_persisted_shareable(persisted_shareable)
|
||||||
|
persisted_shareable.author_id == self.author_id
|
||||||
|
end
|
||||||
|
|
||||||
|
def receive_persisted(user, person, local_shareable)
|
||||||
|
known_shareable = user.find_visible_shareable_by_id(self.class.base_class, self.guid, :key => :guid)
|
||||||
|
if known_shareable
|
||||||
|
if known_shareable.mutable?
|
||||||
|
known_shareable.update_attributes(self.attributes)
|
||||||
|
true
|
||||||
|
else
|
||||||
|
Rails.logger.info("event=receive payload_type=#{self.class} update=true status=abort sender=#{self.diaspora_handle} reason=immutable") #existing_shareable=#{known_shareable.id}")
|
||||||
|
false
|
||||||
|
end
|
||||||
|
else
|
||||||
|
user.contact_for(person).receive_shareable(local_shareable)
|
||||||
|
user.notify_if_mentioned(local_shareable)
|
||||||
|
Rails.logger.info("event=receive payload_type=#{self.class} update=true status=complete sender=#{self.diaspora_handle}") #existing_shareable=#{local_shareable.id}")
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def receive_non_persisted(user, person)
|
||||||
|
if self.save
|
||||||
|
user.contact_for(person).receive_shareable(self)
|
||||||
|
user.notify_if_mentioned(self)
|
||||||
|
Rails.logger.info("event=receive payload_type=#{self.class} update=false status=complete sender=#{self.diaspora_handle}")
|
||||||
|
true
|
||||||
|
else
|
||||||
|
Rails.logger.info("event=receive payload_type=#{self.class} update=false status=abort sender=#{self.diaspora_handle} reason=#{self.errors.full_messages}")
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue