Module: User::Connecting

Included in:
User
Defined in:
app/models/user/connecting.rb

Instance Method Summary collapse

Instance Method Details

#disconnect(contact) ⇒ Object


35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/models/user/connecting.rb', line 35

def disconnect(contact)
  logger.info "event=disconnect user=#{diaspora_handle} target=#{contact.person.diaspora_handle}"

  if contact.person.local?
    raise "FATAL: user entry is missing from the DB. Aborting" if contact.person.owner.nil?
    contact.person.owner.disconnected_by(contact.user.person)
  else
    ContactRetraction.for(contact).defer_dispatch(self)
  end

  contact.aspect_memberships.delete_all

  disconnect_contact(contact, direction: :receiving, destroy: !contact.sharing)
end

#disconnected_by(person) ⇒ Object


50
51
52
53
# File 'app/models/user/connecting.rb', line 50

def disconnected_by(person)
  logger.info "event=disconnected_by user=#{diaspora_handle} target=#{person.diaspora_handle}"
  contact_for(person).try {|contact| disconnect_contact(contact, direction: :sharing, destroy: !contact.receiving) }
end

#share_with(person, aspect) ⇒ Contact

This will create a contact on the side of the sharer and the sharee.

Parameters:

  • person (Person)

    The person to start sharing with.

  • aspect (Aspect)

    The aspect to add them to.

Returns:

  • (Contact)

    The newly made contact for the passed in person.


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/models/user/connecting.rb', line 13

def share_with(person, aspect)
  return if blocks.where(person_id: person.id).exists?

  contact = contacts.find_or_initialize_by(person_id: person.id)
  return false unless contact.valid?

  needs_dispatch = !contact.receiving?
  contact.receiving = true
  contact.aspects << aspect
  contact.save

  if needs_dispatch
    Diaspora::Federation::Dispatcher.defer_dispatch(self, contact)
    deliver_profile_update(subscriber_ids: [person.id]) unless person.local?
  end

  Notifications::StartedSharing.where(recipient_id: id, target: person.id, unread: true)
                               .update_all(unread: false)

  contact
end