From aef5abf6311aa06f96379ef25516046857f5f357 Mon Sep 17 00:00:00 2001 From: danielvincent Date: Tue, 14 Dec 2010 17:33:07 -0800 Subject: [PATCH] Correct some queries, look at incoming requests in search, explicit pending false in activate_contact --- app/controllers/aspects_controller.rb | 8 ++++---- app/controllers/people_controller.rb | 8 ++++++-- app/models/contact.rb | 2 +- app/views/people/_person.html.haml | 4 ++-- lib/diaspora/user/connecting.rb | 5 ++++- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index e8783e149..c054b4e95 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -11,7 +11,7 @@ class AspectsController < ApplicationController def index @posts = current_user.visible_posts(:_type => "StatusMessage").paginate :page => params[:page], :per_page => 15, :order => 'created_at DESC' @post_hashes = hashes_for_posts @posts - @contacts = current_user.contacts + @contacts = current_user.contacts(:pending => false) @aspect_hashes = hashes_for_aspects @aspects.all, @contacts, :limit => 8 @aspect = :all @@ -62,11 +62,11 @@ class AspectsController < ApplicationController def show @aspect = current_user.aspect_by_id params[:id] - @contacts = current_user.contacts + @contacts = current_user.contacts(:pending => false) unless @aspect render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404 else - @aspect_contacts = hashes_for_contacts @aspect.contacts + @aspect_contacts = hashes_for_contacts @aspect.contacts(:pending => false) @aspect_contacts_count = @aspect_contacts.count @posts = @aspect.posts.find_all_by__type("StatusMessage", :order => 'created_at desc').paginate :page => params[:page], :per_page => 15 @@ -79,7 +79,7 @@ class AspectsController < ApplicationController def manage @aspect = :manage - @contacts = current_user.contacts + @contacts = current_user.contacts(:pending => false) @remote_requests = Request.hashes_for_person(current_user.person) @aspect_hashes = hashes_for_aspects @aspects, @contacts end diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 628640ef9..35d84bbe0 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -26,7 +26,7 @@ class PeopleController < ApplicationController def hashes_for_people people, aspects ids = people.map{|p| p.id} requests = {} - Request.all(:to_id.in => ids, :from_id => current_user.person.id).each do |r| + Request.all(:from_id.in => ids, :to_id => current_user.person.id).each do |r| requests[r.to_id] = r end contacts = {} @@ -53,7 +53,11 @@ class PeopleController < ApplicationController @aspects_with_person = @contact.aspects end - @commenting_disabled = (current_user.person.id != @person.id) && !@contact + if (@person != current_user.person) && (!@contact || @contact.pending) + @commenting_disabled = true + else + @commenting_disabled = false + end @posts = current_user.posts_from(@person).paginate :page => params[:page] @post_hashes = hashes_for_posts @posts diff --git a/app/models/contact.rb b/app/models/contact.rb index 57262a432..b330811e3 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -5,7 +5,7 @@ class Contact include MongoMapper::Document - key :pending, Boolean + key :pending, Boolean, :default => true key :user_id, ObjectId belongs_to :user diff --git a/app/views/people/_person.html.haml b/app/views/people/_person.html.haml index 87bcdf756..d0d3eca84 100644 --- a/app/views/people/_person.html.haml +++ b/app/views/people/_person.html.haml @@ -13,9 +13,9 @@ .right{:style=>"display:inline;"} - if person.owner_id == current_user.id = t('.thats_you') - - elsif contact + - elsif contact && !contact.pending = t('.already_connected') - - elsif request + - elsif (contact && contact.pending) || request = link_to t('.pending_request'), aspects_manage_path - else - single_aspect_form ||= nil diff --git a/lib/diaspora/user/connecting.rb b/lib/diaspora/user/connecting.rb index 8a6e53458..d8ea45f36 100644 --- a/lib/diaspora/user/connecting.rb +++ b/lib/diaspora/user/connecting.rb @@ -117,7 +117,10 @@ module Diaspora end def activate_contact(person, aspect) - new_contact = Contact.create!(:user => self, :person => person, :aspects => [aspect]) + new_contact = Contact.create!(:user => self, + :person => person, + :aspects => [aspect], + :pending => false) new_contact.aspects << aspect save! aspect.save!