Newer
Older
class NotVisibleError < RuntimeError; end
class Message < ActiveRecord::Base
include ROXML
include Diaspora::Guid
include Diaspora::Webhooks
xml_attr :text
xml_attr :created_at
xml_reader :diaspora_handle
xml_reader :conversation_guid
belongs_to :author, :class_name => 'Person'
validates_presence_of :text
after_create do
#sign comment as commenter
self.author_signature = self.sign_with_key(self.author.owner.encryption_key) if self.author.owner
if !self.parent.blank? && self.author.owns?(self.parent)
#sign comment as post owner
self.parent_author_signature = self.sign_with_key( self.parent.author.owner.encryption_key) if self.parent.author.owner
end
self.save!
self
validate :participant_of_parent_conversation
def diaspora_handle
self.author.diaspora_handle
end
def diaspora_handle= nh
self.author = Webfinger.new(nh).fetch
end
def conversation_guid
self.conversation.guid
end
def conversation_guid= guid
if cnv = Conversation.find_by_guid(guid)
self.conversation_id = cnv.id
end
end
def parent
self.conversation
end
def parent= parent
self.conversation = parent
def after_receive(user, person)
if vis = ConversationVisibility.where(:conversation_id => self.conversation_id, :person_id => user.person.id).first
vis.unread += 1
vis.save
self
else
raise NotVisibleError.new("User #{user.id} with person #{user.person.id} is not allowed to see conversation #{conversation.id}!")
def notification_type(user, person)
zhitomirskiyi
a validé
Notifications::PrivateMessage unless user.person == person
private
def participant_of_parent_conversation
if self.parent && !self.parent.participants.include?(self.author)
errors[:base] << "Author is not participating in the conversation"
else
true
end
end