Merge pull request #7001 from svbergerem/fix-conversation-recipient-suggestions

Fix conversations autoSuggest showing non-mutual contacts
This commit is contained in:
Jonne Haß 2016-08-18 13:34:43 +02:00
commit 148e85558a
No known key found for this signature in database
GPG key ID: F347E0EB47AC70D6
5 changed files with 47 additions and 9 deletions

View file

@ -167,6 +167,7 @@ The command will report queues that still have jobs and launch sidekiq process f
* Add aspects to the aspect membership dropdown when creating them on the getting started page [#6864](https://github.com/diaspora/diaspora/pull/6864) * Add aspects to the aspect membership dropdown when creating them on the getting started page [#6864](https://github.com/diaspora/diaspora/pull/6864)
* Strip markdown from message preview in conversations list [#6923](https://github.com/diaspora/diaspora/pull/6923) * Strip markdown from message preview in conversations list [#6923](https://github.com/diaspora/diaspora/pull/6923)
* Improve tag stream performance [#6903](https://github.com/diaspora/diaspora/pull/6903) * Improve tag stream performance [#6903](https://github.com/diaspora/diaspora/pull/6903)
* Only show mutual contacts in conversations auto suggestions [#7001](https://github.com/diaspora/diaspora/pull/7001)
## Features ## Features
* Support color themes [#6033](https://github.com/diaspora/diaspora/pull/6033) * Support color themes [#6033](https://github.com/diaspora/diaspora/pull/6033)

View file

@ -104,7 +104,7 @@ class ConversationsController < ApplicationController
private private
def contacts_data def contacts_data
current_user.contacts.sharing.joins(person: :profile) current_user.contacts.mutual.joins(person: :profile)
.pluck(*%w(contacts.id profiles.first_name profiles.last_name people.diaspora_handle)) .pluck(*%w(contacts.id profiles.first_name profiles.last_name people.diaspora_handle))
.map {|contact_id, *name_attrs| .map {|contact_id, *name_attrs|
{value: contact_id, name: ERB::Util.h(Person.name_from_attrs(*name_attrs)) } {value: contact_id, name: ERB::Util.h(Person.name_from_attrs(*name_attrs)) }

View file

@ -33,6 +33,8 @@ class Contact < ActiveRecord::Base
# contact.receiving is true when contact.user is sharing with contact.person # contact.receiving is true when contact.user is sharing with contact.person
scope :receiving, -> { where(receiving: true) } scope :receiving, -> { where(receiving: true) }
scope :mutual, -> { sharing.receiving }
scope :for_a_stream, -> { includes(:aspects, person: :profile).order("profiles.last_name ASC") } scope :for_a_stream, -> { includes(:aspects, person: :profile).order("profiles.last_name ASC") }
scope :only_sharing, -> { sharing.where(receiving: false) } scope :only_sharing, -> { sharing.where(receiving: false) }

View file

@ -23,10 +23,13 @@ describe ConversationsController, :type => :controller do
end end
it "assigns a json list of contacts that are sharing with the person" do it "assigns a json list of contacts that are sharing with the person" do
sharing_user = FactoryGirl.create(:user_with_aspect)
sharing_user.share_with(alice.person, sharing_user.aspects.first)
get :new, :modal => true get :new, :modal => true
expect(assigns(:contacts_json)).to include(alice.contacts.where(:sharing => true).first.person.name) expect(assigns(:contacts_json)).to include(alice.contacts.where(sharing: true, receiving: true).first.person.name)
alice.contacts << Contact.new(:person_id => eve.person.id, :user_id => alice.id, :sharing => false, :receiving => true) alice.contacts << Contact.new(:person_id => eve.person.id, :user_id => alice.id, :sharing => false, :receiving => true)
expect(assigns(:contacts_json)).not_to include(alice.contacts.where(:sharing => false).first.person.name) expect(assigns(:contacts_json)).not_to include(alice.contacts.where(sharing: false).first.person.name)
expect(assigns(:contacts_json)).not_to include(alice.contacts.where(receiving: false).first.person.name)
end end
it "assigns a contact if passed a contact id" do it "assigns a contact if passed a contact id" do

View file

@ -85,10 +85,15 @@ describe Contact, type: :model do
it "returns contacts with sharing true" do it "returns contacts with sharing true" do
expect { expect {
alice.contacts.create!(sharing: true, person: FactoryGirl.create(:person)) alice.contacts.create!(sharing: true, person: FactoryGirl.create(:person))
alice.contacts.create!(sharing: false, person: FactoryGirl.create(:person))
}.to change { }.to change {
Contact.sharing.count Contact.sharing.count
}.by(1) }.by(1)
expect {
alice.contacts.create!(sharing: false, person: FactoryGirl.create(:person))
}.to change {
Contact.sharing.count
}.by(0)
end end
end end
@ -96,23 +101,50 @@ describe Contact, type: :model do
it "returns contacts with sharing true" do it "returns contacts with sharing true" do
expect { expect {
alice.contacts.create!(receiving: true, person: FactoryGirl.build(:person)) alice.contacts.create!(receiving: true, person: FactoryGirl.build(:person))
alice.contacts.create!(receiving: false, person: FactoryGirl.build(:person))
}.to change { }.to change {
Contact.receiving.count Contact.receiving.count
}.by(1) }.by(1)
expect {
alice.contacts.create!(receiving: false, person: FactoryGirl.build(:person))
}.to change {
Contact.receiving.count
}.by(0)
end
end
describe "mutual" do
it "returns contacts with sharing true and receiving true" do
expect {
alice.contacts.create!(receiving: true, sharing: true, person: FactoryGirl.build(:person))
}.to change {
Contact.mutual.count
}.by(1)
expect {
alice.contacts.create!(receiving: false, sharing: true, person: FactoryGirl.build(:person))
alice.contacts.create!(receiving: true, sharing: false, person: FactoryGirl.build(:person))
}.to change {
Contact.mutual.count
}.by(0)
end end
end end
describe "only_sharing" do describe "only_sharing" do
it "returns contacts with sharing true and receiving false" do it "returns contacts with sharing true and receiving false" do
expect {
alice.contacts.create!(receiving: false, sharing: true, person: FactoryGirl.build(:person))
alice.contacts.create!(receiving: false, sharing: true, person: FactoryGirl.build(:person))
}.to change {
Contact.only_sharing.count
}.by(2)
expect { expect {
alice.contacts.create!(receiving: true, sharing: true, person: FactoryGirl.build(:person)) alice.contacts.create!(receiving: true, sharing: true, person: FactoryGirl.build(:person))
alice.contacts.create!(receiving: false, sharing: true, person: FactoryGirl.build(:person))
alice.contacts.create!(receiving: false, sharing: true, person: FactoryGirl.build(:person))
alice.contacts.create!(receiving: true, sharing: false, person: FactoryGirl.build(:person)) alice.contacts.create!(receiving: true, sharing: false, person: FactoryGirl.build(:person))
}.to change { }.to change {
Contact.receiving.count Contact.only_sharing.count
}.by(2) }.by(0)
end end
end end