From 049361ea1539d3ae5351a7a3fb408623ee9d3b17 Mon Sep 17 00:00:00 2001 From: maxwell Date: Wed, 28 Jul 2010 18:32:00 -0700 Subject: [PATCH] MS profiles should send, need to just make the parser now --- app/controllers/users_controller.rb | 3 +-- app/models/profile.rb | 11 +++++++++++ app/models/user.rb | 11 +++++++++++ lib/diaspora/webhooks.rb | 8 ++++++++ lib/message_handler.rb | 2 +- spec/models/user_spec.rb | 28 ++++++++++++---------------- 6 files changed, 44 insertions(+), 19 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index a9adbf346..9b4411c7a 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -17,9 +17,8 @@ class UsersController < ApplicationController def update @user = User.where(:id => params[:id]).first - puts params.inspect - if @user.update_attributes(params[:user]) + if @user.update_profile(params[:user]) flash[:notice] = "Successfully updated user." redirect_to @user else diff --git a/app/models/profile.rb b/app/models/profile.rb index 934c46f93..8243268be 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -1,10 +1,14 @@ class Profile include MongoMapper::EmbeddedDocument + require 'lib/diaspora/webhooks' + include Diaspora::Webhooks include ROXML + xml_reader :person_id xml_accessor :first_name xml_accessor :last_name xml_accessor :image_url + key :first_name, String key :last_name, String @@ -20,5 +24,12 @@ class Profile # self.image_url = self._parent_document.url + self.image_url # end # end + def person_id + self._parent_document.id + end + + def to_diaspora_xml + self.to_xml.to_s + end end diff --git a/app/models/user.rb b/app/models/user.rb index bd8dcdc52..a7326c18a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -28,6 +28,17 @@ class User < Person end false end + + ##profile + def update_profile(params) + if self.update_attributes(params) + puts self.profile.class + self.profile.notify_people! + true + else + false + end + end ######### Friend Requesting def send_friend_request_to(friend_url) diff --git a/lib/diaspora/webhooks.rb b/lib/diaspora/webhooks.rb index b87f7e784..fc20841a4 100644 --- a/lib/diaspora/webhooks.rb +++ b/lib/diaspora/webhooks.rb @@ -10,6 +10,10 @@ module Diaspora push_to(people_with_permissions) end end + + def notify_people! + push_to(people_with_permissions) + end def subscribe_to_ostatus(feed_url) @@queue.add_subscription_request(feed_url) @@ -22,9 +26,12 @@ module Diaspora end def push_to(recipients) + puts "FOOBATT" @@queue.add_hub_notification(APP_CONFIG[:pubsub_server], User.owner.url + self.class.to_s.pluralize.underscore + '.atom') unless recipients.empty? recipients.map!{|x| x = x.url + "receive/"} + puts self.class + puts "made it in here!" xml = self.class.build_xml_for(self) Rails.logger.info("Adding xml for #{self} to message queue to #{recipients}") @@queue.add_post_request( recipients, xml ) @@ -54,6 +61,7 @@ module Diaspora [*posts].each {|x| xml << x.to_diaspora_xml} xml += "" xml += "" + end end end diff --git a/lib/message_handler.rb b/lib/message_handler.rb index a1d5702f2..8d35cb1f3 100644 --- a/lib/message_handler.rb +++ b/lib/message_handler.rb @@ -46,7 +46,7 @@ class MessageHandler case query.type when :post http = EventMachine::HttpRequest.new(query.destination).post :timeout => TIMEOUT, :body =>{:xml => query.body} - http.callback { puts query.destination; process; process} + http.callback { puts query.destination; puts query.body; process; process} when :get http = EventMachine::HttpRequest.new(query.destination).get :timeout => TIMEOUT http.callback {send_to_seed(query, http.response); process} diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 04c4f44a9..b767db3b6 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -59,26 +59,22 @@ describe User do end it 'should be able to update their profile and send it to their friends' do - pending + Factory.create(:person) + p = {:profile => {:first_name => 'bob', :last_name => 'billytown', :image_url => "http://clowntown.com"}} - profile = {:first_name => 'bob', :last_name => 'billytown', :image_url => "http://clowntown.com"} - - @user = Factory.create(:user, :profile => Profile.new(profile)) - profile = {:first_name => 'bob', :last_name => 'billytown', :image_url => "http://awesome.com"} + @user = Factory.create(:user) + p = {:profile => {:first_name => 'bob', :last_name => 'billytown', :image_url => "http://clown.com"}} - @user.update_profile(profile) + @user.update_profile(p).should == true - @user.profile.image_url.should == "http://awesome.com" - #puts @user.to_xml.to_s + @user.profile.image_url.should == "http://clown.com" + + Profile.should_receive(:build_xml_for) + + n = Profile.send :class_variable_get, :@@queue + n.should_receive(:process) end - - it 'should fix the image_url 'do - pending - profile = Profile.new(:image_url => "/images/foo.jpg") - user = Factory.create(:user, :profile => profile) - - puts user.profile.image_url - end + end