diff options
author | Thibaut Girka <thib@sitedethib.com> | 2020-11-25 15:31:45 +0100 |
---|---|---|
committer | Thibaut Girka <thib@sitedethib.com> | 2020-11-25 15:31:45 +0100 |
commit | e71b16ae2b5623dc664c79ffa7d96282af662c78 (patch) | |
tree | db77dc96f03d7e9b51e33b379dd1f1b9bebc0343 /app/models | |
parent | 24696458bf22c8529b49f89b2791e3e07583b7e0 (diff) | |
parent | 41b38b027396d50cac2cf995f2b5830c2cf592fa (diff) |
Merge branch 'master' into glitch-soc/merge-upstream
Conflicts: - `Gemfile.lock`: glitch-soc-only dependency textually too close to updated upstream dependencies. Updated to upsteam dependencies.
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/account.rb | 1 | ||||
-rw-r--r-- | app/models/concerns/account_merging.rb | 43 |
2 files changed, 44 insertions, 0 deletions
diff --git a/app/models/account.rb b/app/models/account.rb index 641e984cd..87b89df51 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -67,6 +67,7 @@ class Account < ApplicationRecord include Paginable include AccountCounters include DomainNormalizable + include AccountMerging MAX_DISPLAY_NAME_LENGTH = (ENV['MAX_DISPLAY_NAME_CHARS'] || 30).to_i MAX_NOTE_LENGTH = (ENV['MAX_BIO_CHARS'] || 500).to_i diff --git a/app/models/concerns/account_merging.rb b/app/models/concerns/account_merging.rb new file mode 100644 index 000000000..691d02e03 --- /dev/null +++ b/app/models/concerns/account_merging.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +module AccountMerging + extend ActiveSupport::Concern + + def merge_with!(other_account) + # Since it's the same remote resource, the remote resource likely + # already believes we are following/blocking, so it's safe to + # re-attribute the relationships too. However, during the presence + # of the index bug users could have *also* followed the reference + # account already, therefore mass update will not work and we need + # to check for (and skip past) uniqueness errors + + owned_classes = [ + Status, StatusPin, MediaAttachment, Poll, Report, Tombstone, Favourite, + Follow, FollowRequest, Block, Mute, AccountIdentityProof, + AccountModerationNote, AccountPin, AccountStat, ListAccount, + PollVote, Mention + ] + + owned_classes.each do |klass| + klass.where(account_id: other_account.id).find_each do |record| + begin + record.update_attribute(:account_id, id) + rescue ActiveRecord::RecordNotUnique + next + end + end + end + + target_classes = [Follow, FollowRequest, Block, Mute, AccountModerationNote, AccountPin] + + target_classes.each do |klass| + klass.where(target_account_id: other_account.id).find_each do |record| + begin + record.update_attribute(:target_account_id, id) + rescue ActiveRecord::RecordNotUnique + next + end + end + end + end +end |