Photo association on GUID 2/2: replace status_message_id with status_message_guid

This commit is contained in:
MrZYX 2011-05-27 18:32:54 +02:00
parent fba69bd8a5
commit e201340bb2
6 changed files with 11 additions and 23 deletions

View file

@ -125,7 +125,7 @@ class PhotosController < ApplicationController
format.json{ render :nothing => true, :status => 204 }
format.html do
flash[:notice] = I18n.t 'photos.destroy.notice'
if photo.status_message_id
if photo.status_message_guid
respond_with photo, :location => photo.status_message
else
respond_with photo, :location => person_photos_path(current_user.person)
@ -140,7 +140,7 @@ class PhotosController < ApplicationController
def show
@photo = current_user.find_visible_post_by_id(params[:id], :type => 'Photo')
if @photo
@parent = StatusMessage.where(:id => @photo.status_message_id).includes(:photos).first if @photo.status_message_id
@parent = StatusMessage.where(:guid => @photo.status_message_guid).includes(:photos).first if @photo.status_message_guid
#if photo is not an attachment, fetch comments for self
if @parent

View file

@ -76,7 +76,7 @@ class StatusMessagesController < ApplicationController
end
else
if !photos.empty?
photos.update_all(:status_message_id => nil)
photos.update_all(:status_message_guid => nil)
end
respond_to do |format|
format.js { render :json =>{:errors => @status_message.errors.full_messages}, :status => 422 }

View file

@ -13,7 +13,7 @@ class Photo < Post
xml_attr :text
xml_attr :status_message_guid
belongs_to :status_message
belongs_to :status_message, :foreign_key => :status_message_guid, :primary_key => :guid
attr_accessible :text, :pending
validate :ownership_of_status_message
@ -22,8 +22,8 @@ class Photo < Post
after_create :queue_processing_job
def ownership_of_status_message
message = StatusMessage.find_by_id(self.status_message_id)
if status_message_id && message
message = StatusMessage.find_by_guid(self.status_message_guid)
if self.status_message_guid && message
self.diaspora_handle == message.diaspora_handle
else
true
@ -61,18 +61,6 @@ class Photo < Post
self.remote_photo_name = remote_path.slice(name_start + 1, remote_path.length)
end
def status_message_guid
if self.status_message
self.status_message.guid
else
nil
end
end
def status_message_guid= new_sm_guid
self.status_message= StatusMessage.where(:guid => new_sm_guid).first
end
def url(name = nil)
if remote_photo_path
name = name.to_s + '_' if name
@ -121,7 +109,7 @@ class Photo < Post
}
end
scope :on_statuses, lambda { |post_ids|
where(:status_message_id => post_ids)
scope :on_statuses, lambda { |post_guids|
where(:status_message_guid => post_guids)
}
end

View file

@ -17,7 +17,7 @@ class StatusMessage < Post
xml_name :status_message
xml_attr :raw_message
has_many :photos, :dependent => :destroy
has_many :photos, :dependent => :destroy, :foreign_key => :status_message_guid, :primary_key => :guid
validate :message_or_photos_present?
attr_accessible :text

View file

@ -17,5 +17,5 @@
#thumbnails.span-15.last
- for photo in photos
= link_to (image_tag photo.url(:thumb_medium), "data-message-id" => photo.status_message_id ), photo_path(photo)
= link_to (image_tag photo.url(:thumb_medium), "data-message-guid" => photo.status_message_guid ), photo_path(photo)

View file

@ -20,7 +20,7 @@
%br
.span-9.last
- if @post.status_message_id
- if @post.status_message_guid
#original_post_info
%h4{:style=>"position:relative;"}
= t('photos.show.original_post')