Module: ActivityPub::Rails::ActorConcern

Extended by:
ActiveSupport::Concern
Included in:
Actor
Defined in:
app/models/concerns/activitypub/rails/actor_concern.rb

Constant Summary collapse

USERNAME_REGEXP =
/[a-z0-9_]+([a-z0-9_\.]+[a-z0-9_]+)?/i
MENTION_REGEXP =
/(?<=^|[^\/[:word:]])@((#{USERNAME_REGEXP})(?:@[a-z0-9\.\-]+[a-z0-9]+)?)/i

Instance Method Summary collapse

Instance Method Details

#acctObject



24
25
26
# File 'app/models/concerns/activitypub/rails/actor_concern.rb', line 24

def acct
  local? ? slug : "#{slug}@#{domain}"
end

#keypairObject



40
41
42
# File 'app/models/concerns/activitypub/rails/actor_concern.rb', line 40

def keypair
  @keypair ||= OpenSSL::PKey::RSA.new(private_key || public_key)
end

#local_slug_and_domainObject



32
33
34
# File 'app/models/concerns/activitypub/rails/actor_concern.rb', line 32

def local_slug_and_domain
  "#{slug}@#{ActivityPub.local_domain}"
end

#magic_keyObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/models/concerns/activitypub/rails/actor_concern.rb', line 44

def magic_key
  modulus, exponent = [keypair.public_key.n, keypair.public_key.e].map do |component|
    result = []

    until component.zero?
      result << [component % 256].pack('C')
      component >>= 8
    end

    result.reverse.join
  end

  (['RSA'] + [modulus, exponent].map { |n| Base64.urlsafe_encode64(n) }).join('.')
end

#possibly_stale?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'app/models/concerns/activitypub/rails/actor_concern.rb', line 28

def possibly_stale?
  last_webfingered_at.nil? || last_webfingered_at <= 1.day.ago
end

#to_webfinger_sObject



36
37
38
# File 'app/models/concerns/activitypub/rails/actor_concern.rb', line 36

def to_webfinger_s
  "acct:#{local_slug_and_domain}"
end