2017-04-11 22:00:43 +02:00
|
|
|
# frozen_string_literal: true
|
2019-02-03 03:59:51 +01:00
|
|
|
|
2017-04-11 22:00:43 +02:00
|
|
|
require 'csv'
|
|
|
|
|
|
|
|
class Export
|
2017-04-13 13:02:02 +02:00
|
|
|
attr_reader :account
|
2017-04-11 22:00:43 +02:00
|
|
|
|
2017-04-13 13:02:02 +02:00
|
|
|
def initialize(account)
|
|
|
|
@account = account
|
2017-04-11 22:00:43 +02:00
|
|
|
end
|
|
|
|
|
2020-11-19 17:48:13 +01:00
|
|
|
def to_bookmarks_csv
|
|
|
|
CSV.generate do |csv|
|
|
|
|
account.bookmarks.includes(:status).reorder(id: :desc).each do |bookmark|
|
|
|
|
csv << [ActivityPub::TagManager.instance.uri_for(bookmark.status)]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-13 13:02:02 +02:00
|
|
|
def to_blocked_accounts_csv
|
2019-01-01 13:44:04 +01:00
|
|
|
to_csv account.blocking.select(:username, :domain)
|
2017-04-13 13:02:02 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_muted_accounts_csv
|
2019-04-03 18:17:43 +02:00
|
|
|
CSV.generate(headers: ['Account address', 'Hide notifications'], write_headers: true) do |csv|
|
|
|
|
account.mute_relationships.includes(:target_account).reorder(id: :desc).each do |mute|
|
|
|
|
csv << [acct(mute.target_account), mute.hide_notifications]
|
|
|
|
end
|
|
|
|
end
|
2017-04-13 13:02:02 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_following_accounts_csv
|
2022-09-20 23:51:21 +02:00
|
|
|
CSV.generate(headers: ['Account address', 'Show boosts', 'Notify on new posts', 'Languages'], write_headers: true) do |csv|
|
2019-04-08 07:28:27 +02:00
|
|
|
account.active_relationships.includes(:target_account).reorder(id: :desc).each do |follow|
|
2022-09-20 23:51:21 +02:00
|
|
|
csv << [acct(follow.target_account), follow.show_reblogs, follow.notify, follow.languages&.join(', ')]
|
2019-04-08 07:28:27 +02:00
|
|
|
end
|
|
|
|
end
|
2019-01-01 13:44:04 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_lists_csv
|
|
|
|
CSV.generate do |csv|
|
2019-03-03 15:38:47 +01:00
|
|
|
account.owned_lists.select(:title, :id).each do |list|
|
2019-01-01 13:44:04 +01:00
|
|
|
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 13:02:02 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def to_csv(accounts)
|
2017-04-11 22:00:43 +02:00
|
|
|
CSV.generate do |csv|
|
|
|
|
accounts.each do |account|
|
2019-01-01 13:44:04 +01:00
|
|
|
csv << [acct(account)]
|
2017-04-11 22:00:43 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-01-01 13:44:04 +01:00
|
|
|
|
|
|
|
def acct(account)
|
|
|
|
account.local? ? account.local_username_and_domain : account.acct
|
|
|
|
end
|
2017-04-11 22:00:43 +02:00
|
|
|
end
|