2017-06-01 04:28:45 +10:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-12-01 22:00:41 +11:00
|
|
|
module Account::FinderConcern
|
2017-06-01 04:28:45 +10:00
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
class_methods do
|
|
|
|
def find_local!(username)
|
|
|
|
find_local(username) || raise(ActiveRecord::RecordNotFound)
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_remote!(username, domain)
|
|
|
|
find_remote(username, domain) || raise(ActiveRecord::RecordNotFound)
|
|
|
|
end
|
|
|
|
|
2019-01-05 17:17:12 +11:00
|
|
|
def representative
|
2024-02-19 22:09:43 +11:00
|
|
|
actor = Account.find(Account::INSTANCE_ACTOR_ID).tap(&:ensure_keys!)
|
2023-01-19 02:33:03 +11:00
|
|
|
actor.update!(username: 'mastodon.internal') if actor.username.include?(':')
|
|
|
|
actor
|
2021-02-10 04:12:54 +11:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
2024-02-19 22:09:43 +11:00
|
|
|
Account.create!(id: Account::INSTANCE_ACTOR_ID, actor_type: 'Application', locked: true, username: 'mastodon.internal')
|
2019-01-05 17:17:12 +11:00
|
|
|
end
|
|
|
|
|
2017-06-01 04:28:45 +10:00
|
|
|
def find_local(username)
|
|
|
|
find_remote(username, nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_remote(username, domain)
|
2024-05-29 00:11:31 +10:00
|
|
|
Account
|
|
|
|
.with_username(username)
|
|
|
|
.with_domain(domain)
|
|
|
|
.order(id: :asc)
|
|
|
|
.take
|
2017-06-01 04:28:45 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|