Merge tag 'v1.0.5+3.2.0' into hometown-v1.0.5+3.3.0
This commit is contained in:
@ -4,8 +4,8 @@ class ActivityPub::Activity
|
||||
include JsonLdHelper
|
||||
include Redisable
|
||||
|
||||
SUPPORTED_TYPES = %w(Note Question).freeze
|
||||
CONVERTED_TYPES = %w(Image Audio Video Article Page Event).freeze
|
||||
SUPPORTED_TYPES = %w(Note Question Article).freeze
|
||||
CONVERTED_TYPES = %w(Image Audio Video Page Event).freeze
|
||||
|
||||
def initialize(json, account, **options)
|
||||
@json = json
|
||||
|
@ -77,6 +77,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
||||
@mentions = []
|
||||
@params = {}
|
||||
|
||||
process_inline_images if @object['content'].present? && @object['type'] == 'Article'
|
||||
process_status_params
|
||||
process_tags
|
||||
process_audience
|
||||
@ -107,7 +108,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
||||
account: @account,
|
||||
text: text_from_content || '',
|
||||
language: detected_language,
|
||||
spoiler_text: converted_object_type? ? '' : (text_from_summary || ''),
|
||||
spoiler_text: converted_object_type? ? '' : (text_from_summary || (@object['type'] == 'Article' && text_from_name) || ''),
|
||||
created_at: @object['published'],
|
||||
override_timestamps: @options[:override_timestamps],
|
||||
reply: @object['inReplyTo'].present?,
|
||||
@ -117,10 +118,61 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
||||
conversation: conversation_from_uri(@object['conversation']),
|
||||
media_attachment_ids: process_attachments.take(4).map(&:id),
|
||||
poll: process_poll,
|
||||
activity_pub_type: @object['type']
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
class Handler < ::Ox::Sax
|
||||
attr_reader :srcs
|
||||
attr_reader :alts
|
||||
def initialize(block)
|
||||
@stack = []
|
||||
@srcs = []
|
||||
@alts = {}
|
||||
end
|
||||
|
||||
def start_element(element_name)
|
||||
@stack << [element_name, {}]
|
||||
end
|
||||
|
||||
def end_element(element_name)
|
||||
self_name, self_attributes = @stack[-1]
|
||||
if self_name == :img && !self_attributes[:src].nil?
|
||||
@srcs << self_attributes[:src]
|
||||
@alts[self_attributes[:src]] = self_attributes[:alt]
|
||||
end
|
||||
@stack.pop
|
||||
end
|
||||
|
||||
def attr(attribute_name, attribute_value)
|
||||
_name, attributes = @stack.last
|
||||
attributes[attribute_name] = attribute_value
|
||||
end
|
||||
end
|
||||
|
||||
def process_inline_images
|
||||
proc = Proc.new { |name| puts name }
|
||||
handler = Handler.new(proc)
|
||||
Ox.sax_parse(handler, @object['content'])
|
||||
handler.srcs.each do |src|
|
||||
if skip_download?
|
||||
@object['content'].gsub!(src, '')
|
||||
next
|
||||
end
|
||||
|
||||
media_attachment = MediaAttachment.create(account: @account, remote_url: src, description: handler.alts[src], focus: nil)
|
||||
media_attachment.file_remote_url = src
|
||||
media_attachment.save
|
||||
if unsupported_media_type?(media_attachment.file.content_type)
|
||||
@object['content'].gsub!(src, '')
|
||||
media_attachment.delete
|
||||
else
|
||||
@object['content'].gsub!(src, media_attachment.file.url(:small))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def process_audience
|
||||
(audience_to + audience_cc).uniq.each do |audience|
|
||||
next if audience == ActivityPub::TagManager::COLLECTIONS[:public]
|
||||
@ -391,6 +443,8 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
||||
def text_from_content
|
||||
return Formatter.instance.linkify([[text_from_name, text_from_summary.presence].compact.join("\n\n"), object_url || object_uri].join(' ')) if converted_object_type?
|
||||
|
||||
return Formatter.instance.format_article(@object['content']) if @object['content'].present? && @object['type'] == 'Article'
|
||||
|
||||
if @object['content'].present?
|
||||
@object['content']
|
||||
elsif content_language_map?
|
||||
|
@ -40,9 +40,9 @@ class FeedManager
|
||||
def filter?(timeline_type, status, receiver)
|
||||
case timeline_type
|
||||
when :home
|
||||
filter_from_home?(status, receiver.id, build_crutches(receiver.id, [status]))
|
||||
filter_from_home?(status, receiver.id, build_crutches(receiver.id, [status]), :home)
|
||||
when :list
|
||||
filter_from_list?(status, receiver) || filter_from_home?(status, receiver.account_id, build_crutches(receiver.account_id, [status]))
|
||||
filter_from_list?(status, receiver) || filter_from_home?(status, receiver.account_id, build_crutches(receiver.account_id, [status]), :list)
|
||||
when :mentions
|
||||
filter_from_mentions?(status, receiver.id)
|
||||
else
|
||||
@ -315,10 +315,17 @@ class FeedManager
|
||||
# @param [Integer] receiver_id
|
||||
# @param [Hash] crutches
|
||||
# @return [Boolean]
|
||||
def filter_from_home?(status, receiver_id, crutches)
|
||||
def filter_from_home?(status, receiver_id, crutches, timeline_type=:home)
|
||||
return false if receiver_id == status.account_id
|
||||
return true if status.reply? && (status.in_reply_to_id.nil? || status.in_reply_to_account_id.nil?)
|
||||
return true if phrase_filtered?(status, receiver_id, :home)
|
||||
# hometown: exclusive list rules
|
||||
unless timeline_type == :list
|
||||
# find all exclusive lists
|
||||
@list = List.where(account: Account.find(receiver_id), is_exclusive: true)
|
||||
# is there a list the receiver owns with this account on it? if so, return true
|
||||
return true if ListAccount.where(list: @list, account_id: status.account_id).exists?
|
||||
end
|
||||
|
||||
check_for_blocks = crutches[:active_mentions][status.id] || []
|
||||
check_for_blocks.concat([status.account_id])
|
||||
|
@ -91,6 +91,12 @@ class Formatter
|
||||
html.html_safe # rubocop:disable Rails/OutputSafety
|
||||
end
|
||||
|
||||
def format_article(text)
|
||||
text = text.gsub(/>\n+</, "><")
|
||||
text = "<span class='article-type'>#{text}</span>"
|
||||
text.html_safe # rubocop:disable Rails/OutputSafety
|
||||
end
|
||||
|
||||
def linkify(text)
|
||||
html = encode_and_link_urls(text)
|
||||
html = simple_format(html, {}, sanitize: false)
|
||||
|
@ -71,11 +71,14 @@ class Sanitize
|
||||
end
|
||||
|
||||
MASTODON_STRICT ||= freeze_config(
|
||||
elements: %w(p br span a),
|
||||
elements: %w(p br span a abbr del pre blockquote code b strong i em h1 h2 h3 h4 h5 ul ol li img),
|
||||
|
||||
attributes: {
|
||||
'a' => %w(href rel class),
|
||||
'span' => %w(class),
|
||||
'a' => %w(href rel class title),
|
||||
'span' => %w(class),
|
||||
'abbr' => %w(title),
|
||||
'blockquote' => %w(cite),
|
||||
'img' => %w(src alt),
|
||||
},
|
||||
|
||||
add_attributes: {
|
||||
@ -83,9 +86,15 @@ class Sanitize
|
||||
'rel' => 'nofollow noopener noreferrer',
|
||||
'target' => '_blank',
|
||||
},
|
||||
'span' => {
|
||||
'class' => 'article-type',
|
||||
},
|
||||
},
|
||||
|
||||
protocols: {},
|
||||
protocols: {
|
||||
'a' => { 'href' => HTTP_PROTOCOLS },
|
||||
'blockquote' => { 'cite' => HTTP_PROTOCOLS },
|
||||
},
|
||||
|
||||
transformers: [
|
||||
CLASS_WHITELIST_TRANSFORMER,
|
||||
|
Reference in New Issue
Block a user