diff --git a/app/controllers/friend_requests_controller.rb b/app/controllers/friend_requests_controller.rb index fa2cd81dc..3c33c049b 100644 --- a/app/controllers/friend_requests_controller.rb +++ b/app/controllers/friend_requests_controller.rb @@ -24,13 +24,12 @@ class FriendRequestsController < ApplicationController end def create - @friend_request = FriendRequest.new(params[:friend_request]) - @friend_request.sender = Person.new( :email => User.first.email, :url => User.first.url ) - puts - puts - puts params.inspect + @friend_request.sender = current_user + puts + puts + puts @recipient if @friend_request.save flash[:notice] = "Successfully created friend request." diff --git a/app/models/friend_request.rb b/app/models/friend_request.rb index 3c9cd0e0c..7c18808b2 100644 --- a/app/models/friend_request.rb +++ b/app/models/friend_request.rb @@ -1,32 +1,18 @@ class FriendRequest include MongoMapper::Document - include ROXML - include Diaspora::Webhooks - xml_name :friend_request - xml_accessor :sender, :as => Person - xml_accessor :recipient, :as => Person + key :recipient_url + + attr_accessor :sender - key :sender, Person - key :recipient, Person + validates_presence_of :recipient_url - validates_presence_of :sender, :recipient after_create :send_off - def accept - f = Friend.new - f.email = self.sender.email - f.url = self.sender.url - f.save - self.destroy - end - - def reject - self.destroy - end - def send_off - push_to_recipient self.recipient + sender = Friend.from_xml( self.sender.to_xml ) + + sender.push_to_url self.recipient_url end - + end diff --git a/app/views/friend_requests/_friend_request.html.haml b/app/views/friend_requests/_friend_request.html.haml index c906e67a1..29e437cb6 100644 --- a/app/views/friend_requests/_friend_request.html.haml +++ b/app/views/friend_requests/_friend_request.html.haml @@ -1,2 +1,4 @@ %li.message{:id => post.id} + = post.inspect + %h2= post.sender.is_a? User diff --git a/app/views/friend_requests/show.html.haml b/app/views/friend_requests/show.html.haml index 72cba82bd..5830e6c99 100644 --- a/app/views/friend_requests/show.html.haml +++ b/app/views/friend_requests/show.html.haml @@ -2,16 +2,10 @@ %p %strong Recipient: - = @friend_request.recipient.email -%p - %strong URL: - = @friend_request.recipient.url + = @friend_request.recipient %p %strong Sender: - = @friend_request.sender.email -%p - %strong URL: - = @friend_request.sender.url + = @friend_request.sender %p = link_to "Edit", edit_friend_request_path(@bookmark) diff --git a/lib/common.rb b/lib/common.rb index aa4034dcf..5c66a6b2f 100644 --- a/lib/common.rb +++ b/lib/common.rb @@ -34,7 +34,7 @@ module Diaspora if p.is_a? Retraction p.perform - elsif p.is_a? FriendRequest + elsif p.is_a? Friend p.save #This line checks if the sender was in the database, among other things? elsif p.respond_to?(:person) && !(p.person.nil?) #WTF @@ -65,10 +65,13 @@ module Diaspora @@queue.process end end - - def push_to_recipient(recipient) - if self.sender_id == User.first.id - push_to( [recipient] ) + + def push_to_url(url) + if url + url = url + "receive/" + xml = self.class.build_xml_for([self]) + @@queue.add_post_request( [url], xml ) + @@queue.process end end diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake index f5aae374a..caa98ba86 100644 --- a/lib/tasks/db.rake +++ b/lib/tasks/db.rake @@ -20,7 +20,7 @@ namespace :db do # Specifiy what models to remove Post.delete_all - #Person.delete_all + Person.delete_all User.delete_all Friend.delete_all Profile.delete_all