Class: Photo

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Diaspora::Commentable, Diaspora::Federated::Shareable, Diaspora::Shareable
Defined in:
app/models/photo.rb

Overview

Copyright © 2009, Diaspora Inc. This file is

licensed under the Affero General Public License version 3 or later.  See
the COPYRIGHT file.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Diaspora::Shareable

included, #update_reshares_counter

Methods included from Diaspora::Commentable

included, #last_three_comments, #update_comments_counter

Methods included from Diaspora::Federated::Shareable

included

Class Method Details

.diaspora_initialize(params = {}) ⇒ Object


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/models/photo.rb', line 70

def self.diaspora_initialize(params = {})
  photo = self.new params.to_hash.slice(:text, :pending)
  photo.author = params[:author]
  photo.public = params[:public] if params[:public]
  photo.pending = params[:pending] if params[:pending]
  photo.diaspora_handle = photo.author.diaspora_handle

  photo.random_string = SecureRandom.hex(10)

  if params[:user_file]
    image_file = params.delete(:user_file)
    photo.unprocessed_image.store! image_file

  elsif params[:image_url]
    photo.remote_unprocessed_image_url = params[:image_url]
    photo.unprocessed_image.store!
  end

  photo.update_remote_path

  photo
end

Instance Method Details

#clear_empty_status_messageObject


53
54
55
56
57
58
59
# File 'app/models/photo.rb', line 53

def clear_empty_status_message
  if self.status_message && self.status_message.text_and_photos_blank?
    self.status_message.destroy
  else
    true
  end
end

#ensure_user_pictureObject


120
121
122
123
124
125
126
# File 'app/models/photo.rb', line 120

def ensure_user_picture
  profiles = Profile.where(:image_url => url(:thumb_large))
  profiles.each { |profile|
    profile.image_url = nil
    profile.save
  }
end

#mutable?Boolean


132
133
134
# File 'app/models/photo.rb', line 132

def mutable?
  true
end

#ownership_of_status_messageObject


61
62
63
64
65
66
67
68
# File 'app/models/photo.rb', line 61

def ownership_of_status_message
  message = StatusMessage.find_by_guid(self.status_message_guid)
  if self.status_message_guid && message
    self.diaspora_handle == message.diaspora_handle
  else
    true
  end
end

#processed?Boolean


93
94
95
# File 'app/models/photo.rb', line 93

def processed?
  processed_image.path.present?
end

#queue_processing_jobObject


128
129
130
# File 'app/models/photo.rb', line 128

def queue_processing_job
  Workers::ProcessPhoto.perform_async(self.id)
end

#update_remote_pathObject


97
98
99
100
101
102
103
104
105
106
107
# File 'app/models/photo.rb', line 97

def update_remote_path
  unless self.unprocessed_image.url.match(/^https?:\/\//)
    remote_path = "#{AppConfig.pod_uri.to_s.chomp("/")}#{self.unprocessed_image.url}"
  else
    remote_path = self.unprocessed_image.url
  end

  name_start = remote_path.rindex '/'
  self.remote_photo_path = "#{remote_path.slice(0, name_start)}/"
  self.remote_photo_name = remote_path.slice(name_start + 1, remote_path.length)
end

#url(name = nil) ⇒ Object


109
110
111
112
113
114
115
116
117
118
# File 'app/models/photo.rb', line 109

def url(name = nil)
  if remote_photo_path
    name = name.to_s + '_' if name
    remote_photo_path + name.to_s + remote_photo_name
  elsif processed?
    processed_image.url(name)
  else
    unprocessed_image.url(name)
  end
end