Class: AccountMigration

Inherits:
ApplicationRecord show all
Includes:
Diaspora::Federated::Base
Defined in:
app/models/account_migration.rb

Defined Under Namespace

Classes: EphemeralUser

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Diaspora::Federated::Base

#object_to_receive

Instance Attribute Details

#old_person_diaspora_id=(value) ⇒ Object

Sets the attribute old_person_diaspora_id

Parameters:

  • value

    the value to set the attribute old_person_diaspora_id to.


15
16
17
# File 'app/models/account_migration.rb', line 15

def old_person_diaspora_id=(value)
  @old_person_diaspora_id = value
end

#old_private_keyObject

Returns the value of attribute old_private_key


14
15
16
# File 'app/models/account_migration.rb', line 14

def old_private_key
  @old_private_key
end

Instance Method Details

#newest_personObject

This method finds the newest user person profile in the migration chain. If person migrated multiple times then #new_person may point to a closed account. In this case in order to find open account we have to delegate new_person call to the next account_migration instance in the chain.


57
58
59
60
61
# File 'app/models/account_migration.rb', line 57

def newest_person
  return new_person if new_person..nil?

  new_person..newest_person
end

#perform!Object

executes a migration plan according to this AccountMigration object


30
31
32
33
34
35
36
37
# File 'app/models/account_migration.rb', line 30

def perform!
  raise "already performed" if performed?
  validate_sender if locally_initiated?
  tombstone_old_user_and_update_all_references if old_person
  dispatch if locally_initiated?
  dispatch_contacts if remotely_initiated?
  update(completed_at: Time.zone.now)
end

#performed?Boolean

Returns:

  • (Boolean)

39
40
41
# File 'app/models/account_migration.rb', line 39

def performed?
  !completed_at.nil?
end

#public?Boolean

Returns:

  • (Boolean)

21
22
23
# File 'app/models/account_migration.rb', line 21

def public?
  true
end

#receiveObject


17
18
19
# File 'app/models/account_migration.rb', line 17

def receive(*)
  perform!
end

#senderObject


25
26
27
# File 'app/models/account_migration.rb', line 25

def sender
  @sender ||= old_user || ephemeral_sender
end

#subscribersObject

We assume that migration message subscribers are people that are subscribed to a new user profile updates. Since during the migration we update contact references, this includes all the contacts of the old person. In case when a user migrated to our pod from a remote one, we include remote person to subscribers so that the new pod is informed about the migration as well.


47
48
49
50
51
# File 'app/models/account_migration.rb', line 47

def subscribers
  new_user.profile.subscribers.remote.to_a.tap do |subscribers|
    subscribers.push(old_person) if old_person&.remote?
  end
end