Skip to content
Extraits de code Groupes Projets
Valider 9e1816dc rédigé par Dennis Collinson's avatar Dennis Collinson
Parcourir les fichiers

Participations are a federated, relayable model :)

parent 1c314c95
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
class FederatedRelayable < ActiveRecord::Base
self.abstract_class = true
#crazy ordering issues - DEATH TO ROXML
include ROXML
include Diaspora::Webhooks
include Diaspora::Guid
#seriously, don't try to move this shit around until you have killed ROXML
xml_attr :target_type
include Diaspora::Relayable
xml_attr :diaspora_handle
belongs_to :target, :polymorphic => true
belongs_to :author, :class_name => 'Person'
#end crazy ordering issues
validates_uniqueness_of :target_id, :scope => [:target_type, :author_id]
validates :parent, :presence => true #should be in relayable (pending on fixing Message)
def diaspora_handle
self.author.diaspora_handle
end
def diaspora_handle=(nh)
self.author = Webfinger.new(nh).fetch
end
def parent_class
self.target_type.constantize
end
def parent
self.target
end
def parent= parent
self.target = parent
end
end
\ No newline at end of file
......@@ -2,14 +2,16 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class Like < ActiveRecord::Base
include ROXML
class Like < FederatedRelayable
after_create do
self.parent.update_likes_counter
end
include Diaspora::Webhooks
include Diaspora::Guid
after_destroy do
self.parent.update_likes_counter
end
xml_attr :target_type
include Diaspora::Relayable
xml_attr :positive
# NOTE API V1 to be extracted
acts_as_api
......@@ -20,43 +22,6 @@ class Like < ActiveRecord::Base
t.add :created_at
end
xml_attr :positive
xml_attr :diaspora_handle
belongs_to :target, :polymorphic => true
belongs_to :author, :class_name => 'Person'
validates_uniqueness_of :target_id, :scope => [:target_type, :author_id]
validates :parent, :presence => true #should be in relayable (pending on fixing Message)
after_create do
self.parent.update_likes_counter
end
after_destroy do
self.parent.update_likes_counter
end
def diaspora_handle
self.author.diaspora_handle
end
def diaspora_handle= nh
self.author = Webfinger.new(nh).fetch
end
def parent_class
self.target_type.constantize
end
def parent
self.target
end
def parent= parent
self.target = parent
end
def notification_type(user, person)
#TODO(dan) need to have a notification for likes on comments, until then, return nil
return nil if self.target_type == "Comment"
......
class Participation < FederatedRelayable
end
\ No newline at end of file
......@@ -294,6 +294,16 @@ class User < ActiveRecord::Base
end
end
def participate!(target, opts={})
participation = build_participation(opts.merge!(:target => target))
if participation.save
dispatch_post(participation)
participation
else
false
end
end
def like!(target, opts={})
like = build_like(opts.merge!(:target => target, :positive => true))
if like.save
......@@ -311,12 +321,14 @@ class User < ActiveRecord::Base
r
end
######## Commenting ########
def build_comment(options = {})
build_relayable(Comment, options)
end
######## Liking ########
def build_participation(options = {})
build_relayable(Participation, options)
end
def build_like(options = {})
build_relayable(Like, options)
end
......
class CreateParticipations < ActiveRecord::Migration
def self.up
create_table "participations", :force => true do |t|
t.string "guid"
t.integer "target_id"
t.string "target_type", :limit => 60, :null => false
t.integer "author_id"
t.text "author_signature"
t.text "parent_author_signature"
t.timestamps
end
end
def self.down
drop_table :participations
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20120203220932) do
ActiveRecord::Schema.define(:version => 20120208231253) do
create_table "account_deletions", :force => true do |t|
t.string "diaspora_handle"
......@@ -244,6 +244,17 @@ ActiveRecord::Schema.define(:version => 20120203220932) do
add_index "oauth_clients", ["name"], :name => "index_oauth_clients_on_name", :unique => true
add_index "oauth_clients", ["nonce"], :name => "index_oauth_clients_on_nonce", :unique => true
create_table "participations", :force => true do |t|
t.string "guid"
t.integer "target_id"
t.string "target_type", :limit => 60, :null => false
t.integer "author_id"
t.text "author_signature"
t.text "parent_author_signature"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "people", :force => true do |t|
t.string "guid", :null => false
t.text "url", :null => false
......
......@@ -7,8 +7,7 @@ require File.join(Rails.root, "spec", "shared_behaviors", "relayable")
describe Like do
before do
bobs_aspect = bob.aspects.first
@status = bob.post(:status_message, :text => "hello", :to => bobs_aspect.id)
@status = bob.post(:status_message, :text => "hello", :to => bob.aspects.first.id)
end
it 'has a valid factory' do
......@@ -94,5 +93,4 @@ describe Like do
let(:build_object) { alice.build_like(:target => @status, :positive => true) }
it_should_behave_like 'it is relayable'
end
end
require "spec_helper"
describe Participation do
describe 'it is relayable' do
before do
@status = bob.post(:status_message, :text => "hello", :to => bob.aspects.first.id)
@local_luke, @local_leia, @remote_raphael = set_up_friends
@remote_parent = Factory(:status_message, :author => @remote_raphael)
@local_parent = @local_luke.post :status_message, :text => "foobar", :to => @local_luke.aspects.first
@object_by_parent_author = @local_luke.participate!(@local_parent)
@object_by_recipient = @local_leia.participate!(@local_parent)
@dup_object_by_parent_author = @object_by_parent_author.dup
@object_on_remote_parent = @local_luke.participate!(@remote_parent)
end
let(:build_object) { alice.build_participation(:target => @status) }
it_should_behave_like 'it is relayable'
end
end
\ No newline at end of file
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter