diff options
author | Raphael Sofaer <raphael@joindiaspora.com> | 2011-07-23 03:00:19 +0400 |
---|---|---|
committer | Raphael Sofaer <raphael@joindiaspora.com> | 2011-07-23 03:00:19 +0400 |
commit | 78bced56bb4874796b29b85b617a4b20f7ea9368 (patch) | |
tree | 4b47af0b4a4fd94e62b702dd5de0fa014b24761b /app | |
parent | 5a12636967703521025625d27f4a1b1f2182bcf4 (diff) |
Reshares and reshare retractions are green.
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/reshares_controller.rb | 4 | ||||
-rw-r--r-- | app/models/post.rb | 2 | ||||
-rw-r--r-- | app/models/reshare.rb | 40 | ||||
-rw-r--r-- | app/models/signed_retraction.rb | 8 | ||||
-rw-r--r-- | app/views/reshares/create.js.erb | 2 | ||||
-rw-r--r-- | app/views/shared/_stream_element.html.haml | 2 |
6 files changed, 26 insertions, 32 deletions
diff --git a/app/controllers/reshares_controller.rb b/app/controllers/reshares_controller.rb index 9520715c7..d1511f634 100644 --- a/app/controllers/reshares_controller.rb +++ b/app/controllers/reshares_controller.rb @@ -3,9 +3,9 @@ class ResharesController < ApplicationController respond_to :js def create - @reshare = current_user.build_post(:reshare, :root_id => params[:root_id]) + @reshare = current_user.build_post(:reshare, :root_guid => params[:root_guid]) if @reshare.save! - current_user.add_to_streams(@reshare, current_user.aspects) + current_user.add_to_streams(@reshare, current_user.aspects) current_user.dispatch_post(@reshare, :url => post_url(@reshare), :additional_subscribers => @reshare.root.author) end diff --git a/app/models/post.rb b/app/models/post.rb index 01da0e94b..eb7dff48a 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -24,7 +24,7 @@ class Post < ActiveRecord::Base has_many :contacts, :through => :post_visibilities has_many :mentions, :dependent => :destroy - has_many :reshares, :class_name => "Reshare", :foreign_key => :root_id + has_many :reshares, :class_name => "Reshare", :foreign_key => :root_guid, :primary_key => :guid has_many :resharers, :class_name => 'Person', :through => :reshares, :source => :author belongs_to :author, :class_name => 'Person' diff --git a/app/models/reshare.rb b/app/models/reshare.rb index cb1cbad64..5040b85be 100644 --- a/app/models/reshare.rb +++ b/app/models/reshare.rb @@ -1,8 +1,8 @@ class Reshare < Post - belongs_to :root, :class_name => 'Post' + belongs_to :root, :class_name => 'Post', :foreign_key => :root_guid, :primary_key => :guid validate :root_must_be_public - attr_accessible :root_id, :public + attr_accessible :root_guid, :public validates_presence_of :root, :on => :create xml_attr :root_diaspora_id @@ -12,25 +12,21 @@ class Reshare < Post self.public = true end - def root_guid - self.root.guid - end - def root_diaspora_id self.root.author.diaspora_handle end - def receive(user, person) + def receive(recipient, sender) local_reshare = Reshare.where(:guid => self.guid).first - if local_reshare && local_reshare.root.author_id == user.person.id + if local_reshare && local_reshare.root.author_id == recipient.person.id local_reshare.root.reshares << local_reshare - if user.contact_for(person) - local_reshare.receive(user, person) + if recipient.contact_for(sender) + local_reshare.receive(recipient, sender) end else - super(user, person) + super(recipient, sender) end end @@ -38,23 +34,19 @@ class Reshare < Post def after_parse root_author = Webfinger.new(@root_diaspora_id).fetch - root_author.save! - - if local_post = Post.where(:guid => @root_guid).select('id').first - self.root_id = local_post.id - return - else - fetched_post = self.class.fetch_post(root_author, @root_guid) + root_author.save! unless root_author.persisted? - if root_author.diaspora_handle != fetched_post.diaspora_handle - raise "Diaspora ID (#{fetched_post.diaspora_handle}) in the root does not match the Diaspora ID (#{root_author.diaspora_handle}) specified in the reshare!" - end + return if Post.exists?(:guid => self.root_guid) - fetched_post.author_id = root_author.id - fetched_post.save! + fetched_post = self.class.fetch_post(root_author, self.root_guid) - self.root_id = fetched_post.id + if root_author.diaspora_handle != fetched_post.diaspora_handle + raise "Diaspora ID (#{fetched_post.diaspora_handle}) in the root does not match the Diaspora ID (#{root_author.diaspora_handle}) specified in the reshare!" end + + #Todo, this is a bug if it is necessary. The marshalling process should set the author. + fetched_post.author_id = root_author.id + fetched_post.save! end # Fetch a remote public post, used for receiving reshares of unknown posts diff --git a/app/models/signed_retraction.rb b/app/models/signed_retraction.rb index a499c7d87..ea152ab76 100644 --- a/app/models/signed_retraction.rb +++ b/app/models/signed_retraction.rb @@ -64,13 +64,15 @@ class SignedRetraction def perform receiving_user Rails.logger.debug "Performing retraction for #{target_guid}" - if reshare = Reshare.where(:author_id => receiving_user.person.id, :root_id => target.id).first + if reshare = Reshare.where(:author_id => receiving_user.person.id, :root_guid => target_guid).first onward_retraction = self.dup onward_retraction.sender = receiving_user.person Postzord::Dispatch.new(receiving_user, onward_retraction).post end - self.target.unsocket_from_user receiving_user if target.respond_to? :unsocket_from_user - self.target.destroy + if target + self.target.unsocket_from_user receiving_user if target.respond_to? :unsocket_from_user + self.target.destroy + end Rails.logger.info(:event => :retraction, :status => :complete, :target_type => self.target_type, :guid => self.target_guid) end diff --git a/app/views/reshares/create.js.erb b/app/views/reshares/create.js.erb index f25d9629f..3c179af45 100644 --- a/app/views/reshares/create.js.erb +++ b/app/views/reshares/create.js.erb @@ -1 +1 @@ -$('.stream_element[data-guid=<%=params[:root_id]%>]').addClass('reshared'); +$('.stream_element[data-guid=<%=params[:root_guid]%>]').addClass('reshared'); diff --git a/app/views/shared/_stream_element.html.haml b/app/views/shared/_stream_element.html.haml index 8c63d93b2..bb5de8f9c 100644 --- a/app/views/shared/_stream_element.html.haml +++ b/app/views/shared/_stream_element.html.haml @@ -61,7 +61,7 @@ - if (post.author_id != current_user.person.id) && (post.public?) && !reshare?(post) · %span.reshare_action - = link_to "#{(post.reshares.size unless post.reshares.size == 0)} Reshare", reshares_path(:root_id => post.id), :method => :post, :remote => true, :confirm => "Reshare: #{post.author.name} - #{post.text}?" + = link_to "#{(post.reshares.size unless post.reshares.size == 0)} Reshare", reshares_path(:root_guid => post.guid), :method => :post, :remote => true, :confirm => "Reshare: #{post.author.name} - #{post.text}?" · = link_to t('comments.new_comment.comment'), '#', :class => 'focus_comment_textarea' |