Mastodon/app/helpers/settings_helper.rb
Claire e08c8b6933 Merge commit 'b48f907b20e2c9909665a484041845697d26f17c' into glitch-soc/merge-upstream
Conflicts:
- `app/helpers/settings_helper.rb`:
  Upstream added a new helper.
  Conflict caused by the fact there is a glitch-soc specific helper.
  Added upstream's new helper in addition to glitch-soc's.
2026-06-09 21:30:54 +02:00

88 lines
2.2 KiB
Ruby

# frozen_string_literal: true
module SettingsHelper
def filterable_languages
LanguagesHelper.sorted_locale_keys(LanguagesHelper::SUPPORTED_LOCALES.keys)
end
def ui_languages
LanguagesHelper.sorted_locale_keys(I18n.available_locales)
end
def featured_tags_hint(recently_used_tags)
recently_used_tags.present? &&
safe_join(
[
t('simple_form.hints.featured_tag.name'),
safe_join(
links_for_featured_tags(recently_used_tags),
', '
),
],
' '
)
end
def user_settings_collection(value)
UserSettings.definition_for(value)&.in || []
end
def author_attribution_name(account)
return if account.nil?
link_to(root_url, class: 'story__details__shared__author-link') do
safe_join(
[image_tag(account.avatar.url, class: 'account__avatar', size: 16, alt: ''), tag.bdi(display_name(account))]
)
end
end
def session_device_icon(session)
device = session.detection.device
if device.mobile?
'smartphone'
elsif device.tablet?
'tablet'
else
'desktop_mac'
end
end
def compact_account_link_to(account)
return if account.nil?
link_to ActivityPub::TagManager.instance.url_for(account), class: 'name-tag', title: account.acct do
safe_join([image_tag(account.avatar.url, width: 15, height: 15, alt: '', class: 'avatar'), content_tag(:span, account.acct, class: 'username')], ' ')
end
end
def default_content_type_label(content_type)
variant = content_type.split('/')[1]
safe_join(
[
t("simple_form.labels.defaults.setting_default_content_type_#{variant}"),
content_tag(:span, t("simple_form.hints.defaults.setting_default_content_type_#{variant}"), class: 'hint'),
]
)
end
def time_zone_options
ActiveSupport::TimeZone.all.map { |tz| ["(GMT#{tz.now.formatted_offset}) #{tz.name}", tz.tzinfo.name] }
end
private
def links_for_featured_tags(tags)
tags.map { |tag| post_link_to_featured_tag(tag) }
end
def post_link_to_featured_tag(tag)
link_to(
"##{tag.display_name}",
settings_featured_tags_path(featured_tag: { name: tag.name }),
method: :post
)
end
end