diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index eba04e66c..a6f79ca28 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -136,11 +136,14 @@ class AspectsController < ApplicationController private def hashes_for_posts posts - comment_hash = Comment.hash_from_post_ids posts.map{|p| p.id} + post_ids = posts.map{|p| p.id} + comment_hash = Comment.hash_from_post_ids post_ids person_hash = Person.from_post_comment_hash comment_hash + photo_hash = Photo.hash_from_post_ids post_ids posts.map do |post| {:post => post, + :photos => photo_hash[post.id], :person => post.person, :comments => comment_hash[post.id].map do |comment| {:comment => comment, diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index f024e791c..db15835f2 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -102,12 +102,15 @@ class PeopleController < ApplicationController private def hashes_for_posts posts - comment_hash = Comment.hash_from_post_ids posts.map{|p| p.id} + post_ids = posts.map{|p| p.id} + comment_hash = Comment.hash_from_post_ids post_ids person_hash = Person.from_post_comment_hash comment_hash + photo_hash = Photo.hash_from_post_ids post_ids posts.map do |post| {:post => post, :person => @person, + :photos => photo_hash[post.id], :comments => comment_hash[post.id].map do |comment| {:comment => comment, :person => person_hash[comment.person_id], diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index eeffa1785..fe4db7255 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -39,6 +39,7 @@ class StatusMessagesController < ApplicationController :locals => { :post => @status_message, :person => @status_message.person, + :photos => @status_message.photos, :comments => [], :aspects => current_user.aspects, :current_user => current_user diff --git a/app/helpers/sockets_helper.rb b/app/helpers/sockets_helper.rb index 44481788c..4f6bfaef6 100644 --- a/app/helpers/sockets_helper.rb +++ b/app/helpers/sockets_helper.rb @@ -12,9 +12,10 @@ module SocketsHelper def action_hash(uid, object, opts={}) begin user = User.find_by_id uid - if object.is_a? Post + if object.is_a? StatusMessage post_hash = {:post => object, :person => object.person, + :photos => object.photos, :comments => object.comments.map{|c| {:comment => c, :person => c.person diff --git a/app/models/photo.rb b/app/models/photo.rb index 46f6286ec..e9b804544 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -102,5 +102,20 @@ class Photo < Post } end + def self.hash_from_post_ids post_ids + hash = {} + photos = self.on_statuses(post_ids) + post_ids.each do |id| + hash[id] = [] + end + photos.each do |photo| + hash[photo.status_message_id] << photo + end + hash.each_value {|photos| photos.sort!{|p1, p2| p1.created_at <=> p2.created_at }} + hash + end + scope :on_statuses, lambda { |post_ids| + where(:status_message_id.in => post_ids) + } end diff --git a/app/views/shared/_stream_element.html.haml b/app/views/shared/_stream_element.html.haml index 376fca4d7..ea9097dc5 100644 --- a/app/views/shared/_stream_element.html.haml +++ b/app/views/shared/_stream_element.html.haml @@ -25,7 +25,7 @@ = render 'shared/reshare', :current_user => current_user, :post => post if post.is_a? StatusMessage = link_to t('delete'), status_message_path(post), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete" - = render 'status_messages/status_message', :post => post + = render 'status_messages/status_message', :post => post, :photos => post.photos .info %span.time= link_to(how_long_ago(post), status_message_path(post)) diff --git a/app/views/status_messages/_status_message.haml b/app/views/status_messages/_status_message.haml index 847f6ae4e..609916769 100644 --- a/app/views/status_messages/_status_message.haml +++ b/app/views/status_messages/_status_message.haml @@ -5,8 +5,8 @@ %p = markdownify(post.message, :youtube_maps => post[:youtube_titles]) -- if post.photos.count > 0 +- if photos.count > 0 .photo_attachments - - for photo in post.photos + - for photo in photos = link_to (image_tag photo.url(:thumb_medium)), photo_path(photo)