Apply quote by parsing post body
This commit is contained in:
parent
18fe946a60
commit
f49c59bc02
2 changed files with 26 additions and 1 deletions
|
@ -73,6 +73,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
|||
@mentions = []
|
||||
@params = {}
|
||||
|
||||
process_quote
|
||||
process_status_params
|
||||
process_tags
|
||||
process_audience
|
||||
|
@ -512,6 +513,13 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
|||
@quote ||= quote_from_url(@object['quoteUrl'] || @object['_misskey_quote'])
|
||||
end
|
||||
|
||||
def process_quote
|
||||
if quote.nil? && md = @object['content']&.match(/QT:\s*\[<a href=\"([^\"]+).*?\]/)
|
||||
@quote = quote_from_url(md[1])
|
||||
@object['content'] = @object['content'].sub(/QT:\s*\[.*?\]/, '<span class="quote-inline"><br/>\1</span>')
|
||||
end
|
||||
end
|
||||
|
||||
def quote_from_url(url)
|
||||
return nil if url.nil?
|
||||
|
||||
|
|
|
@ -31,8 +31,8 @@ class PostStatusService < BaseService
|
|||
return idempotency_duplicate if idempotency_given? && idempotency_duplicate?
|
||||
|
||||
validate_media!
|
||||
preprocess_quote!
|
||||
preprocess_attributes!
|
||||
preprocess_quote!
|
||||
|
||||
if scheduled?
|
||||
schedule_status!
|
||||
|
@ -49,6 +49,19 @@ class PostStatusService < BaseService
|
|||
|
||||
private
|
||||
|
||||
def status_from_uri(uri)
|
||||
ActivityPub::TagManager.instance.uri_to_resource(uri, Status)
|
||||
end
|
||||
|
||||
def quote_from_url(url)
|
||||
return nil if url.nil?
|
||||
|
||||
quote = ResolveURLService.new.call(url)
|
||||
status_from_uri(quote.uri) if quote
|
||||
rescue
|
||||
nil
|
||||
end
|
||||
|
||||
def preprocess_attributes!
|
||||
@sensitive = (@options[:sensitive].nil? ? @account.user&.setting_default_sensitive : @options[:sensitive]) || @options[:spoiler_text].present?
|
||||
@text = @options.delete(:spoiler_text) if @text.blank? && @options[:spoiler_text].present?
|
||||
|
@ -56,6 +69,10 @@ class PostStatusService < BaseService
|
|||
@visibility = :unlisted if @visibility&.to_sym == :public && @account.silenced?
|
||||
@scheduled_at = @options[:scheduled_at]&.to_datetime
|
||||
@scheduled_at = nil if scheduled_in_the_past?
|
||||
if @quote_id.nil? && md = @text.match(/QT:\s*\[\s*(https:\/\/.+?)\s*\]/)
|
||||
@quote_id = quote_from_url(md[1])&.id
|
||||
@text.sub!(/QT:\s*\[.*?\]/, '')
|
||||
end
|
||||
rescue ArgumentError
|
||||
raise ActiveRecord::RecordInvalid
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue