闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
1.9 KiB

  1. # frozen_string_literal: true
  2. require 'csv'
  3. class Export
  4. attr_reader :account
  5. def initialize(account)
  6. @account = account
  7. end
  8. def to_blocked_accounts_csv
  9. to_csv account.blocking.select(:username, :domain)
  10. end
  11. def to_muted_accounts_csv
  12. CSV.generate(headers: ['Account address', 'Hide notifications'], write_headers: true) do |csv|
  13. account.mute_relationships.includes(:target_account).reorder(id: :desc).each do |mute|
  14. csv << [acct(mute.target_account), mute.hide_notifications]
  15. end
  16. end
  17. end
  18. def to_following_accounts_csv
  19. CSV.generate(headers: ['Account address', 'Show boosts'], write_headers: true) do |csv|
  20. account.active_relationships.includes(:target_account).reorder(id: :desc).each do |follow|
  21. csv << [acct(follow.target_account), follow.show_reblogs]
  22. end
  23. end
  24. end
  25. def to_lists_csv
  26. CSV.generate do |csv|
  27. account.owned_lists.select(:title, :id).each do |list|
  28. list.accounts.select(:username, :domain).each do |account|
  29. csv << [list.title, acct(account)]
  30. end
  31. end
  32. end
  33. end
  34. def to_blocked_domains_csv
  35. CSV.generate do |csv|
  36. account.domain_blocks.pluck(:domain).each do |domain|
  37. csv << [domain]
  38. end
  39. end
  40. end
  41. def total_storage
  42. account.media_attachments.sum(:file_file_size)
  43. end
  44. def total_statuses
  45. account.statuses_count
  46. end
  47. def total_follows
  48. account.following_count
  49. end
  50. def total_lists
  51. account.owned_lists.count
  52. end
  53. def total_followers
  54. account.followers_count
  55. end
  56. def total_blocks
  57. account.blocking.count
  58. end
  59. def total_mutes
  60. account.muting.count
  61. end
  62. def total_domain_blocks
  63. account.domain_blocks.count
  64. end
  65. private
  66. def to_csv(accounts)
  67. CSV.generate do |csv|
  68. accounts.each do |account|
  69. csv << [acct(account)]
  70. end
  71. end
  72. end
  73. def acct(account)
  74. account.local? ? account.local_username_and_domain : account.acct
  75. end
  76. end