diff --git a/CHANGELOG_KB.md b/CHANGELOG_KB.md index 8247373a16..37c59ee93a 100644 --- a/CHANGELOG_KB.md +++ b/CHANGELOG_KB.md @@ -4,6 +4,7 @@ ### 追加 +- カスタム絵文字の`isSensitive`値のサポート (from Misskey) - カスタム絵文字の検索用のエイリアスキーワード - アンテナの STL(ソーシャルタイムライン)モード - アカウントの投稿数、フォロー数、フォロワー数の隠蔽 diff --git a/app/javascript/mastodon/actions/importer/normalizer.js b/app/javascript/mastodon/actions/importer/normalizer.js index b030c94b31..fc279fbca5 100644 --- a/app/javascript/mastodon/actions/importer/normalizer.js +++ b/app/javascript/mastodon/actions/importer/normalizer.js @@ -91,6 +91,11 @@ export function normalizeStatus(status, normalOldStatus) { normalStatus.spoiler_text = ''; } + console.dir(normalStatus.emojis); + if (normalStatus.emojis && normalStatus.emojis.some((emoji) => emoji.is_sensitive) && !normalStatus.spoiler_text) { + normalStatus.spoiler_text = '[Contains sensitive custom emoji(s)]'; + } + const spoilerText = normalStatus.spoiler_text || ''; const searchContent = ([spoilerText, status.content].concat((status.poll && status.poll.options) ? status.poll.options.map(option => option.title) : [])).concat(status.media_attachments.map(att => att.description)).join('\n\n').replace(//g, '\n').replace(/<\/p>

/g, '\n\n'); const emojiMap = makeEmojiMap(normalStatus); diff --git a/app/lib/activitypub/activity/create.rb b/app/lib/activitypub/activity/create.rb index 689372987b..2b64b9524d 100644 --- a/app/lib/activitypub/activity/create.rb +++ b/app/lib/activitypub/activity/create.rb @@ -263,7 +263,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity 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 ||= CustomEmoji.new(domain: @account.domain, shortcode: custom_emoji_parser.shortcode, uri: custom_emoji_parser.uri, is_sensitive: custom_emoji_parser.is_sensitive) emoji.image_remote_url = custom_emoji_parser.image_remote_url emoji.save rescue Seahorse::Client::NetworkingError => e diff --git a/app/lib/activitypub/parser/custom_emoji_parser.rb b/app/lib/activitypub/parser/custom_emoji_parser.rb index 724c602150..25feb3cf11 100644 --- a/app/lib/activitypub/parser/custom_emoji_parser.rb +++ b/app/lib/activitypub/parser/custom_emoji_parser.rb @@ -24,4 +24,8 @@ class ActivityPub::Parser::CustomEmojiParser rescue ArgumentError nil end + + def is_sensitive # rubocop:disable Naming/PredicateName + (@json['isSensitive'].presence || false) + end end diff --git a/app/models/custom_emoji.rb b/app/models/custom_emoji.rb index 4855c188dc..f74e034503 100644 --- a/app/models/custom_emoji.rb +++ b/app/models/custom_emoji.rb @@ -22,6 +22,7 @@ # image_width :integer # image_height :integer # aliases :jsonb +# is_sensitive :boolean default(FALSE), not null # class CustomEmoji < ApplicationRecord diff --git a/app/serializers/rest/custom_emoji_serializer.rb b/app/serializers/rest/custom_emoji_serializer.rb index 27795f2a38..465979184f 100644 --- a/app/serializers/rest/custom_emoji_serializer.rb +++ b/app/serializers/rest/custom_emoji_serializer.rb @@ -3,7 +3,7 @@ class REST::CustomEmojiSerializer < ActiveModel::Serializer include RoutingHelper - attributes :shortcode, :url, :static_url, :visible_in_picker + attributes :shortcode, :url, :static_url, :visible_in_picker, :is_sensitive attribute :category, if: :category_loaded? attribute :width, if: :width? diff --git a/db/migrate/20230522082252_add_is_sensitive_to_custom_emojis.rb b/db/migrate/20230522082252_add_is_sensitive_to_custom_emojis.rb new file mode 100644 index 0000000000..12666eec39 --- /dev/null +++ b/db/migrate/20230522082252_add_is_sensitive_to_custom_emojis.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddIsSensitiveToCustomEmojis < ActiveRecord::Migration[6.1] + def change + add_column :custom_emojis, :is_sensitive, :boolean, null: false, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index e931742255..b362bdd571 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -12,7 +12,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2023_05_21_122642) do +ActiveRecord::Schema.define(version: 2023_05_22_082252) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -439,6 +439,7 @@ ActiveRecord::Schema.define(version: 2023_05_21_122642) do t.integer "image_width" t.integer "image_height" t.jsonb "aliases" + t.boolean "is_sensitive", default: false, null: false t.index ["shortcode", "domain"], name: "index_custom_emojis_on_shortcode_and_domain", unique: true end @@ -1488,4 +1489,4 @@ ActiveRecord::Schema.define(version: 2023_05_21_122642) do end -#rubocop:enable all +# rubocop:enable all