diff --git a/app/controllers/friends_controller.rb b/app/controllers/friends_controller.rb deleted file mode 100644 index dbe7bc414..000000000 --- a/app/controllers/friends_controller.rb +++ /dev/null @@ -1,39 +0,0 @@ -class FriendsController < ApplicationController - before_filter :authenticate_user! - - def index - @friends = Friend.paginate :page => params[:page], :order => 'created_at DESC' - end - - def show - @friend = Friend.where(:id => params[:id]).first - @friend_profile = @friend.profile - @friend_posts = Post.where(:person_id => @friend.id).sort(:created_at.desc) - end - - def destroy - @friend = Friend.where(:id => params[:id]).first - @friend.destroy - flash[:notice] = "Successfully destroyed friend." - redirect_to friends_url - end - - def new - @friend = Friend.new - @profile = Profile.new - end - - def create - - puts params.inspect - @friend = Friend.new(params[:friend]) - - - if @friend.save - flash[:notice] = "Successfully created friend." - redirect_to @friend - else - render :action => 'new' - end - end -end diff --git a/app/models/person_request.rb b/app/models/person_request.rb index e240216e1..b4d233eaf 100644 --- a/app/models/person_request.rb +++ b/app/models/person_request.rb @@ -1,8 +1,11 @@ class PersonRequest + require 'lib/common' + include ApplicationHelper include MongoMapper::Document - include Diaspora::Webhooks include ROXML - + include Diaspora::Webhooks + + xml_name :person_request xml_accessor :_id @@ -16,11 +19,9 @@ class PersonRequest before_save :check_for_person_requests def self.for(url) - request = PersonRequest.new(:url => url) - request.person = User.first + request = PersonRequest.new(:url => url, :person => User.first) request.save - - request.push_to([request]) + request.push_to_url(url) end def check_for_person_requests diff --git a/app/views/friend_requests/_form.html.haml b/app/views/friend_requests/_form.html.haml deleted file mode 100644 index f9d962221..000000000 --- a/app/views/friend_requests/_form.html.haml +++ /dev/null @@ -1,5 +0,0 @@ -= form_for @friend_request do |f| - = f.error_messages - - %p - f.submit diff --git a/app/views/friend_requests/_friend_request.html.haml b/app/views/friend_requests/_friend_request.html.haml deleted file mode 100644 index f61edbeca..000000000 --- a/app/views/friend_requests/_friend_request.html.haml +++ /dev/null @@ -1,3 +0,0 @@ -%li.message{:id => friend_request.id} - - = friend_request.inspect diff --git a/app/views/friend_requests/_new_friend_request.haml b/app/views/friend_requests/_new_friend_request.haml deleted file mode 100644 index f208c8ff4..000000000 --- a/app/views/friend_requests/_new_friend_request.haml +++ /dev/null @@ -1,4 +0,0 @@ -= form_for @friend_request, :remote => true do |f| - = f.error_messages - %p - = f.submit diff --git a/app/views/friend_requests/edit.html.haml b/app/views/friend_requests/edit.html.haml deleted file mode 100644 index 11421d0ba..000000000 --- a/app/views/friend_requests/edit.html.haml +++ /dev/null @@ -1,8 +0,0 @@ -- title "Edit Bookmark" - -= render 'form' - -%p - = link_to "Show", bookmark_path(@bookmark) - | - = link_to "View All", bookmarks_path diff --git a/app/views/friend_requests/index.html.haml b/app/views/friend_requests/index.html.haml deleted file mode 100644 index c7091fcbf..000000000 --- a/app/views/friend_requests/index.html.haml +++ /dev/null @@ -1,7 +0,0 @@ -%h1 friend requests -= render "friend_requests/new_friend_request", :friend_request => @friend_request -%ul#stream - - for friend_request in @friend_requests - = render "friend_request", :friend_request => friend_request -#pagination - = will_paginate @friend_requests diff --git a/app/views/friend_requests/new.html.haml b/app/views/friend_requests/new.html.haml deleted file mode 100644 index c799efe57..000000000 --- a/app/views/friend_requests/new.html.haml +++ /dev/null @@ -1,5 +0,0 @@ -- title "New Friend Request" - -= render 'form' - -%p= link_to "Back to List", friend_requests_path diff --git a/app/views/friend_requests/show.html.haml b/app/views/friend_requests/show.html.haml deleted file mode 100644 index e4a482156..000000000 --- a/app/views/friend_requests/show.html.haml +++ /dev/null @@ -1,11 +0,0 @@ -- title "Friend Request" - -%p - = friend_request.inspect - -%p - = link_to "Edit", edit_friend_request_path(@bookmark) - | - = link_to "Destroy", @friend_request, :confirm => 'Are you sure?', :method => :delete - | - = link_to "View All", friend_requests_path diff --git a/lib/common.rb b/lib/common.rb index 537c50c0e..2c117db58 100644 --- a/lib/common.rb +++ b/lib/common.rb @@ -29,16 +29,21 @@ module Diaspora def store_objects_from_xml(xml) objects = parse_objects_from_xml(xml) + + puts xml objects.each do |p| if p.is_a? Retraction p.perform elsif p.is_a? PersonRequest - if PersonRequest.where(:url => p.url).first - p.active = true + if PersonRequest.where(:_id => p._id).first + p.person.active = true end + + p.url = p.person.url p.save p.person.save + #This line checks if the sender was in the database, among other things? elsif p.respond_to?(:person) && !(p.person.nil?) && !(p.person.is_a? User) #WTF p.save @@ -69,6 +74,16 @@ module Diaspora end end + def push_to_url(url) + if url + puts "AHHHHHH, sending" + xml = self.class.build_xml_for([self]) + puts xml + @@queue.add_post_request( [url], xml ) + @@queue.process + end + end + def prep_webhook "#{self.to_xml.to_s}" end diff --git a/spec/lib/parser_spec.rb b/spec/lib/parser_spec.rb index 95ed70894..fe93b33bb 100644 --- a/spec/lib/parser_spec.rb +++ b/spec/lib/parser_spec.rb @@ -114,22 +114,27 @@ describe "parser in application helper" do request = PersonRequest.new(:url => "http://www.googles.com/") request.person = @person - xml = Post.build_xml_for [request] + xml = PersonRequest.build_xml_for [request] @person.destroy @user.destroy Person.count.should be 0 store_objects_from_xml(xml) Person.count.should be 1 + puts Person.first.inspect end it "should activate the Person if I initiated a request to that url" do request = PersonRequest.create(:url => @person.url, :person => @user) - request_remote = PersonRequest.new(:url => "http://www.yahoo.com/") + request_remote = PersonRequest.new(:_id => request.id, :url => "http://www.yahoo.com/") request_remote.person = @person.clone - xml = Post.build_xml_for [request_remote] - + xml = PersonRequest.build_xml_for [request_remote] + + @person.destroy + @user.destroy + request_remote.destroy + store_objects_from_xml(xml) Person.where(:url => @person.url).first.active.should be true end