relayable.rb 1.05 KB
Newer Older
1 2 3 4 5
module Federated
  class Relayable < ActiveRecord::Base
    self.abstract_class = true

    #crazy ordering issues - DEATH TO ROXML
6
    include Diaspora::Federated::Base
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
    include Diaspora::Guid

    #seriously, don't try to move this shit around until you have killed ROXML
    xml_attr :target_type
    include Diaspora::Relayable

    xml_attr :diaspora_handle

    belongs_to :target, :polymorphic => true
    belongs_to :author, :class_name => 'Person'
    #end crazy ordering issues

    validates_uniqueness_of :target_id, :scope => [:target_type, :author_id]
    validates :parent, :presence => true #should be in relayable (pending on fixing Message)

    def diaspora_handle
      self.author.diaspora_handle
    end

    def diaspora_handle=(nh)
27
      self.author = Person.find_or_fetch_by_identifier(nh)
28 29 30 31 32 33 34 35 36 37 38 39 40
    end

    def parent_class
      self.target_type.constantize
    end

    def parent
      self.target
    end

    def parent= parent
      self.target = parent
    end
41 42

    def fetch_parent guid
43
      raise Diaspora::PostNotFetchable
44
    end
45
  end
46
end