2020-11-23 16:50:16 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-12-01 11:00:41 +00:00
|
|
|
module Account::Merging
|
2020-11-23 16:50:16 +00:00
|
|
|
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,
|
2021-11-26 04:58:18 +00:00
|
|
|
Follow, FollowRequest, Block, Mute,
|
2020-11-23 16:50:16 +00:00
|
|
|
AccountModerationNote, AccountPin, AccountStat, ListAccount,
|
2022-03-12 07:33:11 +00:00
|
|
|
PollVote, Mention, AccountDeletionRequest, AccountNote, FollowRecommendationSuppression,
|
2024-11-25 10:27:58 +00:00
|
|
|
Appeal, TagFollow
|
2020-11-23 16:50:16 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
owned_classes.each do |klass|
|
2023-09-05 13:37:23 +00:00
|
|
|
klass.where(account_id: other_account.id).reorder(nil).find_each do |record|
|
2023-02-18 22:09:40 +00:00
|
|
|
record.update_attribute(:account_id, id)
|
|
|
|
rescue ActiveRecord::RecordNotUnique
|
|
|
|
next
|
2020-11-23 16:50:16 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-03-22 16:21:53 +00:00
|
|
|
[
|
|
|
|
Notification, NotificationPermission, NotificationRequest
|
|
|
|
].each do |klass|
|
|
|
|
klass.where(from_account_id: other_account.id).reorder(nil).find_each do |record|
|
|
|
|
record.update_attribute(:from_account_id, id)
|
|
|
|
rescue ActiveRecord::RecordNotUnique
|
|
|
|
next
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-12-04 01:23:51 +00:00
|
|
|
target_classes = [
|
|
|
|
Follow, FollowRequest, Block, Mute, AccountModerationNote, AccountPin,
|
|
|
|
AccountNote
|
|
|
|
]
|
2020-11-23 16:50:16 +00:00
|
|
|
|
|
|
|
target_classes.each do |klass|
|
2023-09-05 13:37:23 +00:00
|
|
|
klass.where(target_account_id: other_account.id).reorder(nil).find_each do |record|
|
2023-02-18 22:09:40 +00:00
|
|
|
record.update_attribute(:target_account_id, id)
|
|
|
|
rescue ActiveRecord::RecordNotUnique
|
|
|
|
next
|
2020-11-23 16:50:16 +00:00
|
|
|
end
|
|
|
|
end
|
2020-12-02 20:20:00 +00:00
|
|
|
|
2021-05-12 21:19:44 +00:00
|
|
|
CanonicalEmailBlock.where(reference_account_id: other_account.id).find_each do |record|
|
|
|
|
record.update_attribute(:reference_account_id, id)
|
|
|
|
end
|
|
|
|
|
2022-03-12 07:33:11 +00:00
|
|
|
Appeal.where(account_warning_id: other_account.id).find_each do |record|
|
|
|
|
record.update_attribute(:account_warning_id, id)
|
|
|
|
end
|
|
|
|
|
2024-03-21 08:36:49 +00:00
|
|
|
SeveredRelationship.about_local_account(other_account).reorder(nil).find_each do |record|
|
2024-03-20 15:37:21 +00:00
|
|
|
record.update_attribute(:local_account_id, id)
|
|
|
|
rescue ActiveRecord::RecordNotUnique
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
2024-03-21 08:36:49 +00:00
|
|
|
SeveredRelationship.about_remote_account(other_account).reorder(nil).find_each do |record|
|
2024-03-20 15:37:21 +00:00
|
|
|
record.update_attribute(:remote_account_id, id)
|
|
|
|
rescue ActiveRecord::RecordNotUnique
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
2020-12-02 20:20:00 +00:00
|
|
|
# Some follow relationships have moved, so the cache is stale
|
|
|
|
Rails.cache.delete_matched("followers_hash:#{id}:*")
|
|
|
|
Rails.cache.delete_matched("relationships:#{id}:*")
|
|
|
|
Rails.cache.delete_matched("relationships:*:#{id}")
|
2020-11-23 16:50:16 +00:00
|
|
|
end
|
|
|
|
end
|