Skip to content

Commit 5e02515

Browse files
ClearlyClaireGargron
authored andcommitted
Add option to disable blurhash previews (mastodon#11188)
* Add option to disable blurhash previews * Update option text * Change options order
1 parent 62578ac commit 5e02515

10 files changed

Lines changed: 21 additions & 3 deletions

File tree

app/controllers/settings/preferences_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def user_settings_params
5454
:setting_aggregate_reblogs,
5555
:setting_show_application,
5656
:setting_advanced_layout,
57+
:setting_use_blurhash,
5758
notification_emails: %i(follow follow_request reblog favourite mention digest report pending_account),
5859
interactions: %i(must_be_follower must_be_following must_be_following_dm)
5960
)

app/javascript/mastodon/components/media_gallery.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import IconButton from './icon_button';
66
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
77
import { isIOS } from '../is_mobile';
88
import classNames from 'classnames';
9-
import { autoPlayGif, displayMedia } from '../initial_state';
9+
import { autoPlayGif, displayMedia, useBlurhash } from '../initial_state';
1010
import { decode } from 'blurhash';
1111

1212
const messages = defineMessages({
@@ -81,6 +81,8 @@ class Item extends React.PureComponent {
8181
}
8282

8383
_decode () {
84+
if (!useBlurhash) return;
85+
8486
const hash = this.props.attachment.get('blurhash');
8587
const pixels = decode(hash, 32, 32);
8688

app/javascript/mastodon/features/video/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { fromJS, is } from 'immutable';
55
import { throttle } from 'lodash';
66
import classNames from 'classnames';
77
import { isFullscreen, requestFullscreen, exitFullscreen } from '../ui/util/fullscreen';
8-
import { displayMedia } from '../../initial_state';
8+
import { displayMedia, useBlurhash } from '../../initial_state';
99
import Icon from 'mastodon/components/icon';
1010
import { decode } from 'blurhash';
1111

@@ -298,6 +298,8 @@ class Video extends React.PureComponent {
298298
}
299299

300300
_decode () {
301+
if (!useBlurhash) return;
302+
301303
const hash = this.props.blurhash;
302304
const pixels = decode(hash, 32, 32);
303305

app/javascript/mastodon/initial_state.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ export const mascot = getMeta('mascot');
2020
export const profile_directory = getMeta('profile_directory');
2121
export const isStaff = getMeta('is_staff');
2222
export const forceSingleColumn = !getMeta('advanced_layout');
23+
export const useBlurhash = getMeta('use_blurhash');
2324

2425
export default initialState;

app/lib/user_settings_decorator.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def process_update
3434
user.settings['aggregate_reblogs'] = aggregate_reblogs_preference if change?('setting_aggregate_reblogs')
3535
user.settings['show_application'] = show_application_preference if change?('setting_show_application')
3636
user.settings['advanced_layout'] = advanced_layout_preference if change?('setting_advanced_layout')
37+
user.settings['use_blurhash'] = use_blurhash_preference if change?('setting_use_blurhash')
3738
end
3839

3940
def merged_notification_emails
@@ -112,6 +113,10 @@ def advanced_layout_preference
112113
boolean_cast_setting 'setting_advanced_layout'
113114
end
114115

116+
def use_blurhash_preference
117+
boolean_cast_setting 'setting_use_blurhash'
118+
end
119+
115120
def boolean_cast_setting(key)
116121
ActiveModel::Type::Boolean.new.cast(settings[key])
117122
end

app/models/user.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class User < ApplicationRecord
106106
delegate :auto_play_gif, :default_sensitive, :unfollow_modal, :boost_modal, :delete_modal,
107107
:reduce_motion, :system_font_ui, :noindex, :theme, :display_media, :hide_network,
108108
:expand_spoilers, :default_language, :aggregate_reblogs, :show_application,
109-
:advanced_layout, to: :settings, prefix: :setting, allow_nil: false
109+
:advanced_layout, :use_blurhash, to: :settings, prefix: :setting, allow_nil: false
110110

111111
attr_reader :invite_code
112112
attr_writer :external

app/serializers/initial_state_serializer.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def meta
3232
store[:expand_spoilers] = object.current_account.user.setting_expand_spoilers
3333
store[:reduce_motion] = object.current_account.user.setting_reduce_motion
3434
store[:advanced_layout] = object.current_account.user.setting_advanced_layout
35+
store[:use_blurhash] = object.current_account.user.setting_use_blurhash
3536
store[:is_staff] = object.current_account.user.staff?
3637
end
3738

app/views/settings/preferences/appearance/show.html.haml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
.fields-group
3535
= f.input :setting_display_media, collection: ['default', 'show_all', 'hide_all'],label_method: lambda { |item| t("simple_form.hints.defaults.setting_display_media_#{item}") }, hint: false, as: :radio_buttons, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li', wrapper: :with_floating_label
3636

37+
.fields-group
38+
= f.input :setting_use_blurhash, as: :boolean, wrapper: :with_label
39+
3740
.fields-group
3841
= f.input :setting_expand_spoilers, as: :boolean, wrapper: :with_label
3942

config/locales/simple_form.en.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ en:
3434
setting_hide_network: Who you follow and who follows you will not be shown on your profile
3535
setting_noindex: Affects your public profile and status pages
3636
setting_show_application: The application you use to toot will be displayed in the detailed view of your toots
37+
setting_use_blurhash: Gradients are based on the colors of the hidden visuals but obfuscate any details
3738
username: Your username will be unique on %{domain}
3839
whole_word: When the keyword or phrase is alphanumeric only, it will only be applied if it matches the whole word
3940
featured_tag:
@@ -109,6 +110,7 @@ en:
109110
setting_system_font_ui: Use system's default font
110111
setting_theme: Site theme
111112
setting_unfollow_modal: Show confirmation dialog before unfollowing someone
113+
setting_use_blurhash: Show colorful gradients for hidden media
112114
severity: Severity
113115
type: Import type
114116
username: Username

config/settings.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ defaults: &defaults
3232
theme: 'default'
3333
aggregate_reblogs: true
3434
advanced_layout: false
35+
use_blurhash: true
3536
notification_emails:
3637
follow: false
3738
reblog: false

0 commit comments

Comments
 (0)