Merge branch 'kb_development' into upstream-20231021

This commit is contained in:
KMY 2023-10-22 14:42:08 +09:00
commit b992e673c7
25 changed files with 667 additions and 114 deletions

View file

@ -5,6 +5,8 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
include Redisable
include Lockable
class AbortError < ::StandardError; end
def call(status, activity_json, object_json, request_id: nil)
raise ArgumentError, 'Status has unsaved changes' if status.changed?
@ -30,6 +32,9 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
handle_implicit_update!
end
@status
rescue AbortError
@status.reload
@status
end
@ -46,6 +51,7 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
update_poll!
update_immediate_attributes!
update_metadata!
validate_status_mentions!
create_edits!
end
@ -158,6 +164,15 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
!Admin::NgWord.reject?("#{@status_parser.spoiler_text}\n#{@status_parser.text}") && !Admin::NgWord.hashtag_reject?(@raw_tags.size)
end
def validate_status_mentions!
raise AbortError if mention_to_stranger? && Admin::NgWord.stranger_mention_reject?("#{@status.spoiler_text}\n#{@status.text}")
end
def mention_to_stranger?
@status.mentions.map(&:account).to_a.any? { |mentioned_account| mentioned_account.id != @status.account.id && !mentioned_account.following?(@status.account) } ||
(@status.thread.present? && @status.thread.account.id != @status.account.id && !@status.thread.account.following?(@status.account))
end
def update_immediate_attributes!
@status.text = @status_parser.text || ''
@status.spoiler_text = @status_parser.spoiler_text || ''
@ -247,6 +262,7 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
emoji.image_remote_url = custom_emoji_parser.image_remote_url
emoji.license = custom_emoji_parser.license
emoji.is_sensitive = custom_emoji_parser.is_sensitive
emoji.aliases = custom_emoji_parser.aliases
emoji.save
rescue Seahorse::Client::NetworkingError => e
Rails.logger.warn "Error storing emoji: #{e}"

View file

@ -16,8 +16,9 @@ module Payloadable
always_sign = options.delete(:always_sign)
payload = ActiveModelSerializers::SerializableResource.new(record, options.merge(serializer: serializer, adapter: ActivityPub::Adapter)).as_json
object = record.respond_to?(:virtual_object) ? record.virtual_object : record
bearcap = object.is_a?(String) && record.respond_to?(:type) && (record.type == 'Create' || record.type == 'Update')
if ((object.respond_to?(:sign?) && object.sign?) && signer && (always_sign || signing_enabled?)) || object.is_a?(String)
if ((object.respond_to?(:sign?) && object.sign?) && signer && (always_sign || signing_enabled?)) || bearcap
ActivityPub::LinkedDataSignature.new(payload).sign!(signer, sign_with: sign_with)
else
payload

View file

@ -214,7 +214,7 @@ class PostStatusService < BaseService
end
def mention_to_stranger?
@status.mentions.map(&:account).to_a.any? { |mentioned_account| mentioned_account.id != @account && !mentioned_account.following?(@account) } ||
@status.mentions.map(&:account).to_a.any? { |mentioned_account| mentioned_account.id != @account.id && !mentioned_account.following?(@account) } ||
(@in_reply_to && @in_reply_to.account.id != @account.id && !@in_reply_to.account.following?(@account))
end

View file

@ -35,10 +35,13 @@ class UpdateStatusService < BaseService
update_poll! if @options.key?(:poll)
update_immediate_attributes!
create_edit! unless @options[:no_history]
reset_preview_card!
process_mentions_service.call(@status)
validate_status_mentions!
end
queue_poll_notifications!
reset_preview_card!
update_metadata!
update_references!
broadcast_updates!
@ -81,6 +84,15 @@ class UpdateStatusService < BaseService
raise Mastodon::ValidationError, I18n.t('statuses.too_many_hashtags') if Admin::NgWord.hashtag_reject_with_extractor?(@options[:text])
end
def validate_status_mentions!
raise Mastodon::ValidationError, I18n.t('statuses.contains_ng_words') if mention_to_stranger? && Setting.stranger_mention_from_local_ng && Admin::NgWord.stranger_mention_reject?("#{@options[:spoiler_text]}\n#{@options[:text]}")
end
def mention_to_stranger?
@status.mentions.map(&:account).to_a.any? { |mentioned_account| mentioned_account.id != @status.account.id && !mentioned_account.following?(@status.account) } ||
(@status.thread.present? && @status.thread.account.id != @status.account.id && !@status.thread.account.following?(@status.account))
end
def validate_media!
return [] if @options[:media_ids].blank? || !@options[:media_ids].is_a?(Enumerable)
@ -167,7 +179,6 @@ class UpdateStatusService < BaseService
def update_metadata!
ProcessHashtagsService.new.call(@status)
process_mentions_service.call(@status)
@status.update(limited_scope: :circle) if process_mentions_service.mentions?
end