Skip to content
Extraits de code Groupes Projets
Valider f9f91a0e rédigé par Benjamin Neff's avatar Benjamin Neff
Parcourir les fichiers

create new contact for local receive

parent 970e8bb3
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -85,11 +85,26 @@ class Contact < ActiveRecord::Base
user.share_with(person, user.auto_follow_back_aspect) if user.auto_follow_back && !receiving
end
# object for local recipient
def object_to_receive
Contact.create_or_update_sharing_contact(person.owner, user.person)
end
# @return [Array<Person>] The recipient of the contact
def subscribers
[person]
end
# creates or updates a contact with active sharing flag. Returns nil if already sharing.
def self.create_or_update_sharing_contact(recipient, sender)
contact = recipient.contacts.find_or_initialize_by(person_id: sender.id)
return if contact.sharing
contact.update(sharing: true)
contact
end
private
def not_contact_with_closed_account
......
......@@ -12,14 +12,15 @@ class User
contact = contacts.find_or_initialize_by(person_id: person.id)
return false unless contact.valid?
unless contact.receiving?
# TODO: dispatch
contact.receiving = true
end
needs_dispatch = !contact.receiving?
contact.receiving = true
contact.aspects << aspect
contact.save
if needs_dispatch
Diaspora::Federation::Dispatcher.defer_dispatch(self, contact)
end
Notifications::StartedSharing.where(recipient_id: id, target: person.id, unread: true)
.update_all(unread: false)
......
......@@ -39,7 +39,9 @@ module Diaspora
end
def deliver_to_local(people)
Workers::ReceiveLocal.perform_async(object.class.to_s, object.id, people.map(&:owner_id))
obj = object.respond_to?(:object_to_receive) ? object.object_to_receive : object
return unless obj
Workers::ReceiveLocal.perform_async(obj.class.to_s, obj.id, people.map(&:owner_id))
end
def deliver_to_remote(people)
......
......@@ -22,14 +22,7 @@ module Diaspora
def self.contact(entity)
recipient = Person.find_by(diaspora_handle: entity.recipient).owner
contact = recipient.contacts.find_or_initialize_by(person_id: author_of(entity).id)
return if contact.sharing
contact.tap do |contact|
contact.sharing = true
contact.save!
end
Contact.create_or_update_sharing_contact(recipient, author_of(entity))
end
def self.conversation(entity)
......
......@@ -109,7 +109,6 @@ describe User::Connecting, type: :model do
end
it "does set mutual on share-back request" do
skip # TODO
eve.share_with(alice.person, eve.aspects.first)
alice.share_with(eve.person, alice.aspects.first)
......@@ -127,25 +126,23 @@ describe User::Connecting, type: :model do
context "dispatching" do
it "dispatches a request on initial request" do
skip # TODO
contact = alice.contacts.new(person: eve.person)
expect(alice.contacts).to receive(:find_or_initialize_by).and_return(contact)
# TODO: expect(contact).to receive(:dispatch_request)
allow(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch)
expect(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch).with(alice, contact)
alice.share_with(eve.person, alice.aspects.first)
end
it "dispatches a request on a share-back" do
skip # TODO
eve.share_with(alice.person, eve.aspects.first)
contact = alice.contact_for(eve.person)
expect(alice.contacts).to receive(:find_or_initialize_by).and_return(contact)
# TODO: expect(contact).to receive(:dispatch_request)
allow(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch)
expect(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch).with(alice, contact)
alice.share_with(eve.person, alice.aspects.first)
end
......@@ -154,7 +151,8 @@ describe User::Connecting, type: :model do
contact = alice.contacts.create(person: eve.person, receiving: true)
allow(alice.contacts).to receive(:find_or_initialize_by).and_return(contact)
# TODO: expect(contact).not_to receive(:dispatch_request)
allow(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch).with(alice, instance_of(Profile))
expect(Diaspora::Federation::Dispatcher).not_to receive(:defer_dispatch).with(alice, instance_of(Contact))
alice.share_with(eve.person, aspect2)
end
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter