Merge branch 'friend-refactor' of github.com:diaspora/diaspora_rails into selector

This commit is contained in:
ilya 2010-08-16 14:43:13 -07:00
commit 6a3eb97fd4
10 changed files with 32 additions and 36 deletions

View file

@ -20,7 +20,7 @@ class ApplicationController < ActionController::Base
@groups = current_user.groups @groups = current_user.groups
@friends = current_user.friends @friends = current_user.friends
@latest_status_message = StatusMessage.newest_for(current_user.person) @latest_status_message = StatusMessage.newest_for(current_user.person)
@group = params[:group] ? current_user.groups.first(:id => params[:group]) : current_user.groups.first @group = params[:group] ? current_user.group_by_id(params[:group]) : current_user.groups.first
end end
end end

View file

@ -39,7 +39,7 @@ def warzombie
def zombiefriendaccept def zombiefriendaccept
render :nothing => true render :nothing => true
Request.all.each{|r| Request.all.each{|r|
current_user.accept_friend_request(r.id, current_user.groups.first.id) current_user.accept_and_respond(r.id, current_user.groups.first.id)
} }
end end

View file

@ -15,7 +15,7 @@ class PeopleController < ApplicationController
end end
def destroy def destroy
current_user.unfriend(current_user.friends.first(params[:id])) current_user.unfriend(current_user.friend_by_id(params[:id]))
flash[:notice] = "unfriended person." flash[:notice] = "unfriended person."
redirect_to people_url redirect_to people_url
end end

View file

@ -8,7 +8,7 @@ class RequestsController < ApplicationController
def destroy def destroy
if params[:accept] if params[:accept]
@friend = current_user.accept_friend_request( params[:id], current_user.groups.first.id) @friend = current_user.accept_and_respond( params[:id], current_user.groups.first.id)
flash[:notice] = "you are now friends" flash[:notice] = "you are now friends"
redirect_to root_url redirect_to root_url

View file

@ -1,9 +1,3 @@
module CommentsHelper module CommentsHelper
def target
end
def text
params[:comment][:text]
end
end end

View file

@ -29,7 +29,7 @@ module RequestsHelper
puts request.host puts request.host
if identifier.include?(request.host) if identifier.include?(request.host)
person = Person.by_webfinger identifier person = Person.by_webfinger identifier
action = :friend action = (person == current_user.person ? :none : :friend)
url = person.owner.receive_url url = person.owner.receive_url
else else
f = Redfinger.finger(identifier) f = Redfinger.finger(identifier)

View file

@ -22,10 +22,12 @@ class Comment
validates_presence_of :text validates_presence_of :text
def push_upstream def push_upstream
Rails.logger.info("GOIN UPSTREAM")
push_to([post.person]) push_to([post.person])
end end
def push_downstream def push_downstream
Rails.logger.info("SWIMMIN DOWNSTREAM")
push_to(post.people_with_permissions) push_to(post.people_with_permissions)
end end

View file

@ -66,7 +66,7 @@ class Person
raise "must comment on something!" unless options[:on] raise "must comment on something!" unless options[:on]
c = Comment.new(:person_id => self.id, :text => text, :post => options[:on]) c = Comment.new(:person_id => self.id, :text => text, :post => options[:on])
if c.save if c.save
send_comment c dispatch_comment c
c.socket_to_uid owner.id if owner_id c.socket_to_uid owner.id if owner_id
true true
else else
@ -75,24 +75,12 @@ class Person
false false
end end
def send_comment( c ) def dispatch_comment( c )
if self.owner.nil? if owns? c.post
if c.post.person.owner.nil? push_downstream
#puts "The commenter is not here, and neither is the poster" elsif owns? c
elsif c.post.person.owner c.push_upstream
#puts "The commenter is not here, and the poster is" end
c.push_downstream
end
else
if owns? c.post
#puts "The commenter is here, and is the poster"
c.push_downstream
else
#puts "The commenter is here, and is not the poster"
c.push_upstream
end
end
end end
##profile ##profile
def update_profile(params) def update_profile(params)
@ -115,6 +103,10 @@ class Person
def self.by_webfinger( identifier ) def self.by_webfinger( identifier )
Person.first(:email => identifier.gsub('acct:', '')) Person.first(:email => identifier.gsub('acct:', ''))
end end
def remote?
owner.nil?
end
protected protected
def clean_url def clean_url

View file

@ -63,10 +63,16 @@ class User
activate_friend(request.person, group_by_id(group_id)) activate_friend(request.person, group_by_id(group_id))
request.reverse self request.reverse self
request
end
def dispatch_friend_acceptance(request)
request.push_to_url(request.callback_url) request.push_to_url(request.callback_url)
request.destroy unless request.callback_url.include? url
request.destroy end
def accept_and_respond(friend_request_id, group_id)
dispatch_friend_acceptance(accept_friend_request(friend_request_id, group_id))
end end
def ignore_friend_request(friend_request_id) def ignore_friend_request(friend_request_id)
@ -167,7 +173,8 @@ class User
elsif object.verify_creator_signature == true elsif object.verify_creator_signature == true
Rails.logger.debug("Saving object: #{object}") Rails.logger.debug("Saving object: #{object}")
object.save object.save
object.socket_to_uid( id) if object.respond_to? :socket_to_uid object.socket_to_uid( id) if (object.respond_to?(:socket_to_uid) && !self.owns?(object))
object.person.dispatch_comment object if object.is_a?(Comment)
end end
end end

View file

@ -22,4 +22,5 @@ user2.person.save
# friending users # friending users
group = user.group(:name => "other dudes") group = user.group(:name => "other dudes")
request = user.send_friend_request_to(user2.receive_url, group.id) request = user.send_friend_request_to(user2.receive_url, group.id)
user2.accept_friend_request request.id, user2.group(:name => "presidents").id reversed_request = user2.accept_friend_request( request.id, user2.group(:name => "presidents").id )
user.receive reversed_request.to_diaspora_xml