From 1e5532e693d9533ee37f553aeb191e284178fa52 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sat, 25 May 2019 21:27:00 +0200 Subject: Add responsive panels to the single-column layout (#10820) * Add responsive panels to the single-column layout * Fixes * Fix not being able to save the preference * Fix code style issues * Set max-height on the compose textarea and add a link to relationship manager --- app/lib/user_settings_decorator.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'app/lib') diff --git a/app/lib/user_settings_decorator.rb b/app/lib/user_settings_decorator.rb index daeb3d936..bf2e5a962 100644 --- a/app/lib/user_settings_decorator.rb +++ b/app/lib/user_settings_decorator.rb @@ -33,6 +33,7 @@ class UserSettingsDecorator user.settings['hide_network'] = hide_network_preference if change?('setting_hide_network') user.settings['aggregate_reblogs'] = aggregate_reblogs_preference if change?('setting_aggregate_reblogs') user.settings['show_application'] = show_application_preference if change?('setting_show_application') + user.settings['advanced_layout'] = advanced_layout_preference if change?('setting_advanced_layout') end def merged_notification_emails @@ -107,6 +108,10 @@ class UserSettingsDecorator boolean_cast_setting 'setting_aggregate_reblogs' end + def advanced_layout_preference + boolean_cast_setting 'setting_advanced_layout' + end + def boolean_cast_setting(key) ActiveModel::Type::Boolean.new.cast(settings[key]) end -- cgit From 18b77224d3ce4ac6aa14278ca2dca34efb0956f5 Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Sun, 26 May 2019 15:10:33 +0200 Subject: Translate incoming remote img tags by a link --- app/lib/sanitize_config.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'app/lib') diff --git a/app/lib/sanitize_config.rb b/app/lib/sanitize_config.rb index 75c916485..a9a2351a4 100644 --- a/app/lib/sanitize_config.rb +++ b/app/lib/sanitize_config.rb @@ -19,6 +19,17 @@ class Sanitize node['class'] = class_list.join(' ') end + IMG_TAG_TRANSFORMER = lambda do |env| + node = env[:node] + + return unless env[:node_name] == 'img' + + node.name = 'a' + + node['href'] = node['src'] + node.content = "[🖼 #{node['alt'] || node['href']}]" + end + MASTODON_STRICT ||= freeze_config( elements: %w(p br span a abbr del pre blockquote code b strong u sub i em h1 h2 h3 h4 h5 ul ol li), @@ -43,6 +54,7 @@ class Sanitize transformers: [ CLASS_WHITELIST_TRANSFORMER, + IMG_TAG_TRANSFORMER, ] ) -- cgit From 07d4ecfe5e7bff09a6fbe492f477cbe2cb4a1c25 Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Sun, 26 May 2019 22:42:01 +0200 Subject: Truncate long URLs while providing alt text for inline images --- app/lib/sanitize_config.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'app/lib') diff --git a/app/lib/sanitize_config.rb b/app/lib/sanitize_config.rb index a9a2351a4..e6e861eb9 100644 --- a/app/lib/sanitize_config.rb +++ b/app/lib/sanitize_config.rb @@ -27,7 +27,15 @@ class Sanitize node.name = 'a' node['href'] = node['src'] - node.content = "[🖼 #{node['alt'] || node['href']}]" + if node['alt'].present? + node.content = "[🖼 #{node['alt']}]" + else + url = node['href'] + prefix = url.match(/\Ahttps?:\/\/(www\.)?/).to_s + text = url[prefix.length, 30] + text = text + "…" if url[prefix.length..-1].length > 30 + node.content = "[🖼 #{text}]" + end end MASTODON_STRICT ||= freeze_config( -- cgit