Newer
Older
# licensed under the Affero General Public License version 3 or later. See
Daniel Vincent Grippi
a validé
class Post < ActiveRecord::Base
require File.join(Rails.root, 'lib/diaspora/web_socket')
include ROXML
xml_attr :diaspora_handle
xml_attr :public
xml_attr :created_at
has_many :comments, :order => 'created_at ASC'
has_many :likes, :conditions => '`likes`.`positive` = 1', :dependent => :delete_all
has_many :dislikes, :conditions => '`likes`.`positive` = 0', :class_name => 'Like', :dependent => :delete_all
has_many :aspect_visibilities
has_many :aspects, :through => :aspect_visibilities
has_many :contacts, :through => :post_visibilities
belongs_to :author, :class_name => 'Person'
if AspectVisibility.exists?(:post_id => self.id)
self.post_visibilities.count + 1
else
self.post_visibilities.count
end
def diaspora_handle= nd
self.author = Person.where(:diaspora_handle => nd).first
write_attribute(:diaspora_handle, nd)
end
def self.diaspora_initialize params
new_post.author = params[:author]
new_post.public = params[:public] if params[:public]
new_post.pending = params[:pending] if params[:pending]
new_post.diaspora_handle = new_post.author.diaspora_handle
danielgrippi
a validé
:id => self.guid,
maxwell
a validé
def mutable?
false
end
def subscribers(user)
user.people_in_aspects(user.aspects_with_post(self.id))
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
local_post = Post.where(:guid => self.guid).first
if local_post && local_post.author_id == self.author_id
known_post = user.raw_visible_posts.where(:guid => self.guid).first
else
Rails.logger.info("event=receive payload_type=#{self.class} update=true status=abort sender=#{self.diaspora_handle} reason=immutable existing_post=#{known_post.id}")
end
Rails.logger.info("event=receive payload_type=#{self.class} update=true status=complete sender=#{self.diaspora_handle} existing_post=#{local_post.id}")
Rails.logger.info("event=receive payload_type=#{self.class} update=false status=complete sender=#{self.diaspora_handle}")
return self
else
Rails.logger.info("event=receive payload_type=#{self.class} update=true status=abort sender=#{self.diaspora_handle} reason='update not from post owner' existing_post=#{self.id}")