]>
cat aescling's git repositories - mastodon.git/blob - app/models/concerns/account_finder_concern.rb
1 # frozen_string_literal: true
3 module AccountFinderConcern
4 extend ActiveSupport
::Concern
7 def find_local!
(username
)
8 find_local(username
) || raise(ActiveRecord
::RecordNotFound)
11 def find_remote!
(username
, domain
)
12 find_remote(username
, domain
) || raise(ActiveRecord
::RecordNotFound)
17 rescue ActiveRecord
::RecordNotFound
18 Account
.create!
(id
: -99, actor_type
: 'Application', locked
: true, username
: Rails
.configuration
.x
.local_domain
)
21 def find_local(username
)
22 find_remote(username
, nil)
25 def find_remote(username
, domain
)
26 AccountFinder
.new(username
, domain
).account
31 attr_reader
:username, :domain
33 def initialize(username
, domain
)
39 scoped_accounts
.order(id
: :asc).take
45 Account
.unscoped
.tap
do |scope
|
46 scope
.merge! with_usernames
47 scope
.merge! matching_username
48 scope
.merge! matching_domain
53 Account
.where
.not(Account
.arel_table
[:username].lower
.eq
'')
57 Account
.where(Account
.arel_table
[:username].lower
.eq username
.to_s
.downcase
)
61 Account
.where(Account
.arel_table
[:domain].lower
.eq(domain
.nil? ? nil : domain
.to_s
.downcase
))
This page took 0.096808 seconds and 5 git commands to generate.