Bookmark -> ActivitiyStreams::Photo
This commit is contained in:
parent
dd31f37fd0
commit
c8e31825c5
13 changed files with 107 additions and 126 deletions
26
app/controllers/activity_streams/photos_controller.rb
Normal file
26
app/controllers/activity_streams/photos_controller.rb
Normal file
|
|
@ -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
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
14
db/schema.rb
14
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"
|
||||
|
|
|
|||
28
spec/models/activity_streams/photo_spec.rb
Normal file
28
spec/models/activity_streams/photo_spec.rb
Normal file
|
|
@ -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
|
||||
|
|
@ -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
|
||||
Loading…
Reference in a new issue