2017-08-08 21:52:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class ActivityPub::Activity::Create < ActivityPub::Activity
|
2022-03-26 02:53:34 +01:00
|
|
|
include FormattingHelper
|
|
|
|
|
2017-08-08 21:52:15 +02:00
|
|
|
def perform
|
2020-07-22 11:43:17 +02:00
|
|
|
dereference_object!
|
|
|
|
|
2020-06-02 19:24:53 +02:00
|
|
|
case @object['type']
|
|
|
|
when 'EncryptedMessage'
|
|
|
|
create_encrypted_message
|
|
|
|
else
|
|
|
|
create_status
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def create_encrypted_message
|
2020-08-30 12:34:20 +02:00
|
|
|
return reject_payload! if invalid_origin?(object_uri) || @options[:delivered_to_account_id].blank?
|
2020-06-02 19:24:53 +02:00
|
|
|
|
|
|
|
target_account = Account.find(@options[:delivered_to_account_id])
|
|
|
|
target_device = target_account.devices.find_by(device_id: @object.dig('to', 'deviceId'))
|
|
|
|
|
|
|
|
return if target_device.nil?
|
|
|
|
|
|
|
|
target_device.encrypted_messages.create!(
|
|
|
|
from_account: @account,
|
|
|
|
from_device_id: @object.dig('attributedTo', 'deviceId'),
|
|
|
|
type: @object['messageType'],
|
|
|
|
body: @object['cipherText'],
|
|
|
|
digest: @object.dig('digest', 'digestValue'),
|
|
|
|
message_franking: message_franking.to_token
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def message_franking
|
|
|
|
MessageFranking.new(
|
|
|
|
hmac: @object.dig('digest', 'digestValue'),
|
|
|
|
original_franking: @object['messageFranking'],
|
|
|
|
source_account_id: @account.id,
|
|
|
|
target_account_id: @options[:delivered_to_account_id],
|
|
|
|
timestamp: Time.now.utc
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_status
|
2020-08-30 12:34:20 +02:00
|
|
|
return reject_payload! if unsupported_object_type? || invalid_origin?(object_uri) || tombstone_exists? || !related_to_local_activity?
|
2017-08-08 21:52:15 +02:00
|
|
|
|
2021-04-21 04:46:09 +02:00
|
|
|
lock_or_fail("create:#{object_uri}") do
|
2021-05-11 14:19:01 +02:00
|
|
|
return if delete_arrived_first?(object_uri) || poll_vote?
|
2019-01-16 15:42:00 +01:00
|
|
|
|
2021-04-21 04:46:09 +02:00
|
|
|
@status = find_existing_status
|
2018-10-30 15:03:55 +01:00
|
|
|
|
2021-04-21 04:46:09 +02:00
|
|
|
if @status.nil?
|
|
|
|
process_status
|
|
|
|
elsif @options[:delivered_to_account_id].present?
|
|
|
|
postprocess_audience_and_deliver
|
2017-09-14 22:26:22 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@status
|
|
|
|
end
|
2017-08-08 21:52:15 +02:00
|
|
|
|
2019-11-30 19:58:00 +01:00
|
|
|
def audience_to
|
2020-08-24 14:11:47 +02:00
|
|
|
as_array(@object['to'] || @json['to']).map { |x| value_or_id(x) }
|
2019-11-30 19:58:00 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def audience_cc
|
2020-08-24 14:11:47 +02:00
|
|
|
as_array(@object['cc'] || @json['cc']).map { |x| value_or_id(x) }
|
2019-11-30 19:58:00 +01:00
|
|
|
end
|
|
|
|
|
2017-09-14 22:26:22 +02:00
|
|
|
def process_status
|
2022-01-19 22:37:27 +01:00
|
|
|
@tags = []
|
|
|
|
@mentions = []
|
|
|
|
@silenced_account_ids = []
|
|
|
|
@params = {}
|
2017-12-10 16:33:52 +01:00
|
|
|
|
2018-10-11 00:50:18 +02:00
|
|
|
process_status_params
|
|
|
|
process_tags
|
2018-10-17 17:13:04 +02:00
|
|
|
process_audience
|
2017-08-08 21:52:15 +02:00
|
|
|
|
2018-10-11 00:50:18 +02:00
|
|
|
ApplicationRecord.transaction do
|
|
|
|
@status = Status.create!(@params)
|
|
|
|
attach_tags(@status)
|
2017-08-08 21:52:15 +02:00
|
|
|
end
|
|
|
|
|
2017-09-14 22:26:22 +02:00
|
|
|
resolve_thread(@status)
|
2019-02-28 15:22:21 +01:00
|
|
|
fetch_replies(@status)
|
2022-01-19 22:37:27 +01:00
|
|
|
distribute
|
2020-08-30 12:34:20 +02:00
|
|
|
forward_for_reply
|
2017-08-08 21:52:15 +02:00
|
|
|
end
|
|
|
|
|
2022-01-19 22:37:27 +01:00
|
|
|
def distribute
|
|
|
|
# Spread out crawling randomly to avoid DDoSing the link
|
|
|
|
LinkCrawlWorker.perform_in(rand(1..59).seconds, @status.id)
|
|
|
|
|
|
|
|
# Distribute into home and list feeds and notify mentioned accounts
|
2022-01-28 00:43:56 +01:00
|
|
|
::DistributionWorker.perform_async(@status.id, { 'silenced_account_ids' => @silenced_account_ids }) if @options[:override_timestamps] || @status.within_realtime_window?
|
2022-01-19 22:37:27 +01:00
|
|
|
end
|
|
|
|
|
2017-08-17 21:35:00 +02:00
|
|
|
def find_existing_status
|
2017-09-01 21:00:43 +02:00
|
|
|
status = status_from_uri(object_uri)
|
2017-09-02 14:01:23 +02:00
|
|
|
status ||= Status.find_by(uri: @object['atomUri']) if @object['atomUri'].present?
|
2017-08-17 21:35:00 +02:00
|
|
|
status
|
|
|
|
end
|
|
|
|
|
2018-03-08 01:22:47 +01:00
|
|
|
def process_status_params
|
2022-01-19 22:37:27 +01:00
|
|
|
@status_parser = ActivityPub::Parser::StatusParser.new(@json, followers_collection: @account.followers_url)
|
|
|
|
|
2018-10-11 00:50:18 +02:00
|
|
|
@params = begin
|
|
|
|
{
|
2022-01-19 22:37:27 +01:00
|
|
|
uri: @status_parser.uri,
|
|
|
|
url: @status_parser.url || @status_parser.uri,
|
2018-10-11 00:50:18 +02:00
|
|
|
account: @account,
|
2022-01-19 22:37:27 +01:00
|
|
|
text: converted_object_type? ? converted_text : (@status_parser.text || ''),
|
2022-02-08 02:41:17 +01:00
|
|
|
language: @status_parser.language,
|
2022-01-19 22:37:27 +01:00
|
|
|
spoiler_text: converted_object_type? ? '' : (@status_parser.spoiler_text || ''),
|
|
|
|
created_at: @status_parser.created_at,
|
|
|
|
edited_at: @status_parser.edited_at,
|
2018-10-11 00:50:18 +02:00
|
|
|
override_timestamps: @options[:override_timestamps],
|
2022-01-19 22:37:27 +01:00
|
|
|
reply: @status_parser.reply,
|
|
|
|
sensitive: @account.sensitized? || @status_parser.sensitive || false,
|
|
|
|
visibility: @status_parser.visibility,
|
2018-10-11 00:50:18 +02:00
|
|
|
thread: replied_to_status,
|
2019-07-28 17:47:37 +02:00
|
|
|
conversation: conversation_from_uri(@object['conversation']),
|
2018-10-11 00:50:18 +02:00
|
|
|
media_attachment_ids: process_attachments.take(4).map(&:id),
|
2019-03-28 04:44:59 +01:00
|
|
|
poll: process_poll,
|
2018-10-11 00:50:18 +02:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-10-17 17:13:04 +02:00
|
|
|
def process_audience
|
2022-01-19 22:37:27 +01:00
|
|
|
# Unlike with tags, there is no point in resolving accounts we don't already
|
|
|
|
# know here, because silent mentions would only be used for local access control anyway
|
|
|
|
accounts_in_audience = (audience_to + audience_cc).uniq.filter_map do |audience|
|
|
|
|
account_from_uri(audience) unless ActivityPub::TagManager.instance.public_collection?(audience)
|
|
|
|
end
|
2018-10-17 17:13:04 +02:00
|
|
|
|
2022-01-19 22:37:27 +01:00
|
|
|
# If the payload was delivered to a specific inbox, the inbox owner must have
|
|
|
|
# access to it, unless they already have access to it anyway
|
|
|
|
if @options[:delivered_to_account_id]
|
|
|
|
accounts_in_audience << delivered_to_account
|
|
|
|
accounts_in_audience.uniq!
|
|
|
|
end
|
2018-10-17 17:13:04 +02:00
|
|
|
|
2022-01-19 22:37:27 +01:00
|
|
|
accounts_in_audience.each do |account|
|
|
|
|
# This runs after tags are processed, and those translate into non-silent
|
|
|
|
# mentions, which take precedence
|
|
|
|
next if @mentions.any? { |mention| mention.account_id == account.id }
|
2018-10-17 17:13:04 +02:00
|
|
|
|
|
|
|
@mentions << Mention.new(account: account, silent: true)
|
|
|
|
|
|
|
|
# If there is at least one silent mention, then the status can be considered
|
2018-10-25 18:12:22 +02:00
|
|
|
# as a limited-audience status, and not strictly a direct message, but only
|
|
|
|
# if we considered a direct message in the first place
|
2022-01-19 22:37:27 +01:00
|
|
|
@params[:visibility] = :limited if @params[:visibility] == :direct
|
2018-10-17 17:13:04 +02:00
|
|
|
end
|
2018-10-25 18:12:22 +02:00
|
|
|
|
2022-01-19 22:37:27 +01:00
|
|
|
# Accounts that are tagged but are not in the audience are not
|
|
|
|
# supposed to be notified explicitly
|
|
|
|
@silenced_account_ids = @mentions.map(&:account_id) - accounts_in_audience.map(&:id)
|
2018-10-17 17:13:04 +02:00
|
|
|
end
|
|
|
|
|
2018-10-30 15:03:55 +01:00
|
|
|
def postprocess_audience_and_deliver
|
|
|
|
return if @status.mentions.find_by(account_id: @options[:delivered_to_account_id])
|
|
|
|
|
|
|
|
@status.mentions.create(account: delivered_to_account, silent: true)
|
|
|
|
@status.update(visibility: :limited) if @status.direct_visibility?
|
|
|
|
|
|
|
|
return unless delivered_to_account.following?(@account)
|
|
|
|
|
2022-01-28 00:43:56 +01:00
|
|
|
FeedInsertWorker.perform_async(@status.id, delivered_to_account.id, 'home')
|
2018-10-30 15:03:55 +01:00
|
|
|
end
|
|
|
|
|
2022-01-19 22:37:27 +01:00
|
|
|
def delivered_to_account
|
|
|
|
@delivered_to_account ||= Account.find(@options[:delivered_to_account_id])
|
|
|
|
end
|
|
|
|
|
2018-10-11 00:50:18 +02:00
|
|
|
def attach_tags(status)
|
|
|
|
@tags.each do |tag|
|
|
|
|
status.tags << tag
|
2021-11-25 13:07:38 +01:00
|
|
|
tag.update(last_status_at: status.created_at) if tag.last_status_at.nil? || (tag.last_status_at < status.created_at && tag.last_status_at < 12.hours.ago)
|
2018-10-11 00:50:18 +02:00
|
|
|
end
|
|
|
|
|
2021-11-25 13:07:38 +01:00
|
|
|
# If we're processing an old status, this may register tags as being used now
|
|
|
|
# as opposed to when the status was really published, but this is probably
|
|
|
|
# not a big deal
|
|
|
|
Trends.tags.register(status)
|
|
|
|
|
2018-10-11 00:50:18 +02:00
|
|
|
@mentions.each do |mention|
|
|
|
|
mention.status = status
|
|
|
|
mention.save
|
|
|
|
end
|
2017-08-08 21:52:15 +02:00
|
|
|
end
|
|
|
|
|
2018-10-11 00:50:18 +02:00
|
|
|
def process_tags
|
2017-10-27 16:10:36 +02:00
|
|
|
return if @object['tag'].nil?
|
2017-08-08 21:52:15 +02:00
|
|
|
|
2017-10-27 16:10:36 +02:00
|
|
|
as_array(@object['tag']).each do |tag|
|
2018-05-02 12:40:24 +02:00
|
|
|
if equals_or_includes?(tag['type'], 'Hashtag')
|
2018-10-11 00:50:18 +02:00
|
|
|
process_hashtag tag
|
2018-05-02 12:40:24 +02:00
|
|
|
elsif equals_or_includes?(tag['type'], 'Mention')
|
2018-10-11 00:50:18 +02:00
|
|
|
process_mention tag
|
2018-05-02 12:40:24 +02:00
|
|
|
elsif equals_or_includes?(tag['type'], 'Emoji')
|
2018-10-11 00:50:18 +02:00
|
|
|
process_emoji tag
|
2017-08-08 21:52:15 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-10-11 00:50:18 +02:00
|
|
|
def process_hashtag(tag)
|
2017-09-25 18:33:11 +02:00
|
|
|
return if tag['name'].blank?
|
|
|
|
|
2019-07-28 05:59:51 +02:00
|
|
|
Tag.find_or_create_by_names(tag['name']) do |hashtag|
|
2019-12-17 13:31:56 +01:00
|
|
|
@tags << hashtag unless @tags.include?(hashtag) || !hashtag.valid?
|
2019-07-28 05:59:51 +02:00
|
|
|
end
|
2018-03-30 15:44:54 +02:00
|
|
|
rescue ActiveRecord::RecordInvalid
|
|
|
|
nil
|
2017-08-08 21:52:15 +02:00
|
|
|
end
|
|
|
|
|
2018-10-11 00:50:18 +02:00
|
|
|
def process_mention(tag)
|
2017-09-25 18:33:11 +02:00
|
|
|
return if tag['href'].blank?
|
|
|
|
|
2017-08-08 21:52:15 +02:00
|
|
|
account = account_from_uri(tag['href'])
|
2019-12-17 13:32:57 +01:00
|
|
|
account = ActivityPub::FetchRemoteAccountService.new.call(tag['href']) if account.nil?
|
2018-10-11 00:50:18 +02:00
|
|
|
|
2017-08-08 21:52:15 +02:00
|
|
|
return if account.nil?
|
2018-10-11 00:50:18 +02:00
|
|
|
|
2018-10-17 17:13:04 +02:00
|
|
|
@mentions << Mention.new(account: account, silent: false)
|
2017-08-08 21:52:15 +02:00
|
|
|
end
|
|
|
|
|
2018-10-11 00:50:18 +02:00
|
|
|
def process_emoji(tag)
|
2017-10-07 17:43:42 +02:00
|
|
|
return if skip_download?
|
2017-09-25 18:33:11 +02:00
|
|
|
|
2022-01-19 22:37:27 +01:00
|
|
|
custom_emoji_parser = ActivityPub::Parser::CustomEmojiParser.new(tag)
|
|
|
|
|
|
|
|
return if custom_emoji_parser.shortcode.blank? || custom_emoji_parser.image_remote_url.blank?
|
2017-09-19 02:42:40 +02:00
|
|
|
|
2022-01-19 22:37:27 +01:00
|
|
|
emoji = CustomEmoji.find_by(shortcode: custom_emoji_parser.shortcode, domain: @account.domain)
|
2017-09-19 02:42:40 +02:00
|
|
|
|
2022-01-19 22:37:27 +01:00
|
|
|
return unless emoji.nil? || custom_emoji_parser.image_remote_url != emoji.image_remote_url || (custom_emoji_parser.updated_at && custom_emoji_parser.updated_at >= emoji.updated_at)
|
|
|
|
|
|
|
|
begin
|
|
|
|
emoji ||= CustomEmoji.new(domain: @account.domain, shortcode: custom_emoji_parser.shortcode, uri: custom_emoji_parser.uri)
|
|
|
|
emoji.image_remote_url = custom_emoji_parser.image_remote_url
|
|
|
|
emoji.save
|
|
|
|
rescue Seahorse::Client::NetworkingError => e
|
|
|
|
Rails.logger.warn "Error storing emoji: #{e}"
|
|
|
|
end
|
2017-09-19 02:42:40 +02:00
|
|
|
end
|
|
|
|
|
2017-12-10 16:33:52 +01:00
|
|
|
def process_attachments
|
2018-03-08 01:22:47 +01:00
|
|
|
return [] if @object['attachment'].nil?
|
2017-08-08 21:52:15 +02:00
|
|
|
|
2017-12-10 16:33:52 +01:00
|
|
|
media_attachments = []
|
|
|
|
|
2017-10-27 16:10:36 +02:00
|
|
|
as_array(@object['attachment']).each do |attachment|
|
2022-01-19 22:37:27 +01:00
|
|
|
media_attachment_parser = ActivityPub::Parser::MediaAttachmentParser.new(attachment)
|
|
|
|
|
|
|
|
next if media_attachment_parser.remote_url.blank? || media_attachments.size >= 4
|
2017-08-08 21:52:15 +02:00
|
|
|
|
2019-09-10 15:29:12 +02:00
|
|
|
begin
|
2022-01-19 22:37:27 +01:00
|
|
|
media_attachment = MediaAttachment.create(
|
|
|
|
account: @account,
|
|
|
|
remote_url: media_attachment_parser.remote_url,
|
|
|
|
thumbnail_remote_url: media_attachment_parser.thumbnail_remote_url,
|
|
|
|
description: media_attachment_parser.description,
|
|
|
|
focus: media_attachment_parser.focus,
|
|
|
|
blurhash: media_attachment_parser.blurhash
|
|
|
|
)
|
|
|
|
|
2019-09-10 15:29:12 +02:00
|
|
|
media_attachments << media_attachment
|
2017-08-08 21:52:15 +02:00
|
|
|
|
2022-01-19 22:37:27 +01:00
|
|
|
next if unsupported_media_type?(media_attachment_parser.file_content_type) || skip_download?
|
2017-08-08 21:52:15 +02:00
|
|
|
|
2020-06-29 13:56:55 +02:00
|
|
|
media_attachment.download_file!
|
|
|
|
media_attachment.download_thumbnail!
|
2019-09-10 15:29:12 +02:00
|
|
|
media_attachment.save
|
|
|
|
rescue Mastodon::UnexpectedResponseError, HTTP::TimeoutError, HTTP::ConnectionError, OpenSSL::SSL::SSLError
|
|
|
|
RedownloadMediaWorker.perform_in(rand(30..600).seconds, media_attachment.id)
|
2021-07-21 18:34:39 +02:00
|
|
|
rescue Seahorse::Client::NetworkingError => e
|
|
|
|
Rails.logger.warn "Error storing media attachment: #{e}"
|
2019-09-10 15:29:12 +02:00
|
|
|
end
|
2017-08-08 21:52:15 +02:00
|
|
|
end
|
2017-12-10 16:33:52 +01:00
|
|
|
|
|
|
|
media_attachments
|
2017-09-25 18:33:11 +02:00
|
|
|
rescue Addressable::URI::InvalidURIError => e
|
2019-09-10 15:29:12 +02:00
|
|
|
Rails.logger.debug "Invalid URL in attachment: #{e}"
|
2017-12-10 16:33:52 +01:00
|
|
|
media_attachments
|
|
|
|
end
|
|
|
|
|
2019-03-03 22:18:23 +01:00
|
|
|
def process_poll
|
2022-01-19 22:37:27 +01:00
|
|
|
poll_parser = ActivityPub::Parser::PollParser.new(@object)
|
2019-03-03 22:18:23 +01:00
|
|
|
|
2022-01-19 22:37:27 +01:00
|
|
|
return unless poll_parser.valid?
|
2019-09-29 22:58:01 +02:00
|
|
|
|
2019-03-04 01:13:42 +01:00
|
|
|
@account.polls.new(
|
2022-01-19 22:37:27 +01:00
|
|
|
multiple: poll_parser.multiple,
|
|
|
|
expires_at: poll_parser.expires_at,
|
|
|
|
options: poll_parser.options,
|
|
|
|
cached_tallies: poll_parser.cached_tallies,
|
|
|
|
voters_count: poll_parser.voters_count
|
2019-03-03 22:18:23 +01:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def poll_vote?
|
2019-03-28 04:44:59 +01:00
|
|
|
return false if replied_to_status.nil? || replied_to_status.preloadable_poll.nil? || !replied_to_status.local? || !replied_to_status.preloadable_poll.options.include?(@object['name'])
|
2019-03-12 22:58:59 +01:00
|
|
|
|
2019-09-29 22:58:01 +02:00
|
|
|
poll_vote! unless replied_to_status.preloadable_poll.expired?
|
2019-03-12 22:58:59 +01:00
|
|
|
|
2019-03-11 00:49:31 +01:00
|
|
|
true
|
2019-03-03 22:18:23 +01:00
|
|
|
end
|
|
|
|
|
2019-09-29 22:58:01 +02:00
|
|
|
def poll_vote!
|
|
|
|
poll = replied_to_status.preloadable_poll
|
|
|
|
already_voted = true
|
2020-06-02 19:24:53 +02:00
|
|
|
|
2021-04-21 04:46:09 +02:00
|
|
|
lock_or_fail("vote:#{replied_to_status.poll_id}:#{@account.id}") do
|
|
|
|
already_voted = poll.votes.where(account: @account).exists?
|
|
|
|
poll.votes.create!(account: @account, choice: poll.options.index(@object['name']), uri: object_uri)
|
2019-09-29 22:58:01 +02:00
|
|
|
end
|
2020-06-02 19:24:53 +02:00
|
|
|
|
2019-09-29 22:58:01 +02:00
|
|
|
increment_voters_count! unless already_voted
|
|
|
|
ActivityPub::DistributePollUpdateWorker.perform_in(3.minutes, replied_to_status.id) unless replied_to_status.preloadable_poll.hide_totals?
|
|
|
|
end
|
|
|
|
|
2017-08-08 21:52:15 +02:00
|
|
|
def resolve_thread(status)
|
2018-12-26 19:15:53 +01:00
|
|
|
return unless status.reply? && status.thread.nil? && Request.valid_url?(in_reply_to_uri)
|
2020-06-02 19:24:53 +02:00
|
|
|
|
2017-08-26 19:55:10 +02:00
|
|
|
ThreadResolveWorker.perform_async(status.id, in_reply_to_uri)
|
2017-08-08 21:52:15 +02:00
|
|
|
end
|
|
|
|
|
2019-02-28 15:22:21 +01:00
|
|
|
def fetch_replies(status)
|
|
|
|
collection = @object['replies']
|
|
|
|
return if collection.nil?
|
2020-06-02 19:24:53 +02:00
|
|
|
|
2019-02-28 15:22:21 +01:00
|
|
|
replies = ActivityPub::FetchRepliesService.new.call(status, collection, false)
|
2019-03-07 01:50:37 +01:00
|
|
|
return unless replies.nil?
|
2020-06-02 19:24:53 +02:00
|
|
|
|
2019-02-28 15:22:21 +01:00
|
|
|
uri = value_or_id(collection)
|
|
|
|
ActivityPub::FetchRepliesWorker.perform_async(status.id, uri) unless uri.nil?
|
|
|
|
end
|
|
|
|
|
2019-07-28 17:47:37 +02:00
|
|
|
def conversation_from_uri(uri)
|
|
|
|
return nil if uri.nil?
|
|
|
|
return Conversation.find_by(id: OStatus::TagManager.instance.unique_tag_to_local_id(uri, 'Conversation')) if OStatus::TagManager.instance.local_id?(uri)
|
2020-06-02 19:24:53 +02:00
|
|
|
|
2019-07-28 17:47:37 +02:00
|
|
|
begin
|
|
|
|
Conversation.find_or_create_by!(uri: uri)
|
|
|
|
rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotUnique
|
|
|
|
retry
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-08 21:52:15 +02:00
|
|
|
def replied_to_status
|
2017-08-26 19:55:10 +02:00
|
|
|
return @replied_to_status if defined?(@replied_to_status)
|
|
|
|
|
|
|
|
if in_reply_to_uri.blank?
|
|
|
|
@replied_to_status = nil
|
|
|
|
else
|
|
|
|
@replied_to_status = status_from_uri(in_reply_to_uri)
|
2017-09-02 14:01:23 +02:00
|
|
|
@replied_to_status ||= status_from_uri(@object['inReplyToAtomUri']) if @object['inReplyToAtomUri'].present?
|
2017-08-26 19:55:10 +02:00
|
|
|
@replied_to_status
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def in_reply_to_uri
|
|
|
|
value_or_id(@object['inReplyTo'])
|
2017-08-08 21:52:15 +02:00
|
|
|
end
|
|
|
|
|
2022-01-19 22:37:27 +01:00
|
|
|
def converted_text
|
2022-03-26 02:53:34 +01:00
|
|
|
linkify([@status_parser.title.presence, @status_parser.spoiler_text.presence, @status_parser.url || @status_parser.uri].compact.join("\n\n"))
|
2017-11-30 04:06:20 +01:00
|
|
|
end
|
|
|
|
|
2017-08-08 21:52:15 +02:00
|
|
|
def unsupported_media_type?(mime_type)
|
2019-06-22 02:50:36 +02:00
|
|
|
mime_type.present? && !MediaAttachment.supported_mime_types.include?(mime_type)
|
2017-08-08 21:52:15 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def skip_download?
|
|
|
|
return @skip_download if defined?(@skip_download)
|
2020-06-02 19:24:53 +02:00
|
|
|
|
2019-06-22 00:13:10 +02:00
|
|
|
@skip_download ||= DomainBlock.reject_media?(@account.domain)
|
2017-08-08 21:52:15 +02:00
|
|
|
end
|
2017-08-30 15:37:02 +02:00
|
|
|
|
|
|
|
def reply_to_local?
|
|
|
|
!replied_to_status.nil? && replied_to_status.account.local?
|
|
|
|
end
|
|
|
|
|
2019-02-13 18:42:47 +01:00
|
|
|
def related_to_local_activity?
|
|
|
|
fetch? || followed_by_local_accounts? || requested_through_relay? ||
|
|
|
|
responds_to_followed_account? || addresses_local_accounts?
|
|
|
|
end
|
|
|
|
|
|
|
|
def responds_to_followed_account?
|
|
|
|
!replied_to_status.nil? && (replied_to_status.account.local? || replied_to_status.account.passive_relationships.exists?)
|
|
|
|
end
|
|
|
|
|
|
|
|
def addresses_local_accounts?
|
|
|
|
return true if @options[:delivered_to_account_id]
|
|
|
|
|
2020-08-24 14:11:47 +02:00
|
|
|
local_usernames = (audience_to + audience_cc).uniq.select { |uri| ActivityPub::TagManager.instance.local_uri?(uri) }.map { |uri| ActivityPub::TagManager.instance.uri_to_local_id(uri, :username) }
|
2019-02-13 18:42:47 +01:00
|
|
|
|
|
|
|
return false if local_usernames.empty?
|
|
|
|
|
|
|
|
Account.local.where(username: local_usernames).exists?
|
|
|
|
end
|
|
|
|
|
2020-08-30 12:34:20 +02:00
|
|
|
def tombstone_exists?
|
|
|
|
Tombstone.exists?(uri: object_uri)
|
|
|
|
end
|
|
|
|
|
2017-08-30 15:37:02 +02:00
|
|
|
def forward_for_reply
|
2020-08-30 12:34:20 +02:00
|
|
|
return unless @status.distributable? && @json['signature'].present? && reply_to_local?
|
2020-06-02 19:24:53 +02:00
|
|
|
|
2017-11-30 03:50:05 +01:00
|
|
|
ActivityPub::RawDistributionWorker.perform_async(Oj.dump(@json), replied_to_status.account_id, [@account.preferred_inbox_url])
|
2017-08-30 15:37:02 +02:00
|
|
|
end
|
2017-09-14 22:26:22 +02:00
|
|
|
|
2019-09-29 22:58:01 +02:00
|
|
|
def increment_voters_count!
|
|
|
|
poll = replied_to_status.preloadable_poll
|
2020-06-02 19:24:53 +02:00
|
|
|
|
2019-09-29 22:58:01 +02:00
|
|
|
unless poll.voters_count.nil?
|
|
|
|
poll.voters_count = poll.voters_count + 1
|
|
|
|
poll.save
|
|
|
|
end
|
|
|
|
rescue ActiveRecord::StaleObjectError
|
|
|
|
poll.reload
|
|
|
|
retry
|
|
|
|
end
|
2017-08-08 21:52:15 +02:00
|
|
|
end
|