diff options
author | ThibG <thib@sitedethib.com> | 2020-11-25 19:01:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-25 19:01:15 +0100 |
commit | 29812c2e59e02ea5ff8e4818a38b59944e2367ba (patch) | |
tree | 481dc4c0158a2def1e41f5998ef67a4e3707bb8b /app/models/concerns | |
parent | 24696458bf22c8529b49f89b2791e3e07583b7e0 (diff) | |
parent | b9fc807115e83347ad7bb74cd3ff82841c35809a (diff) |
Merge pull request #1468 from ThibG/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app/models/concerns')
-rw-r--r-- | app/models/concerns/account_merging.rb | 43 |
1 files changed, 43 insertions, 0 deletions
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 |