From 13a2abacc8f943e2b1d2da63551443887e1065b0 Mon Sep 17 00:00:00 2001 From: Claire Date: Wed, 25 Jan 2023 19:55:40 +0100 Subject: [PATCH 1/3] Add `roles` attribute to Account entities in REST API (#23255) --- app/models/status.rb | 4 ++-- app/serializers/rest/account_serializer.rb | 18 ++++++++++++++++++ spec/fabricators/user_role_fabricator.rb | 6 +++--- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/app/models/status.rb b/app/models/status.rb index fa9fb9fad3..b1c49e99a4 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -117,7 +117,7 @@ class Status < ApplicationRecord :tags, :preview_cards, :preloadable_poll, - account: [:account_stat, :user], + account: [:account_stat, user: :role], active_mentions: { account: :account_stat }, reblog: [ :application, @@ -127,7 +127,7 @@ class Status < ApplicationRecord :conversation, :status_stat, :preloadable_poll, - account: [:account_stat, :user], + account: [:account_stat, user: :role], active_mentions: { account: :account_stat }, ], thread: { account: :account_stat } diff --git a/app/serializers/rest/account_serializer.rb b/app/serializers/rest/account_serializer.rb index 6582b5bcf6..62eac1fbde 100644 --- a/app/serializers/rest/account_serializer.rb +++ b/app/serializers/rest/account_serializer.rb @@ -26,6 +26,16 @@ class REST::AccountSerializer < ActiveModel::Serializer end end + class RoleSerializer < ActiveModel::Serializer + attributes :id, :name, :color + + def id + object.id.to_s + end + end + + has_many :roles, serializer: RoleSerializer, if: :local? + class FieldSerializer < ActiveModel::Serializer include FormattingHelper @@ -114,6 +124,14 @@ class REST::AccountSerializer < ActiveModel::Serializer object.silenced? end + def roles + if object.suspended? + [] + else + [object.user.role].compact.filter { |role| role.highlighted? } + end + end + def noindex object.user_prefers_noindex? end diff --git a/spec/fabricators/user_role_fabricator.rb b/spec/fabricators/user_role_fabricator.rb index 28f76c8c47..ed0a7dc1f3 100644 --- a/spec/fabricators/user_role_fabricator.rb +++ b/spec/fabricators/user_role_fabricator.rb @@ -1,5 +1,5 @@ Fabricator(:user_role) do name "MyString" - color "MyString" - permissions "" -end \ No newline at end of file + color "" + permissions 0 +end From 20abef6590505d12aca81ed1c386804d75b8b552 Mon Sep 17 00:00:00 2001 From: neatchee Date: Thu, 26 Jan 2023 10:36:44 -0800 Subject: [PATCH 2/3] Allow users to set the trigger height for lengthy toot auto-collapse (#2070) * Allow users to set the trigger height for lengthy toot autocollapse Add a field in the glitch-soc preferences to set the exact height in pixels of a "lengthy toot" where auto-collapse is triggered Originally authored by Dean Bassett (github.com/deanveloper) Squashed 3 commits from neatchee/mastodon and returned some values to project defaults: * ef665c1df5821e684c8da3392049f33243fafa74 * 0fce108d210efe55027a3af061bfc57aaaa83843 * 998f701a2b2e37edbda7dffb11a61f67f5559b18 * Remove bad escape characters * Apply feedback from glitch-soc code review - move input width specification to CSS - adjust language for clarity * Update comments re: lengthy toot height * Fix inconsistent indentation * Use a calculated width that scales better with browser font instead of static 45px width --- .../flavours/glitch/components/status.js | 9 +++++++-- .../glitch/features/local_settings/page/index.js | 14 +++++++++++++- .../features/local_settings/page/item/index.js | 14 ++++++++++---- app/javascript/flavours/glitch/locales/en.json | 1 + .../flavours/glitch/reducers/local_settings.js | 1 + .../glitch/styles/components/local_settings.scss | 4 ++++ 6 files changed, 36 insertions(+), 7 deletions(-) diff --git a/app/javascript/flavours/glitch/components/status.js b/app/javascript/flavours/glitch/components/status.js index 409ec0adc5..cbd8eb31cd 100644 --- a/app/javascript/flavours/glitch/components/status.js +++ b/app/javascript/flavours/glitch/components/status.js @@ -224,7 +224,7 @@ class Status extends ImmutablePureComponent { // - The user has decided to collapse all notifications ('muted' // statuses). // - The user has decided to collapse long statuses and the status is - // over 400px (without media, or 650px with). + // over the user set value (default 400 without media, or 610px with). // - The status is a reply and the user has decided to collapse all // replies. // - The status contains media and the user has decided to collapse all @@ -251,10 +251,15 @@ class Status extends ImmutablePureComponent { // as it could cause surprising changes when receiving notifications if (settings.getIn(['content_warnings', 'shared_state']) && status.get('spoiler_text').length && !status.get('hidden')) return; + let autoCollapseHeight = parseInt(autoCollapseSettings.get('height')); + if (status.get('media_attachments').size && !muted) { + autoCollapseHeight += 210; + } + if (collapse || autoCollapseSettings.get('all') || (autoCollapseSettings.get('notifications') && muted) || - (autoCollapseSettings.get('lengthy') && node.clientHeight > ((status.get('media_attachments').size && !muted) ? 650 : 400)) || + (autoCollapseSettings.get('lengthy') && node.clientHeight > autoCollapseHeight) || (autoCollapseSettings.get('reblogs') && prepend === 'reblogged_by') || (autoCollapseSettings.get('replies') && status.get('in_reply_to_id', null) !== null) || (autoCollapseSettings.get('media') && !(status.get('spoiler_text').length) && status.get('media_attachments').size > 0) diff --git a/app/javascript/flavours/glitch/features/local_settings/page/index.js b/app/javascript/flavours/glitch/features/local_settings/page/index.js index d01eec811e..d1573da9c2 100644 --- a/app/javascript/flavours/glitch/features/local_settings/page/index.js +++ b/app/javascript/flavours/glitch/features/local_settings/page/index.js @@ -5,7 +5,7 @@ import ImmutablePropTypes from 'react-immutable-proptypes'; import { defineMessages, FormattedMessage, injectIntl } from 'react-intl'; // Our imports -import { expandSpoilers, disableSwiping } from 'flavours/glitch/initial_state'; +import { expandSpoilers } from 'flavours/glitch/initial_state'; import { preferenceLink } from 'flavours/glitch/utils/backend_links'; import LocalSettingsPageItem from './item'; import DeprecatedLocalSettingsPageItem from './deprecated_item'; @@ -406,6 +406,18 @@ class LocalSettingsPage extends React.PureComponent { > + + +

diff --git a/app/javascript/flavours/glitch/features/local_settings/page/item/index.js b/app/javascript/flavours/glitch/features/local_settings/page/item/index.js index 6b24e41435..86da640ba7 100644 --- a/app/javascript/flavours/glitch/features/local_settings/page/item/index.js +++ b/app/javascript/flavours/glitch/features/local_settings/page/item/index.js @@ -14,6 +14,7 @@ export default class LocalSettingsPageItem extends React.PureComponent { id: PropTypes.string.isRequired, item: PropTypes.array.isRequired, onChange: PropTypes.func.isRequired, + inputProps: PropTypes.object, options: PropTypes.arrayOf(PropTypes.shape({ value: PropTypes.string.isRequired, message: PropTypes.string.isRequired, @@ -34,7 +35,7 @@ export default class LocalSettingsPageItem extends React.PureComponent { render () { const { handleChange } = this; - const { settings, item, id, options, children, dependsOn, dependsOnNot, placeholder, disabled } = this.props; + const { settings, item, id, inputProps, options, children, dependsOn, dependsOnNot, placeholder, disabled } = this.props; let enabled = !disabled; if (dependsOn) { @@ -54,14 +55,17 @@ export default class LocalSettingsPageItem extends React.PureComponent { let optionId = `${id}--${opt.value}`; return ( @@ -103,7 +108,8 @@ export default class LocalSettingsPageItem extends React.PureComponent { checked={settings.getIn(item)} onChange={handleChange} disabled={!enabled} - /> + {...inputProps} + /> {children} diff --git a/app/javascript/flavours/glitch/locales/en.json b/app/javascript/flavours/glitch/locales/en.json index 59f2f74b1e..7c21f69c3c 100644 --- a/app/javascript/flavours/glitch/locales/en.json +++ b/app/javascript/flavours/glitch/locales/en.json @@ -103,6 +103,7 @@ "settings.auto_collapse_all": "Everything", "settings.auto_collapse_lengthy": "Lengthy toots", "settings.auto_collapse_media": "Toots with media", + "settings.auto_collapse_height": "Height (in pixels) for a toot to be considered lengthy", "settings.auto_collapse_notifications": "Notifications", "settings.auto_collapse_reblogs": "Boosts", "settings.auto_collapse_replies": "Replies", diff --git a/app/javascript/flavours/glitch/reducers/local_settings.js b/app/javascript/flavours/glitch/reducers/local_settings.js index 81ab1cb0d8..9075146f3e 100644 --- a/app/javascript/flavours/glitch/reducers/local_settings.js +++ b/app/javascript/flavours/glitch/reducers/local_settings.js @@ -37,6 +37,7 @@ const initialState = ImmutableMap({ reblogs : false, replies : false, media : false, + height : 400, }), backgrounds : ImmutableMap({ user_backgrounds : false, diff --git a/app/javascript/flavours/glitch/styles/components/local_settings.scss b/app/javascript/flavours/glitch/styles/components/local_settings.scss index db2b9f154e..f36b21e1cd 100644 --- a/app/javascript/flavours/glitch/styles/components/local_settings.scss +++ b/app/javascript/flavours/glitch/styles/components/local_settings.scss @@ -110,6 +110,10 @@ text-decoration: none; } } + + #mastodon-settings--collapsed-auto-height { + width: calc(4ch + 20px); + } } .glitch.local-settings__page__item.string, From d9a078e6d35b54804cfa696f1b2989b9769b8488 Mon Sep 17 00:00:00 2001 From: Claire Date: Thu, 26 Jan 2023 23:35:23 +0100 Subject: [PATCH 3/3] Add role badges to WebUI (#2096) * [Glitch] Add role badges to WebUI Signed-off-by: Claire * [Glitch] Ensure role name remains readable Signed-off-by: Claire Signed-off-by: Claire --- .../glitch/features/account/components/header.js | 6 ++++++ .../flavours/glitch/styles/accounts.scss | 2 +- .../glitch/styles/components/accounts.scss | 14 +++++++++++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/javascript/flavours/glitch/features/account/components/header.js b/app/javascript/flavours/glitch/features/account/components/header.js index 071d00bb4c..963ce7bf3f 100644 --- a/app/javascript/flavours/glitch/features/account/components/header.js +++ b/app/javascript/flavours/glitch/features/account/components/header.js @@ -321,6 +321,11 @@ class Header extends ImmutablePureComponent { badge = null; } + let role = null; + if (account.getIn(['roles', 0])) { + role = (
{account.getIn(['roles', 0, 'name'])}
); + } + return (
{!(suspended || hidden || account.get('moved')) && account.getIn(['relationship', 'requested_by']) && } @@ -337,6 +342,7 @@ class Header extends ImmutablePureComponent {
{!suspended && ( diff --git a/app/javascript/flavours/glitch/styles/accounts.scss b/app/javascript/flavours/glitch/styles/accounts.scss index cdc506cf45..2158a691ff 100644 --- a/app/javascript/flavours/glitch/styles/accounts.scss +++ b/app/javascript/flavours/glitch/styles/accounts.scss @@ -214,7 +214,7 @@ font-size: 12px; line-height: 12px; font-weight: 500; - color: var(--user-role-accent, $ui-secondary-color); + color: $ui-secondary-color; background-color: var(--user-role-background, rgba($ui-secondary-color, 0.1)); border: 1px solid var(--user-role-border, rgba($ui-secondary-color, 0.5)); diff --git a/app/javascript/flavours/glitch/styles/components/accounts.scss b/app/javascript/flavours/glitch/styles/components/accounts.scss index 5b3e1db1bc..c2a6593b1a 100644 --- a/app/javascript/flavours/glitch/styles/components/accounts.scss +++ b/app/javascript/flavours/glitch/styles/components/accounts.scss @@ -533,14 +533,22 @@ &__tabs { display: flex; - align-items: flex-start; + align-items: flex-end; justify-content: space-between; padding: 7px 10px; - margin-top: -55px; - gap: 8px; + margin-top: -81px; + height: 130px; overflow: hidden; margin-left: -2px; // aligns the pfp with content below + .account-role { + margin: 0 2px; + padding: 4px 0; + box-sizing: border-box; + min-width: 90px; + text-align: center; + } + &__buttons { display: flex; align-items: center;