dont delete chat channel memberships multiple times (#6556)

This commit is contained in:
Molly Struve 2020-03-09 20:04:40 -04:00 committed by GitHub
parent 8e4905522d
commit 5ec96613df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,18 +3,10 @@ module Users
def self.call(user)
# We only destroy direct message channels, not open and invite-only ones
direct_channels = user.chat_channels.where(channel_type: "direct")
direct_channels.each do |direct_channel|
cleanup_memberships(direct_channel.chat_channel_memberships)
direct_channel.destroy!
end
direct_channels.each(&:destroy!)
# Clean up the banished user's remaining channel memberships
cleanup_memberships(user.chat_channel_memberships)
user.reload.chat_channel_memberships.each(&:destroy!)
end
def self.cleanup_memberships(chat_channel_memberships)
chat_channel_memberships.each(&:destroy!)
end
private_class_method :cleanup_memberships
end
end