From d7899d10e3a73f8ced4cbbd2319cbf44cb376274 Mon Sep 17 00:00:00 2001
From: danielgrippi <danielgrippi@gmail.com>
Date: Thu, 19 May 2011 15:17:16 -0700
Subject: [PATCH] Fix various links in to cubbi.es objects

---
 .../activity_streams/photos_controller.rb      | 18 ++++++++++++++++--
 app/helpers/application_helper.rb              | 10 ++++++++--
 app/helpers/stream_helper.rb                   |  8 --------
 app/views/shared/_stream_element.html.haml     |  2 +-
 app/views/shared/_stream_element.mobile.haml   |  7 ++++++-
 config/routes.rb                               |  4 ++--
 6 files changed, 33 insertions(+), 16 deletions(-)

diff --git a/app/controllers/activity_streams/photos_controller.rb b/app/controllers/activity_streams/photos_controller.rb
index c17cea042e..79dcd1774a 100644
--- a/app/controllers/activity_streams/photos_controller.rb
+++ b/app/controllers/activity_streams/photos_controller.rb
@@ -4,10 +4,11 @@
 
 class ActivityStreams::PhotosController < ApplicationController
   before_filter :authenticate_user!
-  before_filter :redirect_unless_admin
-  skip_before_filter :verify_authenticity_token
+  before_filter :redirect_unless_admin, :only => :create
+  skip_before_filter :verify_authenticity_token, :only => :create
 
   respond_to :json
+  respond_to :html, :only => [:show, :destroy]
 
   def create
     @photo = ActivityStreams::Photo.from_activity(params[:activity])
@@ -23,4 +24,17 @@ class ActivityStreams::PhotosController < ApplicationController
       render :nothing => true, :status => 201
     end
   end
+
+  def show
+    @photo = current_user.find_visible_post_by_id(params[:id])
+    respond_with @photo
+  end
+
+  def destroy
+    @photo = current_user.posts.where(:id => params[:id]).first
+    if @photo
+      current_user.retract(@photo)
+    end
+    respond_with @photo
+  end
 end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index a5da5dd7e4..e84951e37f 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -18,8 +18,14 @@ module ApplicationHelper
 
   def object_path(object, opts={})
     return "" if object.nil?
-    object = object.person if object.is_a? User
-    eval("#{object.class.name.underscore}_path(object, opts)")
+    object = object.person if object.instance_of? User
+    object = object.model if object.instance_of? PostsFake::Fake
+    if object.activity_streams?
+      class_name = object.class.name.underscore.split('/')
+      eval("#{class_name.first}_#{class_name.last}_path(object, opts)")
+    else
+      eval("#{object.class.name.underscore}_path(object, opts)")
+    end
   end
 
   def object_fields(object)
diff --git a/app/helpers/stream_helper.rb b/app/helpers/stream_helper.rb
index f51167ce80..3fe8aca2b7 100644
--- a/app/helpers/stream_helper.rb
+++ b/app/helpers/stream_helper.rb
@@ -20,12 +20,4 @@ module StreamHelper
       post.created_at
     end
   end
-
-  def show_link_for post
-    if post.activity_streams?
-      how_long_ago(post)
-    else
-      link_to(how_long_ago(post), status_message_path(post))
-    end
-  end
 end
diff --git a/app/views/shared/_stream_element.html.haml b/app/views/shared/_stream_element.html.haml
index 472a3d196a..4bf30f9f4a 100644
--- a/app/views/shared/_stream_element.html.haml
+++ b/app/views/shared/_stream_element.html.haml
@@ -38,7 +38,7 @@
             = aspect_badges(aspects_with_post(all_aspects, post), :link => true)
 
         %span.timeago
-          = show_link_for post
+          = link_to(how_long_ago(post), object_path(post))
 
         %span.via
           - if post.activity_streams?
diff --git a/app/views/shared/_stream_element.mobile.haml b/app/views/shared/_stream_element.mobile.haml
index eed5a67dcc..5a31e4f6e3 100644
--- a/app/views/shared/_stream_element.mobile.haml
+++ b/app/views/shared/_stream_element.mobile.haml
@@ -17,4 +17,9 @@
     .info
       %span.time{:integer => post.created_at.to_i}
         = t('ago', :time => time_ago_in_words(post.created_at))
-      = link_to "#{t('comments', :count => post.comments.length)} →", status_message_path(post), :class => 'comment_link right'
+
+      - if post.activity_streams?
+        = link_to "#{t('comments', :count => post.comments.length)} →", activity_streams_photo_path(post), :class => 'comment_link right'
+      - else
+        = link_to "#{t('comments', :count => post.comments.length)} →", status_message_path(post), :class => 'comment_link right'
+
diff --git a/config/routes.rb b/config/routes.rb
index e5363f0f7e..ed560372cf 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -63,8 +63,8 @@ Diaspora::Application.routes.draw do
   # generating a new user token (for devise)
 
   # ActivityStreams routes
-  scope "/activity_streams", :module => "activity_streams" do
-    resources :photos, :controller => "photos", :only => :create, :as => "as_photos"
+  scope "/activity_streams", :module => "activity_streams", :as => "activity_streams" do
+    resources :photos, :controller => "photos", :only => [:create, :show, :destroy]
   end
 
 
-- 
GitLab