2017-04-11 23:00:43 +03:00
|
|
|
# frozen_string_literal: true
|
2019-02-03 04:59:51 +02:00
|
|
|
|
2017-04-11 23:00:43 +03:00
|
|
|
require 'csv'
|
|
|
|
|
|
|
|
class Export
|
2017-04-13 14:02:02 +03:00
|
|
|
attr_reader :account
|
2017-04-11 23:00:43 +03:00
|
|
|
|
2017-04-13 14:02:02 +03:00
|
|
|
def initialize(account)
|
|
|
|
@account = account
|
2017-04-11 23:00:43 +03:00
|
|
|
end
|
|
|
|
|
2017-04-13 14:02:02 +03:00
|
|
|
def to_blocked_accounts_csv
|
2019-01-01 14:44:04 +02:00
|
|
|
to_csv account.blocking.select(:username, :domain)
|
2017-04-13 14:02:02 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_muted_accounts_csv
|
2019-01-01 14:44:04 +02:00
|
|
|
to_csv account.muting.select(:username, :domain)
|
2017-04-13 14:02:02 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_following_accounts_csv
|
2019-01-01 14:44:04 +02:00
|
|
|
to_csv account.following.select(:username, :domain)
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_lists_csv
|
|
|
|
CSV.generate do |csv|
|
|
|
|
account.owned_lists.select(:title).each do |list|
|
|
|
|
list.accounts.select(:username, :domain).each do |account|
|
|
|
|
csv << [list.title, acct(account)]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_blocked_domains_csv
|
|
|
|
CSV.generate do |csv|
|
|
|
|
account.domain_blocks.pluck(:domain).each do |domain|
|
|
|
|
csv << [domain]
|
|
|
|
end
|
|
|
|
end
|
2017-04-13 14:02:02 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def total_storage
|
|
|
|
account.media_attachments.sum(:file_file_size)
|
|
|
|
end
|
|
|
|
|
2018-08-14 22:56:17 +03:00
|
|
|
def total_statuses
|
|
|
|
account.statuses_count
|
|
|
|
end
|
|
|
|
|
2017-04-13 14:02:02 +03:00
|
|
|
def total_follows
|
2018-08-14 22:56:17 +03:00
|
|
|
account.following_count
|
|
|
|
end
|
|
|
|
|
2019-01-01 14:44:04 +02:00
|
|
|
def total_lists
|
|
|
|
account.owned_lists.count
|
|
|
|
end
|
|
|
|
|
2018-08-14 22:56:17 +03:00
|
|
|
def total_followers
|
|
|
|
account.followers_count
|
2017-04-13 14:02:02 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def total_blocks
|
|
|
|
account.blocking.count
|
|
|
|
end
|
|
|
|
|
|
|
|
def total_mutes
|
|
|
|
account.muting.count
|
|
|
|
end
|
|
|
|
|
2019-01-01 14:44:04 +02:00
|
|
|
def total_domain_blocks
|
|
|
|
account.domain_blocks.count
|
|
|
|
end
|
|
|
|
|
2017-04-13 14:02:02 +03:00
|
|
|
private
|
|
|
|
|
|
|
|
def to_csv(accounts)
|
2017-04-11 23:00:43 +03:00
|
|
|
CSV.generate do |csv|
|
|
|
|
accounts.each do |account|
|
2019-01-01 14:44:04 +02:00
|
|
|
csv << [acct(account)]
|
2017-04-11 23:00:43 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-01-01 14:44:04 +02:00
|
|
|
|
|
|
|
def acct(account)
|
|
|
|
account.local? ? account.local_username_and_domain : account.acct
|
|
|
|
end
|
2017-04-11 23:00:43 +03:00
|
|
|
end
|