forked from mastodon/mastodon
-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
9 changed files
with
29 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
class GroupReblogService < BaseService | ||
include RoutingHelper | ||
|
||
ACTIVITYPUB_CONTINUOUS_SIZE = 30 | ||
|
||
def call(status) | ||
return nil if status.account.group? | ||
|
||
visibility = status.visibility.to_sym | ||
return nil unless %i(public public_unlisted unlisted login private direct).include?(visibility) | ||
return nil unless %i(public public_unlisted unlisted login).include?(visibility) | ||
|
||
accounts = status.mentions.map(&:account) | status.active_mentions.map(&:account) | ||
transcription = %i(private direct).include?(visibility) | ||
|
||
accounts.each do |account| | ||
status.mentions.map(&:account).each do |account| | ||
next unless account.local? | ||
next unless status.account.following?(account) | ||
next unless account.group? | ||
next if account.id == status.account_id | ||
next if transcription && !account.group_allow_private_message | ||
|
||
if status.account.activitypub? && ACTIVITYPUB_CONTINUOUS_SIZE.positive? | ||
next if account.group_activitypub_count >= ACTIVITYPUB_CONTINUOUS_SIZE | ||
|
||
account.group_activitypub_count = account.group_activitypub_count + 1 | ||
account.save! | ||
elsif account.group_activitypub_count.positive? | ||
account.group_activitypub_count = 0 | ||
account.save! | ||
end | ||
|
||
ReblogService.new.call(account, status, { visibility: status.visibility }) unless transcription | ||
|
||
next unless transcription | ||
|
||
username = status.account.local? ? status.account.username : "#{status.account.username}@#{status.account.domain}" | ||
|
||
media_attachments = status.media_attachments.map do |media| | ||
media.needs_redownload? ? media_proxy_url(media.id, :original) : full_asset_url(media.file.url(:original)) | ||
MediaAttachment.create( | ||
account: account, | ||
remote_url: media_url(media), | ||
thumbnail_remote_url: media_preview_url(media) | ||
).tap do |attachment| | ||
attachment.download_file! | ||
attachment.save | ||
end | ||
end | ||
|
||
text = status.account.local? ? status.text : strip_tags(status.text.gsub('<br>', "\n").gsub(%r{<br />}, "\n").gsub(%r{</p>}, "\n\n").strip) | ||
|
||
PostStatusService.new.call( | ||
account, | ||
text: "Private message by @#{username}\n\\-\\-\\-\\-\n#{text}", | ||
thread: status.thread, | ||
media_ids: media_attachments.map(&:id), | ||
sensitive: status.sensitive, | ||
spoiler_text: status.spoiler_text, | ||
visibility: :private, | ||
language: status.language, | ||
poll: status.poll, | ||
with_rate_limit: true | ||
) | ||
end | ||
end | ||
|
||
def media_url(media) | ||
if media.not_processed? | ||
nil | ||
elsif media.needs_redownload? | ||
media_proxy_url(media.id, :original) | ||
else | ||
full_asset_url(media.file.url(:original)) | ||
end | ||
end | ||
|
||
def media_preview_url(media) | ||
if media.needs_redownload? | ||
media_proxy_url(media.id, :small) | ||
elsif media.thumbnail.present? | ||
full_asset_url(media.thumbnail.url(:original)) | ||
elsif media.file.styles.key?(:small) | ||
full_asset_url(media.file.url(:small)) | ||
ReblogService.new.call(account, status, { visibility: status.visibility }) | ||
end | ||
end | ||
end |
10 changes: 10 additions & 0 deletions
10
db/migrate/20240227033337_remove_group_attrs_from_accounts.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
class RemoveGroupAttrsFromAccounts < ActiveRecord::Migration[7.1] | ||
def change | ||
safety_assured do | ||
remove_column :accounts, :group_allow_private_message, :boolean | ||
remove_column :account_stats, :group_activitypub_count, :integer | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters