Merge upstream (#81)
This commit is contained in:
13
app/lib/activitypub/adapter.rb
Normal file
13
app/lib/activitypub/adapter.rb
Normal file
@ -0,0 +1,13 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::Adapter < ActiveModelSerializers::Adapter::Base
|
||||
def self.default_key_transform
|
||||
:camel_lower
|
||||
end
|
||||
|
||||
def serializable_hash(options = nil)
|
||||
options = serialization_options(options)
|
||||
serialized_hash = { '@context': 'https://www.w3.org/ns/activitystreams' }.merge(ActiveModelSerializers::Adapter::Attributes.new(serializer, instance_options).serializable_hash(options))
|
||||
self.class.transform_key_casing!(serialized_hash, instance_options)
|
||||
end
|
||||
end
|
69
app/lib/activitypub/tag_manager.rb
Normal file
69
app/lib/activitypub/tag_manager.rb
Normal file
@ -0,0 +1,69 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'singleton'
|
||||
|
||||
class ActivityPub::TagManager
|
||||
include Singleton
|
||||
include RoutingHelper
|
||||
|
||||
COLLECTIONS = {
|
||||
public: 'https://www.w3.org/ns/activitystreams#Public',
|
||||
}.freeze
|
||||
|
||||
def url_for(target)
|
||||
return target.url if target.respond_to?(:local?) && !target.local?
|
||||
|
||||
case target.object_type
|
||||
when :person
|
||||
short_account_url(target)
|
||||
when :note, :comment, :activity
|
||||
short_account_status_url(target.account, target)
|
||||
end
|
||||
end
|
||||
|
||||
def uri_for(target)
|
||||
return target.uri if target.respond_to?(:local?) && !target.local?
|
||||
|
||||
case target.object_type
|
||||
when :person
|
||||
account_url(target)
|
||||
when :note, :comment, :activity
|
||||
account_status_url(target.account, target)
|
||||
end
|
||||
end
|
||||
|
||||
# Primary audience of a status
|
||||
# Public statuses go out to primarily the public collection
|
||||
# Unlisted and private statuses go out primarily to the followers collection
|
||||
# Others go out only to the people they mention
|
||||
def to(status)
|
||||
case status.visibility
|
||||
when 'public'
|
||||
[COLLECTIONS[:public]]
|
||||
when 'unlisted', 'private'
|
||||
[account_followers_url(status.account)]
|
||||
when 'direct'
|
||||
status.mentions.map { |mention| uri_for(mention.account) }
|
||||
end
|
||||
end
|
||||
|
||||
# Secondary audience of a status
|
||||
# Public statuses go out to followers as well
|
||||
# Unlisted statuses go to the public as well
|
||||
# Both of those and private statuses also go to the people mentioned in them
|
||||
# Direct ones don't have a secondary audience
|
||||
def cc(status)
|
||||
cc = []
|
||||
|
||||
case status.visibility
|
||||
when 'public'
|
||||
cc << account_followers_url(status.account)
|
||||
when 'unlisted'
|
||||
cc << COLLECTIONS[:public]
|
||||
end
|
||||
|
||||
cc.concat(status.mentions.map { |mention| uri_for(mention.account) }) unless status.direct_visibility?
|
||||
|
||||
cc
|
||||
end
|
||||
end
|
@ -99,7 +99,7 @@ class FeedManager
|
||||
#return true if reggie === status.content || reggie === status.spoiler_text
|
||||
# extremely violent filtering code END
|
||||
|
||||
return true if status.reply? && status.in_reply_to_id.nil?
|
||||
return true if status.reply? && (status.in_reply_to_id.nil? || status.in_reply_to_account_id.nil?)
|
||||
|
||||
check_for_mutes = [status.account_id]
|
||||
check_for_mutes.concat([status.reblog.account_id]) if status.reblog?
|
||||
@ -126,12 +126,13 @@ class FeedManager
|
||||
end
|
||||
|
||||
def filter_from_mentions?(status, receiver_id)
|
||||
return true if receiver_id == status.account_id
|
||||
|
||||
check_for_blocks = [status.account_id]
|
||||
check_for_blocks.concat(status.mentions.pluck(:account_id))
|
||||
check_for_blocks.concat([status.in_reply_to_account]) if status.reply? && !status.in_reply_to_account_id.nil?
|
||||
|
||||
should_filter = receiver_id == status.account_id # Filter if I'm mentioning myself
|
||||
should_filter ||= Block.where(account_id: receiver_id, target_account_id: check_for_blocks).any? # or it's from someone I blocked, in reply to someone I blocked, or mentioning someone I blocked
|
||||
should_filter = Block.where(account_id: receiver_id, target_account_id: check_for_blocks).any? # Filter if it's from someone I blocked, in reply to someone I blocked, or mentioning someone I blocked
|
||||
should_filter ||= (status.account.silenced? && !Follow.where(account_id: receiver_id, target_account_id: status.account_id).exists?) # of if the account is silenced and I'm not following them
|
||||
|
||||
should_filter
|
||||
|
@ -1,11 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ProviderDiscovery < OEmbed::ProviderDiscovery
|
||||
extend HttpHelper
|
||||
|
||||
class << self
|
||||
def discover_provider(url, options = {})
|
||||
res = http_client.get(url)
|
||||
res = Request.new(:get, url).perform
|
||||
format = options[:format]
|
||||
|
||||
raise OEmbed::NotFound, url if res.code != 200 || res.mime_type != 'text/html'
|
||||
|
70
app/lib/request.rb
Normal file
70
app/lib/request.rb
Normal file
@ -0,0 +1,70 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Request
|
||||
REQUEST_TARGET = '(request-target)'
|
||||
|
||||
include RoutingHelper
|
||||
|
||||
def initialize(verb, url, options = {})
|
||||
@verb = verb
|
||||
@url = Addressable::URI.parse(url).normalize
|
||||
@options = options
|
||||
@headers = {}
|
||||
|
||||
set_common_headers!
|
||||
end
|
||||
|
||||
def on_behalf_of(account)
|
||||
raise ArgumentError unless account.local?
|
||||
@account = account
|
||||
end
|
||||
|
||||
def add_headers(new_headers)
|
||||
@headers.merge!(new_headers)
|
||||
end
|
||||
|
||||
def perform
|
||||
http_client.headers(headers).public_send(@verb, @url.to_s, @options)
|
||||
end
|
||||
|
||||
def headers
|
||||
(@account ? @headers.merge('Signature' => signature) : @headers).without(REQUEST_TARGET)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_common_headers!
|
||||
@headers[REQUEST_TARGET] = "#{@verb} #{@url.path}"
|
||||
@headers['User-Agent'] = user_agent
|
||||
@headers['Host'] = @url.host
|
||||
@headers['Date'] = Time.now.utc.httpdate
|
||||
end
|
||||
|
||||
def signature
|
||||
key_id = @account.to_webfinger_s
|
||||
algorithm = 'rsa-sha256'
|
||||
signature = Base64.strict_encode64(@account.keypair.sign(OpenSSL::Digest::SHA256.new, signed_string))
|
||||
|
||||
"keyId=\"#{key_id}\",algorithm=\"#{algorithm}\",headers=\"#{signed_headers}\",signature=\"#{signature}\""
|
||||
end
|
||||
|
||||
def signed_string
|
||||
@headers.map { |key, value| "#{key.downcase}: #{value}" }.join("\n")
|
||||
end
|
||||
|
||||
def signed_headers
|
||||
@headers.keys.join(' ').downcase
|
||||
end
|
||||
|
||||
def user_agent
|
||||
@user_agent ||= "#{HTTP::Request::USER_AGENT} (Mastodon/#{Mastodon::Version}; +#{root_url})"
|
||||
end
|
||||
|
||||
def timeout
|
||||
{ write: 10, connect: 10, read: 10 }
|
||||
end
|
||||
|
||||
def http_client
|
||||
HTTP.timeout(:per_operation, timeout).follow
|
||||
end
|
||||
end
|
@ -70,7 +70,7 @@ class TagManager
|
||||
|
||||
uri = Addressable::URI.new
|
||||
uri.host = domain.gsub(/[\/]/, '')
|
||||
uri.normalize.host
|
||||
uri.normalized_host
|
||||
end
|
||||
|
||||
def same_acct?(canonical, needle)
|
||||
|
@ -23,6 +23,7 @@ class UserSettingsDecorator
|
||||
user.settings['delete_modal'] = delete_modal_preference
|
||||
user.settings['auto_play_gif'] = auto_play_gif_preference
|
||||
user.settings['system_font_ui'] = system_font_ui_preference
|
||||
user.settings['noindex'] = noindex_preference
|
||||
end
|
||||
|
||||
def merged_notification_emails
|
||||
@ -57,6 +58,10 @@ class UserSettingsDecorator
|
||||
boolean_cast_setting 'setting_auto_play_gif'
|
||||
end
|
||||
|
||||
def noindex_preference
|
||||
boolean_cast_setting 'setting_noindex'
|
||||
end
|
||||
|
||||
def boolean_cast_setting(key)
|
||||
settings[key] == '1'
|
||||
end
|
||||
|
Reference in New Issue
Block a user