Publish noai, noindex or other_settings on activitypub

This commit is contained in:
KMY 2023-05-14 13:22:44 +09:00
parent a4de9fcfdb
commit 062da7f31d
5 changed files with 34 additions and 11 deletions

View file

@ -293,6 +293,14 @@ class Account < ApplicationRecord
true
end
def noindex?
user_prefers_noindex? || (settings.present? && settings['noindex']) || false
end
def noai?
user&.setting_noai || (settings.present? && settings['noai']) || false
end
def previous_strikes_count
strikes.where(overruled_at: nil).count
end

View file

@ -7,13 +7,14 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer
context :security
context_extensions :manually_approves_followers, :featured, :also_known_as,
:moved_to, :property_value, :discoverable, :olm, :suspended, :searchable_by, :subscribable_by
:moved_to, :property_value, :discoverable, :olm, :suspended, :searchable_by, :subscribable_by,
:other_setting
attributes :id, :type, :following, :followers,
:inbox, :outbox, :featured, :featured_tags,
:preferred_username, :name, :summary,
:url, :manually_approves_followers,
:discoverable, :published, :searchable_by, :subscribable_by, :obher_setting
:discoverable, :published, :searchable_by, :subscribable_by, :other_setting
has_one :public_key, serializer: ActivityPub::PublicKeySerializer
@ -170,6 +171,21 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer
ActivityPub::TagManager.instance.subscribable_by(object)
end
def other_setting
hash = []
if object.settings.present?
hash = object.settings.map do |k, v|
{
type: 'PropertyValue',
name: k,
value: v,
}
end
end
hash << { type: 'PropertyValue', name: 'noindex', value: object.noindex? }
hash << { type: 'PropertyValue', name: 'noai', value: object.noai? }
end
class CustomEmojiSerializer < ActivityPub::EmojiSerializer
end

View file

@ -6,7 +6,8 @@ class REST::AccountSerializer < ActiveModel::Serializer
attributes :id, :username, :acct, :display_name, :locked, :bot, :discoverable, :group, :created_at,
:note, :url, :avatar, :avatar_static, :header, :header_static, :searchability, :subscribable,
:followers_count, :following_count, :statuses_count, :last_status_at, :other_settings
:followers_count, :following_count, :statuses_count, :last_status_at, :other_settings,
:noindex, :noai
has_one :moved_to_account, key: :moved, serializer: REST::AccountSerializer, if: :moved_and_not_nested?
@ -14,8 +15,6 @@ class REST::AccountSerializer < ActiveModel::Serializer
attribute :suspended, if: :suspended?
attribute :silenced, key: :limited, if: :silenced?
attribute :noindex, if: :local?
attribute :noai, if: :local?
attribute :memorial, if: :memorial?
@ -144,11 +143,11 @@ class REST::AccountSerializer < ActiveModel::Serializer
end
def noindex
object.user_prefers_noindex?
object.noindex?
end
def noai
object.user&.setting_noai
object.noai?
end
delegate :suspended?, :silenced?, :local?, :memorial?, to: :object

View file

@ -2,10 +2,10 @@
= "#{display_name(@account)} (#{acct(@account)})"
- content_for :header_tags do
- if @account.user_prefers_noindex?
- if @account.noindex?
%meta{ name: 'robots', content: 'noindex, noarchive, noai, noimageai' }/
%meta{ name: 'CCBot', content: 'nofollow' }/
- elsif @account.user&.setting_noai
- elsif @account.noai?
%meta{ name: 'robots', content: 'noai, noimageai' }/
%meta{ name: 'CCBot', content: 'nofollow' }/

View file

@ -2,10 +2,10 @@
= t('statuses.title', name: display_name(@account), quote: truncate(@status.spoiler_text.presence || @status.text, length: 50, omission: '…', escape: false))
- content_for :header_tags do
- if @account.user_prefers_noindex?
- if @account.noindex?
%meta{ name: 'robots', content: 'noindex, noarchive, noai, noimageai' }/
%meta{ name: 'CCBot', content: 'nofollow' }/
- elsif @account.user&.setting_noai
- elsif @account.noai?
%meta{ name: 'robots', content: 'noai, noimageai' }/
%meta{ name: 'CCBot', content: 'nofollow' }/