From 5e3ea221a80d7498d4939386f072d933e6b23dda Mon Sep 17 00:00:00 2001 From: multiple creatures Date: Mon, 15 Jul 2019 13:40:54 -0500 Subject: [PATCH] add `supports_chat` property, rename `adults_only` to `adult_content`, federate the kobolds~ --- .../settings/profiles_controller.rb | 2 +- app/helpers/stream_entries_helper.rb | 6 +++--- .../features/account/components/header.js | 8 ++++---- .../flavours/glitch/styles/accounts.scss | 2 +- app/javascript/mastodon/locales/en.json | 4 ++-- app/lib/activitypub/adapter.rb | 18 +++++++++++++++++- app/models/account.rb | 5 ++++- .../activitypub/actor_serializer.rb | 15 ++++----------- app/serializers/rest/account_serializer.rb | 10 +--------- .../activitypub/process_account_service.rb | 5 ++++- app/views/settings/profiles/show.html.haml | 9 +++++++-- config/locales/simple_form.en.yml | 7 ++++--- ...0531084425_add_supports_chat_to_accounts.rb | 5 +++++ .../20190714172440_add_kobolds_to_accounts.rb | 6 ++++++ ...90714172721_adults_only_to_adult_content.rb | 8 ++++++++ db/schema.rb | 5 ++++- 16 files changed, 75 insertions(+), 40 deletions(-) create mode 100644 db/migrate/20190531084425_add_supports_chat_to_accounts.rb create mode 100644 db/migrate/20190714172440_add_kobolds_to_accounts.rb create mode 100644 db/migrate/20190714172721_adults_only_to_adult_content.rb diff --git a/app/controllers/settings/profiles_controller.rb b/app/controllers/settings/profiles_controller.rb index e30079a0f..eefd48371 100644 --- a/app/controllers/settings/profiles_controller.rb +++ b/app/controllers/settings/profiles_controller.rb @@ -25,7 +25,7 @@ class Settings::ProfilesController < Settings::BaseController private def account_params - params.require(:account).permit(:display_name, :note, :avatar, :header, :replies, :locked, :hidden, :unlisted, :adults_only, :bot, :discoverable, fields_attributes: [:name, :value]) + params.require(:account).permit(:display_name, :note, :avatar, :header, :replies, :locked, :hidden, :unlisted, :supports_chat, :gently, :kobold, :adults_content, :bot, :discoverable, fields_attributes: [:name, :value]) end def set_account diff --git a/app/helpers/stream_entries_helper.rb b/app/helpers/stream_entries_helper.rb index a7d113a22..fe8505f3b 100644 --- a/app/helpers/stream_entries_helper.rb +++ b/app/helpers/stream_entries_helper.rb @@ -38,9 +38,9 @@ module StreamEntriesHelper content_tag(:div, class: 'roles') do roles = [] roles << content_tag(:div, t('accounts.roles.bot'), class: 'account-role bot') if account.bot? - roles << content_tag(:div, t('accounts.roles.adults_only'), class: 'account-role adults-only') if account.adults_only? - roles << content_tag(:div, t('accounts.roles.gentlies_kobolds'), class: 'account-role gentlies') if account.user_gentlies_kobolds? - roles << content_tag(:div, t('accounts.roles.kobold'), class: 'account-role kobold') if account.user_is_a_kobold? + roles << content_tag(:div, t('accounts.roles.adult'), class: 'account-role adult') if account.adult_content? + roles << content_tag(:div, t('accounts.roles.gently'), class: 'account-role gently') if account.gently? + roles << content_tag(:div, t('accounts.roles.kobold'), class: 'account-role kobold') if account.kobold? if (Setting.show_staff_badge && account.user_staff?) || all if all && !account.user_staff? diff --git a/app/javascript/flavours/glitch/features/account/components/header.js b/app/javascript/flavours/glitch/features/account/components/header.js index 8758c6cca..2b4adb4f5 100644 --- a/app/javascript/flavours/glitch/features/account/components/header.js +++ b/app/javascript/flavours/glitch/features/account/components/header.js @@ -190,9 +190,9 @@ class Header extends ImmutablePureComponent { const displayNameHtml = { __html: account.get('display_name_html') }; const fields = account.get('fields'); const badge_bot = account.get('bot') ? (
) : null; - const badge_ao = account.get('adults_only') ? (
) : null; - const badge_gntly_kbld = account.get('gentlies_kobolds') ? (
) : null; - const badge_kobold = account.get('is_a_kobold') ? (
) : null; + const badge_ac = account.get('adult_content') ? (
) : null; + const badge_gently = account.get('gently') ? (
) : null; + const badge_kobold = account.get('kobold') ? (
) : null; const badge_mod = account.get('role') == 'moderator' ? (
) : null; const badge_admin = account.get('role') == 'admin' ? (
) : null; const acct = account.get('acct').indexOf('@') === -1 && domain ? `${account.get('acct')}@${domain}` : account.get('acct'); @@ -226,7 +226,7 @@ class Header extends ImmutablePureComponent {

@{acct} {lockedIcon} -
{badge_admin}{badge_mod}{badge_ao}{badge_bot}{badge_gntly_kbld}{badge_kobold}
+
{badge_admin}{badge_mod}{badge_ac}{badge_bot}{badge_gently}{badge_kobold}

diff --git a/app/javascript/flavours/glitch/styles/accounts.scss b/app/javascript/flavours/glitch/styles/accounts.scss index 02e589cc0..65c7fc80c 100644 --- a/app/javascript/flavours/glitch/styles/accounts.scss +++ b/app/javascript/flavours/glitch/styles/accounts.scss @@ -223,7 +223,7 @@ border-color: rgba(lighten($error-red, 12%), 0.5); } - &.gentlies { + &.gently { color: lighten(cyan, 25%); background-color: rgba(lighten(cyan, 25%), 0.1); border-color: rgba(lighten(cyan, 25%), 0.1); diff --git a/app/javascript/mastodon/locales/en.json b/app/javascript/mastodon/locales/en.json index 9c8dbbb7d..d82863a1f 100644 --- a/app/javascript/mastodon/locales/en.json +++ b/app/javascript/mastodon/locales/en.json @@ -1,8 +1,8 @@ { "account.add_or_remove_from_list": "Add or Remove from lists", "account.badges.bot": "Bot", - "account.badges.adults_only": "🔞 Adult content", - "account.badges.gentlies_kobolds": "Gentlies kobolds", + "account.badges.adult": "🔞 Adult content", + "account.badges.gently": "Gentlies kobolds", "account.badges.kobold": "Gently the kobold", "account.block": "Block @{name}", "account.block_domain": "Hide {domain}", diff --git a/app/lib/activitypub/adapter.rb b/app/lib/activitypub/adapter.rb index 4c0231ad7..2278ecc2c 100644 --- a/app/lib/activitypub/adapter.rb +++ b/app/lib/activitypub/adapter.rb @@ -19,7 +19,23 @@ class ActivityPub::Adapter < ActiveModelSerializers::Adapter::Base focal_point: { 'toot' => 'http://joinmastodon.org/ns#', 'focalPoint' => { '@container' => '@list', '@id' => 'toot:focalPoint' } }, identity_proof: { 'toot' => 'http://joinmastodon.org/ns#', 'IdentityProof' => 'toot:IdentityProof' }, blurhash: { 'toot' => 'http://joinmastodon.org/ns#', 'blurhash' => 'toot:blurhash' }, - adults_only: { 'schema' => 'http://schema.org#', 'suggestedMinAge' => 'schema:suggestedMinAge' } + + adult_content: { + 'mp' => 'https://monsterpit.net/ns#', + 'adultContent' => 'mp:adultContent' + } + gently: { + 'mp' => 'https://monsterpit.net/ns#', + 'gently' => 'mp:gently' + } + kobold: { + 'mp' => 'https://monsterpit.net/ns#', + 'kobold' => 'mp:kobold' + } + supports_chat: { + 'mp' => 'https://monsterpit.net/ns#', + 'supportsChat' => 'mp:supportsChat' + } }.freeze def self.default_key_transform diff --git a/app/models/account.rb b/app/models/account.rb index 7040f138b..8187bc7d9 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -45,9 +45,12 @@ # unlisted :boolean default(FALSE), not null # force_unlisted :boolean default(FALSE), not null # force_sensitive :boolean default(FALSE), not null -# adults_only :boolean default(FALSE), not null +# adult_content :boolean default(FALSE), not null # silenced_at :datetime # suspended_at :datetime +# supports_chat :boolean default(FALSE), not null +# gently :boolean default(FALSE), not null +# kobold :boolean default(FALSE), not null # class Account < ApplicationRecord diff --git a/app/serializers/activitypub/actor_serializer.rb b/app/serializers/activitypub/actor_serializer.rb index 2af3c0701..a260a6f1f 100644 --- a/app/serializers/activitypub/actor_serializer.rb +++ b/app/serializers/activitypub/actor_serializer.rb @@ -7,12 +7,14 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer context_extensions :manually_approves_followers, :featured, :also_known_as, :moved_to, :property_value, :hashtag, :emoji, :identity_proof, - :adults_only + :adult_content, :gently, :kobold, :supports_chat attributes :id, :type, :following, :followers, :inbox, :outbox, :featured, :preferred_username, :name, :summary, - :url, :manually_approves_followers + :url, :manually_approves_followers, + :gently, :kobold, :adult_content, + :supports_chat has_one :public_key, serializer: ActivityPub::PublicKeySerializer @@ -21,7 +23,6 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer attribute :moved_to, if: :moved? attribute :also_known_as, if: :also_known_as? - attribute :adults_only, key: :suggestedMinAge, if: :adults_only? class EndpointsSerializer < ActivityPub::Serializer include RoutingHelper @@ -68,10 +69,6 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer account_collection_url(object, :featured) end - def adults_only - 18 - end - def endpoints object end @@ -132,10 +129,6 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer !object.also_known_as.empty? end - def adults_only? - object.adults_only - end - class CustomEmojiSerializer < ActivityPub::EmojiSerializer end diff --git a/app/serializers/rest/account_serializer.rb b/app/serializers/rest/account_serializer.rb index 7716aafde..852ecdae1 100644 --- a/app/serializers/rest/account_serializer.rb +++ b/app/serializers/rest/account_serializer.rb @@ -6,7 +6,7 @@ class REST::AccountSerializer < ActiveModel::Serializer attributes :id, :username, :acct, :display_name, :locked, :bot, :created_at, :note, :url, :avatar, :avatar_static, :header, :header_static, :followers_count, :following_count, :statuses_count, :replies, - :adults_only, :gentlies_kobolds, :is_a_kobold, :role + :adult_content, :supports_chat, :gently, :kobold, :role has_one :moved_to_account, key: :moved, serializer: REST::AccountSerializer, if: :moved_and_not_nested? has_many :emojis, serializer: REST::CustomEmojiSerializer @@ -57,14 +57,6 @@ class REST::AccountSerializer < ActiveModel::Serializer (Setting.hide_followers_count || object.user&.setting_hide_followers_count) ? -1 : object.followers_count end - def gentlies_kobolds - object.user_gentlies_kobolds? || false - end - - def is_a_kobold - object.user_is_a_kobold? || false - end - def role return 'admin' if object.user_admin? return 'moderator' if object.user_moderator? diff --git a/app/services/activitypub/process_account_service.rb b/app/services/activitypub/process_account_service.rb index 414dbfda7..6846f6d4e 100644 --- a/app/services/activitypub/process_account_service.rb +++ b/app/services/activitypub/process_account_service.rb @@ -79,7 +79,10 @@ class ActivityPub::ProcessAccountService < BaseService @account.display_name = @json['name'] || '' @account.note = @json['summary'] || '' @account.locked = @json['manuallyApprovesFollowers'] || false - @account.adults_only = @json['suggestedMinAge'].to_i >= 18 + @account.adult_content = @json['adultContent'] || (@json['suggestedMinAge'].to_i >= 18) + @account.supports_chat = @json['supportsChat'] || false + @account.gently = @json['gently'] || false + @account.kobold = @json['kobold'] || false @account.fields = property_values || {} @account.also_known_as = as_array(@json['alsoKnownAs'] || []).map { |item| value_or_id(item) } @account.actor_type = actor_type diff --git a/app/views/settings/profiles/show.html.haml b/app/views/settings/profiles/show.html.haml index 8a7ccfd37..18addcd50 100644 --- a/app/views/settings/profiles/show.html.haml +++ b/app/views/settings/profiles/show.html.haml @@ -22,16 +22,21 @@ .fields-group = f.input :locked, as: :boolean, wrapper: :with_label, hint: t('simple_form.hints.defaults.locked') - = f.input :hidden, as: :boolean, wrapper: :with_label, hint: t('simple_form.hints.defaults.hidden') + = f.input :hidden, as: :boolean, wrapper: :with_label = f.input :unlisted, as: :boolean, wrapper: :with_label, hint: t('simple_form.hints.defaults.unlisted') = f.input :replies, as: :boolean, wrapper: :with_label + = f.input :supports_chat, as: :boolean, wrapper: :with_label .fields-group - = f.input :adults_only, as: :boolean, wrapper: :with_label, hint: t('simple_form.hints.defaults.adults_only') + = f.input :adult_content, as: :boolean, wrapper: :with_label .fields-group = f.input :bot, as: :boolean, wrapper: :with_label, hint: t('simple_form.hints.defaults.bot') + .fields-group + = f.input :gently, as: :boolean, wrapper: :with_label + = f.input :kobold, as: :boolean, wrapper: :with_label + - if Setting.profile_directory .fields-group = f.input :discoverable, as: :boolean, wrapper: :with_label, hint: t('simple_form.hints.defaults.discoverable_html', min_followers: Account::MIN_FOLLOWERS_DISCOVERY, path: explore_path) diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml index 289523f3d..d0ca2160d 100644 --- a/config/locales/simple_form.en.yml +++ b/config/locales/simple_form.en.yml @@ -10,8 +10,6 @@ en: type_html: Choose what to do with %{acct} warning_preset_id: Optional. You can still add custom text to end of the preset defaults: - hidden: Toggles whether your public profile is publicaly accessible - adults_only: This account may contain mature or sensitive content unlisted: Excludes you from public repeated/admired by lists of *local* monsters autofollow: People who sign up through the invite will automatically join your pack avatar: PNG, GIF or JPG. At most %{size}. Will be downscaled to %{dimensions}px @@ -76,7 +74,10 @@ en: warning_preset_id: Use a warning preset defaults: hidden: Disable your public profile - adults_only: Adult content + adult_content: Contains adult content + supports_chat: Allow chat messages + gently: Gently the kobolds + kobold: I am a kobold unlisted: Exclude from public interaction lists replies: Show your public replies autofollow: Invite to join your pack diff --git a/db/migrate/20190531084425_add_supports_chat_to_accounts.rb b/db/migrate/20190531084425_add_supports_chat_to_accounts.rb new file mode 100644 index 000000000..4312f78d3 --- /dev/null +++ b/db/migrate/20190531084425_add_supports_chat_to_accounts.rb @@ -0,0 +1,5 @@ +class AddSupportsChatToAccounts < ActiveRecord::Migration[5.2] + def change + safety_assured { add_column :accounts, :supports_chat, :boolean, null: false, default: false } + end +end diff --git a/db/migrate/20190714172440_add_kobolds_to_accounts.rb b/db/migrate/20190714172440_add_kobolds_to_accounts.rb new file mode 100644 index 000000000..608dd2bfa --- /dev/null +++ b/db/migrate/20190714172440_add_kobolds_to_accounts.rb @@ -0,0 +1,6 @@ +class AddKoboldsToAccounts < ActiveRecord::Migration[5.2] + def change + safety_assured { add_column :accounts, :gently, :boolean, null: false, default: false } + safety_assured { add_column :accounts, :kobold, :boolean, null: false, default: false } + end +end diff --git a/db/migrate/20190714172721_adults_only_to_adult_content.rb b/db/migrate/20190714172721_adults_only_to_adult_content.rb new file mode 100644 index 000000000..c42e6fb35 --- /dev/null +++ b/db/migrate/20190714172721_adults_only_to_adult_content.rb @@ -0,0 +1,8 @@ +class AdultsOnlyToAdultContent < ActiveRecord::Migration[5.2] + def up + safety_assured { rename_column :accounts, :adults_only, :adult_content } + end + def down + safety_assured { rename_column :accounts, :adult_content, :adults_only } + end +end diff --git a/db/schema.rb b/db/schema.rb index 0cfefbf7f..5c4360422 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -148,9 +148,12 @@ ActiveRecord::Schema.define(version: 2019_05_21_003909) do t.boolean "unlisted", default: false, null: false t.boolean "force_unlisted", default: false, null: false t.boolean "force_sensitive", default: false, null: false - t.boolean "adults_only", default: false, null: false + t.boolean "adult_content", default: false, null: false t.datetime "silenced_at" t.datetime "suspended_at" + t.boolean "supports_chat", default: false, null: false + t.boolean "gently", default: false, null: false + t.boolean "kobold", default: false, null: false t.index "(((setweight(to_tsvector('simple'::regconfig, (display_name)::text), 'A'::\"char\") || setweight(to_tsvector('simple'::regconfig, (username)::text), 'B'::\"char\")) || setweight(to_tsvector('simple'::regconfig, (COALESCE(domain, ''::character varying))::text), 'C'::\"char\")))", name: "search_index", using: :gin t.index "lower((username)::text), lower((domain)::text)", name: "index_accounts_on_username_and_domain_lower", unique: true t.index ["moved_to_account_id"], name: "index_accounts_on_moved_to_account_id"