@current_session = SessionActivation.find_by(session_id: cookies.signed['_session_id']) if cookies.signed['_session_id'].present?
end
- def current_theme
- return Setting.theme unless Themes.instance.names.include? current_user&.setting_theme
- current_user.setting_theme
+ def current_flavour
+ return Setting.flavour unless Themes.instance.flavours.include? current_user&.setting_flavour
+ current_user.setting_flavour
+ end
+
+ def current_skin
+ return Setting.skin unless Themes.instance.skins_for(current_flavour).include? current_user&.setting_skin
+ current_user.setting_skin
end
- def cache_collection(raw, klass)
- return raw unless klass.respond_to?(:with_includes)
-
- raw = raw.cache_ids.to_a if raw.is_a?(ActiveRecord::Relation)
- cached_keys_with_value = Rails.cache.read_multi(*raw).transform_keys(&:id)
- uncached_ids = raw.map(&:id) - cached_keys_with_value.keys
-
- klass.reload_stale_associations!(cached_keys_with_value.values) if klass.respond_to?(:reload_stale_associations!)
-
- unless uncached_ids.empty?
- uncached = klass.where(id: uncached_ids).with_includes.each_with_object({}) { |item, h| h[item.id] = item }
-
- uncached.each_value do |item|
- Rails.cache.write(item, item)
- end
- end
-
- raw.map { |item| cached_keys_with_value[item.id] || uncached[item.id] }.compact
- end
-
def respond_with_error(code)
respond_to do |format|
format.any { head code }
- format.html { render "errors/#{code}", layout: 'error', status: code }
+
+ format.html do
- set_locale
+ use_pack 'error'
+ render "errors/#{code}", layout: 'error', status: code
+ end
end
end
-
- def render_cached_json(cache_key, **options)
- options[:expires_in] ||= 3.minutes
- cache_public = options.key?(:public) ? options.delete(:public) : true
- content_type = options.delete(:content_type) || 'application/json'
-
- data = Rails.cache.fetch(cache_key, { raw: true }.merge(options)) do
- yield.to_json
- end
-
- expires_in options[:expires_in], public: cache_public
- render json: data, content_type: content_type
- end
-
- def set_cache_headers
- response.headers['Vary'] = public_fetch_mode? ? 'Accept' : 'Accept, Signature'
- end
end
if (parallaxComponents.length > 0 ) {
new Rellax('.parallax', { speed: -1 });
}
+
+ delegate(document, '.custom-emoji', 'mouseover', getEmojiAnimationHandler('data-original'));
+ delegate(document, '.custom-emoji', 'mouseout', getEmojiAnimationHandler('data-static'));
});
-
- delegate(document, '.webapp-btn', 'click', ({ target, button }) => {
- if (button !== 0) {
- return true;
- }
- window.location.href = target.href;
- return false;
- });
-
- delegate(document, '.status__content__spoiler-link', 'click', function() {
- const contentEl = this.parentNode.parentNode.querySelector('.e-content');
-
- if (contentEl.style.display === 'block') {
- contentEl.style.display = 'none';
- this.parentNode.style.marginBottom = 0;
- } else {
- contentEl.style.display = 'block';
- this.parentNode.style.marginBottom = null;
- }
-
- return false;
- });
-
- delegate(document, '.modal-button', 'click', e => {
- e.preventDefault();
-
- let href;
-
- if (e.target.nodeName !== 'A') {
- href = e.target.parentNode.href;
- } else {
- href = e.target.href;
- }
-
- window.open(href, 'mastodon-intent', 'width=445,height=600,resizable=no,menubar=no,status=no,scrollbars=yes');
- });
-
- delegate(document, '#account_display_name', 'input', ({ target }) => {
- const name = document.querySelector('.card .display-name strong');
- if (name) {
- if (target.value) {
- name.innerHTML = emojify(escapeTextContentForBrowser(target.value));
- } else {
- name.textContent = document.querySelector('#default_account_display_name').textContent;
- }
- }
- });
-
- delegate(document, '#account_avatar', 'change', ({ target }) => {
- const avatar = document.querySelector('.card .avatar img');
- const [file] = target.files || [];
- const url = file ? URL.createObjectURL(file) : avatar.dataset.originalSrc;
-
- avatar.src = url;
- });
-
- const getProfileAvatarAnimationHandler = (swapTo) => {
- //animate avatar gifs on the profile page when moused over
- return ({ target }) => {
- const swapSrc = target.getAttribute(swapTo);
- //only change the img source if autoplay is off and the image src is actually different
- if(target.getAttribute('data-autoplay') !== 'true' && target.src !== swapSrc) {
- target.src = swapSrc;
- }
- };
- };
-
- delegate(document, 'img#profile_page_avatar', 'mouseover', getProfileAvatarAnimationHandler('data-original'));
-
- delegate(document, 'img#profile_page_avatar', 'mouseout', getProfileAvatarAnimationHandler('data-static'));
-
- delegate(document, '#account_header', 'change', ({ target }) => {
- const header = document.querySelector('.card .card__img img');
- const [file] = target.files || [];
- const url = file ? URL.createObjectURL(file) : header.dataset.originalSrc;
-
- header.src = url;
- });
-
- delegate(document, '#account_locked', 'change', ({ target }) => {
- const lock = document.querySelector('.card .display-name i');
-
- if (target.checked) {
- lock.style.display = 'inline';
- } else {
- lock.style.display = 'none';
- }
- });
-
- delegate(document, '.input-copy input', 'click', ({ target }) => {
- target.focus();
- target.select();
- target.setSelectionRange(0, target.value.length);
- });
-
- delegate(document, '.input-copy button', 'click', ({ target }) => {
- const input = target.parentNode.querySelector('.input-copy__wrapper input');
-
- const oldReadOnly = input.readonly;
-
- input.readonly = false;
- input.focus();
- input.select();
- input.setSelectionRange(0, input.value.length);
-
- try {
- if (document.execCommand('copy')) {
- input.blur();
- target.parentNode.classList.add('copied');
-
- setTimeout(() => {
- target.parentNode.classList.remove('copied');
- }, 700);
- }
- } catch (err) {
- console.error(err);
- }
-
- input.readonly = oldReadOnly;
- });
}
loadPolyfills().then(main).catch(error => {