From 062da7f31d166d51e490d216636d3e6108454d98 Mon Sep 17 00:00:00 2001 From: KMY Date: Sun, 14 May 2023 13:22:44 +0900 Subject: [PATCH] Publish noai, noindex or other_settings on activitypub --- app/models/account.rb | 8 ++++++++ .../activitypub/actor_serializer.rb | 20 +++++++++++++++++-- app/serializers/rest/account_serializer.rb | 9 ++++----- app/views/accounts/show.html.haml | 4 ++-- app/views/statuses/show.html.haml | 4 ++-- 5 files changed, 34 insertions(+), 11 deletions(-) diff --git a/app/models/account.rb b/app/models/account.rb index fa98eea1db..9e86fd9cfb 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -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 diff --git a/app/serializers/activitypub/actor_serializer.rb b/app/serializers/activitypub/actor_serializer.rb index 755bc8f03f..9b473aac35 100644 --- a/app/serializers/activitypub/actor_serializer.rb +++ b/app/serializers/activitypub/actor_serializer.rb @@ -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 diff --git a/app/serializers/rest/account_serializer.rb b/app/serializers/rest/account_serializer.rb index 8dbc3cbccb..90ff61cde7 100644 --- a/app/serializers/rest/account_serializer.rb +++ b/app/serializers/rest/account_serializer.rb @@ -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 diff --git a/app/views/accounts/show.html.haml b/app/views/accounts/show.html.haml index f1076e04b4..8dfd938cbe 100644 --- a/app/views/accounts/show.html.haml +++ b/app/views/accounts/show.html.haml @@ -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' }/ diff --git a/app/views/statuses/show.html.haml b/app/views/statuses/show.html.haml index 0290dbc361..dc0d0857a2 100644 --- a/app/views/statuses/show.html.haml +++ b/app/views/statuses/show.html.haml @@ -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' }/