mirror of
https://github.com/mastodon/mastodon.git
synced 2026-06-10 09:37:24 -05:00
Some checks failed
Bundler Audit / security (push) Has been cancelled
Check i18n / check-i18n (push) Has been cancelled
Chromatic / Check for relevant changes (push) Has been cancelled
CodeQL / Analyze (actions) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
CodeQL / Analyze (ruby) (push) Has been cancelled
Crowdin / Upload translations / upload-translations (push) Has been cancelled
Check formatting / lint (push) Has been cancelled
CSS Linting / lint (push) Has been cancelled
Haml Linting / lint (push) Has been cancelled
JavaScript Linting / lint (push) Has been cancelled
Ruby Linting / lint (push) Has been cancelled
JavaScript Testing / test (push) Has been cancelled
Historical data migration test / test (14-alpine) (push) Has been cancelled
Historical data migration test / test (15-alpine) (push) Has been cancelled
Historical data migration test / test (16-alpine) (push) Has been cancelled
Historical data migration test / test (17-alpine) (push) Has been cancelled
Ruby Testing / build (production) (push) Has been cancelled
Ruby Testing / build (test) (push) Has been cancelled
Chromatic / Run Chromatic (push) Has been cancelled
Ruby Testing / test (.ruby-version) (push) Has been cancelled
Ruby Testing / test (3.3) (push) Has been cancelled
Ruby Testing / test (3.4) (push) Has been cancelled
Ruby Testing / End to End testing (.ruby-version) (push) Has been cancelled
Ruby Testing / End to End testing (3.3) (push) Has been cancelled
Ruby Testing / End to End testing (3.4) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.19.2) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (3.4, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Has been cancelled
89 lines
2.5 KiB
Ruby
89 lines
2.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'csv'
|
|
|
|
class Export
|
|
attr_reader :account
|
|
|
|
def initialize(account)
|
|
@account = account
|
|
end
|
|
|
|
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)] if bookmark.status.present?
|
|
end
|
|
end
|
|
end
|
|
|
|
def to_blocked_accounts_csv
|
|
to_csv account.blocking.select(:username, :domain)
|
|
end
|
|
|
|
def to_muted_accounts_csv
|
|
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
|
|
end
|
|
|
|
def to_following_accounts_csv
|
|
CSV.generate(headers: ['Account address', 'Show boosts', 'Notify on new posts', 'Languages'], write_headers: true) do |csv|
|
|
account.active_relationships.includes(:target_account).reorder(id: :desc).each do |follow|
|
|
csv << [acct(follow.target_account), follow.show_reblogs, follow.notify, follow.languages&.join(', ')]
|
|
end
|
|
end
|
|
end
|
|
|
|
def to_lists_csv
|
|
CSV.generate do |csv|
|
|
account.owned_lists.select(:title, :id).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
|
|
end
|
|
|
|
def to_custom_filters_json
|
|
data_collection = { custom_filters: [] }
|
|
account.custom_filters.includes(:keywords, :statuses).order(:phrase).each do |filter|
|
|
keywords_attributes = filter.keywords.map { |k| { keyword: k.keyword, whole_word: k.whole_word } }
|
|
|
|
data_collection[:custom_filters] << {
|
|
title: filter.title,
|
|
expires_at: filter.expires_at,
|
|
context: filter.context,
|
|
action: filter.action,
|
|
keywords_attributes: keywords_attributes,
|
|
statuses: filter.statuses.map { |s| ActivityPub::TagManager.instance.uri_for(s.status) },
|
|
}
|
|
end
|
|
JSON.generate(data_collection)
|
|
end
|
|
|
|
private
|
|
|
|
def to_csv(accounts)
|
|
CSV.generate do |csv|
|
|
accounts.each do |account|
|
|
csv << [acct(account)]
|
|
end
|
|
end
|
|
end
|
|
|
|
def acct(account)
|
|
account.local? ? account.local_username_and_domain : account.acct
|
|
end
|
|
end
|