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

View file

@ -76,7 +76,7 @@ class StatusMessagesController < ApplicationController
end end
else else
if !photos.empty? if !photos.empty?
photos.update_all(:status_message_id => nil) photos.update_all(:status_message_guid => nil)
end end
respond_to do |format| respond_to do |format|
format.js { render :json =>{:errors => @status_message.errors.full_messages}, :status => 422 } 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 :text
xml_attr :status_message_guid 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 attr_accessible :text, :pending
validate :ownership_of_status_message validate :ownership_of_status_message
@ -22,8 +22,8 @@ class Photo < Post
after_create :queue_processing_job after_create :queue_processing_job
def ownership_of_status_message def ownership_of_status_message
message = StatusMessage.find_by_id(self.status_message_id) message = StatusMessage.find_by_guid(self.status_message_guid)
if status_message_id && message if self.status_message_guid && message
self.diaspora_handle == message.diaspora_handle self.diaspora_handle == message.diaspora_handle
else else
true true
@ -61,18 +61,6 @@ class Photo < Post
self.remote_photo_name = remote_path.slice(name_start + 1, remote_path.length) self.remote_photo_name = remote_path.slice(name_start + 1, remote_path.length)
end 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) def url(name = nil)
if remote_photo_path if remote_photo_path
name = name.to_s + '_' if name name = name.to_s + '_' if name
@ -121,7 +109,7 @@ class Photo < Post
} }
end end
scope :on_statuses, lambda { |post_ids| scope :on_statuses, lambda { |post_guids|
where(:status_message_id => post_ids) where(:status_message_guid => post_guids)
} }
end end

View file

@ -17,7 +17,7 @@ class StatusMessage < Post
xml_name :status_message xml_name :status_message
xml_attr :raw_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? validate :message_or_photos_present?
attr_accessible :text attr_accessible :text

View file

@ -17,5 +17,5 @@
#thumbnails.span-15.last #thumbnails.span-15.last
- for photo in photos - 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 %br
.span-9.last .span-9.last
- if @post.status_message_id - if @post.status_message_guid
#original_post_info #original_post_info
%h4{:style=>"position:relative;"} %h4{:style=>"position:relative;"}
= t('photos.show.original_post') = t('photos.show.original_post')