diff --git a/app/controllers/activity_streams/photos_controller.rb b/app/controllers/activity_streams/photos_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..c17cea042e14282667ef8d9aff7ab681bc4f2428 --- /dev/null +++ b/app/controllers/activity_streams/photos_controller.rb @@ -0,0 +1,26 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +class ActivityStreams::PhotosController < ApplicationController + before_filter :authenticate_user! + before_filter :redirect_unless_admin + skip_before_filter :verify_authenticity_token + + respond_to :json + + def create + @photo = ActivityStreams::Photo.from_activity(params[:activity]) + @photo.author = current_user.person + @photo.public = true + + if @photo.save + Rails.logger.info("event=create type=activitystreams_photo") + + current_user.add_to_streams(@photo, current_user.aspects) + current_user.dispatch_post(@photo, :url => post_url(@photo)) + + render :nothing => true, :status => 201 + end + end +end diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index a66a4b7defcfe3c1aa1c8a9f8b51838eba1fa909..8b0341f0c183fa0f8c774b5032d2169ab0e01207 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -31,7 +31,7 @@ class AspectsController < ApplicationController @aspect_ids = @aspects.map { |a| a.id } posts = current_user.visible_posts(:by_members_of => @aspect_ids, - :type => ['StatusMessage','Bookmark'], + :type => ['StatusMessage','ActivityStreams::Photo'], :order => session[:sort_order] + ' DESC', :max_time => params[:max_time].to_i ).includes(:comments, :mentions, :likes, :dislikes) diff --git a/app/controllers/bookmarks_controller.rb b/app/controllers/bookmarks_controller.rb deleted file mode 100644 index f3e1826cb597c48bc00b0a1eaaaa800a1b6d30b6..0000000000000000000000000000000000000000 --- a/app/controllers/bookmarks_controller.rb +++ /dev/null @@ -1,56 +0,0 @@ -# Copyright (c) 2010, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -class BookmarksController < ApplicationController - before_filter :authenticate_user! - skip_before_filter :verify_authenticity_token - - respond_to :json - - def create - @bookmark = Bookmark.from_activity(params[:activity]) - @bookmark.author = current_user.person - @bookmark.public = true - - if @bookmark.save - Rails.logger.info("event=create type=bookmark") - - current_user.add_to_streams(@bookmark, current_user.aspects) - current_user.dispatch_post(@bookmark, :url => post_url(@bookmark)) - - render :nothing => true, :status => 201 - end - end - -=begin - def destroy - if @bookmark = current_user.posts.where(:id => params[:id]).first - current_user.retract(@bookmark) - else - Rails.logger.info "event=post_destroy status=failure user=#{current_user.diaspora_handle} reason='User does not own post'" - render :nothing => true, :status => 404 - end - end - - def show - @status_message = current_user.find_visible_post_by_id params[:id] - if @status_message - @object_aspect_ids = @status_message.aspects.map{|a| a.id} - - # mark corresponding notification as read - if notification = Notification.where(:recipient_id => current_user.id, :target_id => @status_message.id).first - notification.unread = false - notification.save - end - - respond_with @status_message - else - Rails.logger.info(:event => :link_to_nonexistent_post, :ref => request.env['HTTP_REFERER'], :user_id => current_user.id, :post_id => params[:id]) - flash[:error] = I18n.t('status_messages.show.not_found') - redirect_to :back - end - end -=end - -end diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 78711df0bb16a19e588cb2838414b90f3f84d4f3..45779f3c33e1b99549bf74c6cee31b6ca906fb60 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -86,10 +86,10 @@ class PeopleController < ApplicationController else @commenting_disabled = false end - @posts = current_user.posts_from(@person).where(:type => ["StatusMessage", "Bookmark"]).includes(:comments).limit(15).where(StatusMessage.arel_table[:created_at].lt(max_time)) + @posts = current_user.posts_from(@person).where(:type => ["StatusMessage", "ActivityStreams::Photo"]).includes(:comments).limit(15).where(StatusMessage.arel_table[:created_at].lt(max_time)) else @commenting_disabled = true - @posts = @person.posts.where(:type => ["StatusMessage", "Bookmark"], :public => true).includes(:comments).limit(15).where(StatusMessage.arel_table[:created_at].lt(max_time)).order('posts.created_at DESC') + @posts = @person.posts.where(:type => ["StatusMessage", "ActivityStreams::Photo"], :public => true).includes(:comments).limit(15).where(StatusMessage.arel_table[:created_at].lt(max_time)).order('posts.created_at DESC') end @posts = PostsFake.new(@posts) diff --git a/app/models/bookmark.rb b/app/models/activity_streams/photo.rb similarity index 60% rename from app/models/bookmark.rb rename to app/models/activity_streams/photo.rb index 0a60524d6fd0fe4194c2eea914d73f8cfed8b9d9..ace74a18c565c89284d76faa6b33e255bd0b724c 100644 --- a/app/models/bookmark.rb +++ b/app/models/activity_streams/photo.rb @@ -2,11 +2,13 @@ # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. -class Bookmark < Post +class ActivityStreams::Photo < Post include Diaspora::Socketable - validates_presence_of :target_url - + validates_presence_of :image_url, + :object_url, + :provider_display_name, + :actor_url def socket_to_user(user_or_id, opts={}) #adds aspect_ids to opts if they are not there unless opts[:aspect_ids] @@ -21,10 +23,13 @@ class Bookmark < Post def self.from_activity(json) self.new( - :image_url => json["target"]["image"]["url"], - :image_height => json["target"]["image"]["height"], - :image_width => json["target"]["image"]["width"], - :target_url => json["target"]["url"] + :image_url => json["object"]["image"]["url"], + :image_height => json["object"]["image"]["height"], + :image_width => json["object"]["image"]["width"], + :object_url => json["object"]["url"], + + :provider_display_name => json["provider"]["displayName"], + :actor_url => json["actor"]["url"] ) end end diff --git a/app/views/shared/_stream_element.html.haml b/app/views/shared/_stream_element.html.haml index d1a5769470778ffa36c0d4512ebd7aa4299da8f0..8fb22f7ba71681df791dac551237e7a949166384 100644 --- a/app/views/shared/_stream_element.html.haml +++ b/app/views/shared/_stream_element.html.haml @@ -23,7 +23,7 @@ = person_link(post.author, :class => 'author') %time.time.timeago{:datetime => post.created_at, :integer => time_for_sort(post).to_i} - - if post.model.instance_of?(Bookmark) + - if post.model.instance_of?(ActivityStreams::Photo) = image_tag post.image_url - else = render 'status_messages/status_message', :post => post, :photos => post.photos diff --git a/app/views/shared/_stream_element.mobile.haml b/app/views/shared/_stream_element.mobile.haml index 82a34279042bfa4930200df65fdbd9344bb9ede5..d711643cfb2daf0e3a51910db416f3666a36c8dd 100644 --- a/app/views/shared/_stream_element.mobile.haml +++ b/app/views/shared/_stream_element.mobile.haml @@ -9,7 +9,10 @@ .from = person_link(post.author) - = render 'status_messages/status_message', :post => post, :photos => post.photos + - if post.model.instance_of?(ActivityStreams::Photo) + = image_tag post.image_url + - else + = render 'status_messages/status_message', :post => post, :photos => post.photos .info %span.time{:integer => post.created_at.to_i} diff --git a/config/routes.rb b/config/routes.rb index dcd1f9fe6f9baa63775c587f3061285d6a56f3ef..9951299c9f4578d438e32ba3b7ba7d8afa7c6028 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -63,7 +63,10 @@ Diaspora::Application.routes.draw do # generating a new user token (for devise) match 'users/generate_new_token' => 'users#generate_new_token' - resources :bookmarks, :only => :create + # ActivityStreams routes + scope "/activity_streams", :module => "activity_streams" do + resources :photos, :controller => "photos", :only => :create, :as => "as_photos" + end get 'login' => redirect('/users/sign_in') diff --git a/db/migrate/20110518222303_add_column_for_activity_streams_photo.rb b/db/migrate/20110518222303_add_column_for_activity_streams_photo.rb new file mode 100644 index 0000000000000000000000000000000000000000..0927da02e81dd3d633962065707ce8a00c043e44 --- /dev/null +++ b/db/migrate/20110518222303_add_column_for_activity_streams_photo.rb @@ -0,0 +1,21 @@ +class AddColumnForActivityStreamsPhoto < ActiveRecord::Migration + def self.up + add_column(:posts, :object_url, :string) + add_column(:posts, :image_url, :string) + add_column(:posts, :image_height, :integer) + add_column(:posts, :image_width, :integer) + + add_column(:posts, :provider_display_name, :string) + add_column(:posts, :actor_url, :string) + end + + def self.down + remove_column(:posts, :actor_url) + remove_column(:posts, :provider_display_name) + + remove_column(:posts, :image_width) + remove_column(:posts, :image_height) + remove_column(:posts, :image_url) + remove_column(:posts, :object_url) + end +end diff --git a/db/migrate/20110518222303_add_column_for_bookmark.rb b/db/migrate/20110518222303_add_column_for_bookmark.rb deleted file mode 100644 index 8f8670be70403c734e7b38108772f38fc772b0d0..0000000000000000000000000000000000000000 --- a/db/migrate/20110518222303_add_column_for_bookmark.rb +++ /dev/null @@ -1,15 +0,0 @@ -class AddColumnForBookmark < ActiveRecord::Migration - def self.up - add_column(:posts, :target_url, :string) - add_column(:posts, :image_url, :string) - add_column(:posts, :image_height, :integer) - add_column(:posts, :image_width, :integer) - end - - def self.down - remove_column(:posts, :image_width) - remove_column(:posts, :image_height) - remove_column(:posts, :image_url) - remove_column(:posts, :target_url) - end -end diff --git a/db/schema.rb b/db/schema.rb index 136864edd1427604089f8d8e3d59f30d5b096c76..4237ec91db1a8a76f77278146e57e2ec3388bffe 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -225,12 +225,12 @@ ActiveRecord::Schema.define(:version => 20110518222303) do add_index "post_visibilities", ["post_id"], :name => "index_post_visibilities_on_post_id" create_table "posts", :force => true do |t| - t.integer "author_id", :null => false - t.boolean "public", :default => false, :null => false + t.integer "author_id", :null => false + t.boolean "public", :default => false, :null => false t.string "diaspora_handle" - t.string "guid", :null => false - t.boolean "pending", :default => false, :null => false - t.string "type", :limit => 40, :null => false + t.string "guid", :null => false + t.boolean "pending", :default => false, :null => false + t.string "type", :limit => 40, :null => false t.text "text" t.integer "status_message_id" t.text "remote_photo_path" @@ -242,10 +242,12 @@ ActiveRecord::Schema.define(:version => 20110518222303) do t.datetime "updated_at" t.string "mongo_id" t.string "unprocessed_image" - t.string "target_url" + t.string "object_url" t.string "image_url" t.integer "image_height" t.integer "image_width" + t.string "provider_display_name" + t.string "actor_url" end add_index "posts", ["author_id"], :name => "index_posts_on_person_id" diff --git a/spec/models/activity_streams/photo_spec.rb b/spec/models/activity_streams/photo_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..4081676ec3b8380b4a360a4a40dc18ba0c324862 --- /dev/null +++ b/spec/models/activity_streams/photo_spec.rb @@ -0,0 +1,28 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +require 'spec_helper' + +describe ActivityStreams::Photo do + describe '.from_activity' do + before do + @json = JSON.parse <<JSON + {"activity":{"actor":{"url":"http://cubbi.es/daniel","displayName":"daniel","objectType":"person"},"published":"2011-05-19T18:12:23Z","verb":"save","object":{"objectType":"photo","url":"http://i658.photobucket.com/albums/uu308/R3b3lAp3/Swagger_dog.jpg","image":{"url":"http://i658.photobucket.com/albums/uu308/R3b3lAp3/Swagger_dog.jpg","width":637,"height":469}},"provider":{"url":"http://cubbi.es/","displayName":"Cubbi.es"}}} +JSON + @json = @json["activity"] + end + it 'marshals into an object' do + photo = ActivityStreams::Photo.from_activity(@json) + + photo.image_url.should == @json["object"]["image"]["url"] + photo.image_height.should == @json["object"]["image"]["height"] + photo.image_width.should == @json["object"]["image"]["width"] + photo.object_url.should == @json["object"]["url"] + + photo.provider_display_name.should == @json["provider"]["displayName"] + photo.actor_url.should == @json["actor"]["url"] + end + + end +end diff --git a/spec/models/bookmark_spec.rb b/spec/models/bookmark_spec.rb deleted file mode 100644 index eb938773c0d2e15ef1bf4671a0859d4d918dec61..0000000000000000000000000000000000000000 --- a/spec/models/bookmark_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright (c) 2010, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -require 'spec_helper' - -describe Bookmark do - describe '.from_activity' do - before do - @json = { - "verb"=>"save", - "target"=> { - "url"=>"http://abcnews.go.com/US/wireStory?id=13630884", - "objectType"=>"photo", - "image"=> { - "url"=> "http://a.abcnews.com/images/Entertainment/abc_ann_wtb_blake_leo_110518_wl.jpg", - "height"=>"112", - "width"=>"200" - } - }, - "object"=> { - "url"=>"http://cubbi.es/daniel", - "objectType"=>"bookmark" - } - } - end - it 'marshals into a bookmark' do - bookmark = Bookmark.from_activity(@json) - bookmark.image_url.should == @json["target"]["image"]["url"] - bookmark.image_height.should == @json["target"]["image"]["height"].to_i - bookmark.image_width.should == @json["target"]["image"]["width"].to_i - bookmark.target_url.should == @json["target"]["url"] - end - - end -end