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

This commit is contained in:
ilya 2010-08-16 11:50:04 -07:00
commit 122da43058
12 changed files with 47 additions and 49 deletions

View file

@ -6,7 +6,7 @@ class PeopleController < ApplicationController
end
def show
@person= Person.where(:id => params[:id]).first
@person= current_user.friend_by_id(params[:id])
@person_profile = @person.profile
@person_posts = Post.where(:person_id => @person.id).paginate :page => params[:page], :order => 'created_at DESC'

View file

@ -11,12 +11,11 @@ class PublicsController < ApplicationController
end
def host_meta
@user = User.owner
render 'host_meta', :layout => false, :content_type => 'application/xrd+xml'
end
def webfinger
@person = Person.first(:email => params[:q].gsub('acct:', ''))
@person = Person.by_webfinger(params[:q])
unless @person.nil? || @person.owner.nil?
render 'webfinger', :layout => false, :content_type => 'application/xrd+xml'
end

View file

@ -32,7 +32,11 @@ module ApplicationHelper
end
def owner_image_tag
person_image_tag(User.owner)
person_image_tag(current_user)
end
def owner_image_link
person_image_link(current_user)
end
def person_image_tag(person)
@ -46,10 +50,6 @@ module ApplicationHelper
link_to person_image_tag(person), object_path(person)
end
def owner_image_link
person_image_link(User.owner)
end
def new_request(request_count)
"new_requests" if request_count > 0
end

View file

@ -26,9 +26,16 @@ module RequestsHelper
end
def relationship_flow(identifier)
f = Redfinger.finger(identifier)
action = subscription_mode(f)
url = subscription_url(action, f)
puts request.host
if identifier.include?(request.host)
person = Person.by_webfinger identifier
action = :friend
url = person.owner.receive_url
else
f = Redfinger.finger(identifier)
action = subscription_mode(f)
url = subscription_url(action, f)
end
{ action => url }
end

View file

@ -15,8 +15,8 @@ class Blog < Post
<activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
<title>#{self.title}</title>
<content>#{self.body}</content>
<link rel="alternate" type="text/html" href="#{User.owner.url}blogs/#{self.id}"/>
<id>#{User.owner.url}blogs/#{self.id}</id>
<link rel="alternate" type="text/html" href="#{person.url}blogs/#{self.id}"/>
<id>#{person.url}blogs/#{self.id}</id>
<published>#{self.created_at.xmlschema}</published>
<updated>#{self.updated_at.xmlschema}</updated>
</entry>

View file

@ -17,9 +17,9 @@ class Bookmark < Post
<entry>
<activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
<title>#{self.title}</title>
<link rel="alternate" type="text/html" href="#{User.owner.url}bookmarks/#{self.id}"/>
<link rel="alternate" type="text/html" href="#{person.url}bookmarks/#{self.id}"/>
<link rel="related" type="text/html" href="#{self.link}"/>
<id>#{User.owner.url}bookmarks/#{self.id}</id>
<id>#{person.url}bookmarks/#{self.id}</id>
<published>#{self.created_at.xmlschema}</published>
<updated>#{self.updated_at.xmlschema}</updated>
</entry>

View file

@ -75,7 +75,7 @@ class Person
false
end
def send_comment c
def send_comment( c )
if self.owner.nil?
if c.post.person.owner.nil?
#puts "The commenter is not here, and neither is the poster"
@ -112,6 +112,10 @@ class Person
"#{self.url}receive/users/#{self.id}/"
end
def self.by_webfinger( identifier )
Person.first(:email => identifier.gsub('acct:', ''))
end
protected
def clean_url
self.url ||= "http://localhost:3000/" if self.class == User

View file

@ -37,7 +37,7 @@ class Photo < Post
end
def remote_photo
@remote_photo ||= User.owner.url.chop + image.url
@remote_photo ||= self.person.url.chop + image.url
end
def remote_photo= remote_path
@ -47,10 +47,10 @@ class Photo < Post
end
def ensure_user_picture
user = User.owner
if user.profile.image_url == image.url(:thumb_medium)
users = Person.all('profile.image_url' => image.url(:thumb_medium) )
users.each{ |user|
user.profile.update_attributes!(:image_url => nil)
end
}
end
def thumb_hash

View file

@ -13,8 +13,8 @@ class StatusMessage < Post
<entry>
<activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
<title>#{self.message}</title>
<link rel="alternate" type="text/html" href="#{User.owner.url}status_messages/#{self.id}"/>
<id>#{User.owner.url}status_messages/#{self.id}</id>
<link rel="alternate" type="text/html" href="#{person.url}status_messages/#{self.id}"/>
<id>#{person.url}status_messages/#{self.id}</id>
<published>#{self.created_at.xmlschema}</published>
<updated>#{self.updated_at.xmlschema}</updated>
</entry>

View file

@ -45,7 +45,7 @@ class User
self.pending_requests << request
self.save
group = self.groups.first(:id => group_id)
group = self.group_by_id(group_id)
group.requests << request
group.save
@ -60,7 +60,7 @@ class User
request = Request.where(:id => friend_request_id).first
n = pending_requests.delete(request)
activate_friend(request.person, groups.first(:id => group_id))
activate_friend(request.person, group_by_id(group_id))
request.reverse self
@ -82,7 +82,7 @@ class User
def receive_friend_request(friend_request)
Rails.logger.info("receiving friend request #{friend_request.to_json}")
if request_from_me?(friend_request)
group = self.groups.first(:id => friend_request.group_id)
group = self.group_by_id(friend_request.group_id)
activate_friend(friend_request.person, group)
Rails.logger.info("#{self.real_name}'s friend request has been accepted")
@ -145,8 +145,8 @@ class User
if object.is_a? Retraction
if object.type == 'Person' && object.signature_valid?
Rails.logger.info( "the person id is #{object.post_id} the friend found is #{friends.first(object.post_id)}")
unfriended_by friends.first(object.post_id)
Rails.logger.info( "the person id is #{object.post_id} the friend found is #{friend_by_id(object.post_id).inspect}")
unfriended_by friend_by_id(object.post_id)
else
object.perform self.id
@ -189,10 +189,14 @@ class User
self.password_confirmation = self.password
end
def self.owner
User.first
def friend_by_id( id )
friends.detect{|x| x.id == ensure_bson id }
end
def group_by_id( id )
groups.detect{|x| x.id == ensure_bson id }
end
protected
def assign_key
@ -207,4 +211,7 @@ class User
OpenSSL::PKey::RSA::generate 1024
end
def ensure_bson id
id.class == String ? BSON::ObjectID(id) : id
end
end

View file

@ -1,11 +1,3 @@
#This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
# Mayor.create(:name => 'Daley', :city => citie
require 'config/environment'
# Create seed user

View file

@ -6,17 +6,6 @@ describe Post do
@user.person.save
end
describe 'defaults' do
before do
WebSocket.stub!(:update_clients)
@post = Factory.create(:post, :person => nil)
end
it "should associate the owner if none is present" do
@post.person.should == User.owner
end
end
describe "newest" do
before do
@person_one = Factory.create(:person, :email => "some@dudes.com")