Class: BlockService

Inherits:
Object
  • Object
show all
Defined in:
app/services/block_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ BlockService

Returns a new instance of BlockService.


4
5
6
# File 'app/services/block_service.rb', line 4

def initialize(user)
  @user = user
end

Instance Method Details

#block(person) ⇒ Object

Raises:

  • (ActiveRecord::RecordNotUnique)

8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/services/block_service.rb', line 8

def block(person)
  raise ActiveRecord::RecordNotUnique if @user.blocks.exists?(person: person)

  block = @user.blocks.create!(person: person)
  contact = @user.contact_for(person)

  if contact
    @user.disconnect(contact)
  elsif block.person.remote?
    Diaspora::Federation::Dispatcher.defer_dispatch(@user, block)
  end
end

#remove_block(block) ⇒ Object


25
26
27
28
# File 'app/services/block_service.rb', line 25

def remove_block(block)
  block.destroy
  ContactRetraction.for(block).defer_dispatch(@user)
end

#unblock(person) ⇒ Object


21
22
23
# File 'app/services/block_service.rb', line 21

def unblock(person)
  remove_block(@user.blocks.find_by!(person: person))
end