diff options
author | David Yip <yipdw@member.fsf.org> | 2017-11-16 22:52:37 -0600 |
---|---|---|
committer | David Yip <yipdw@member.fsf.org> | 2017-11-16 22:52:37 -0600 |
commit | b28b405b9763a0bb3df653b51e6d084b42e9a54d (patch) | |
tree | c69f1ccb99440fea8cc94014e77687238e205160 /app | |
parent | ee560abdbe7a2caf0f7ac6137faf248bbaff9a93 (diff) | |
parent | dc6e031364d1f47a49ea47f20070a4e9986a4c68 (diff) |
Merge remote-tracking branch 'origin/master' into gs-master
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/application_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/auth/sessions_controller.rb | 2 | ||||
-rw-r--r-- | app/helpers/admin/filter_helper.rb | 2 | ||||
-rw-r--r-- | app/javascript/styles/mastodon/accounts.scss | 18 | ||||
-rw-r--r-- | app/lib/activitypub/activity/create.rb | 2 | ||||
-rw-r--r-- | app/lib/extractor.rb | 3 | ||||
-rw-r--r-- | app/lib/language_detector.rb | 31 | ||||
-rw-r--r-- | app/models/account.rb | 2 | ||||
-rw-r--r-- | app/models/concerns/account_finder_concern.rb | 2 | ||||
-rw-r--r-- | app/models/web/push_subscription.rb | 4 | ||||
-rw-r--r-- | app/services/batched_remove_status_service.rb | 2 | ||||
-rw-r--r-- | app/services/resolve_remote_account_service.rb | 4 | ||||
-rw-r--r-- | app/views/accounts/_header.html.haml | 6 | ||||
-rw-r--r-- | app/views/settings/applications/new.html.haml | 2 | ||||
-rw-r--r-- | app/views/settings/applications/show.html.haml | 2 |
15 files changed, 61 insertions, 23 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f41a7f9be..a213302cb 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -104,7 +104,7 @@ class ApplicationController < ActionController::Base unless uncached_ids.empty? uncached = klass.where(id: uncached_ids).with_includes.map { |item| [item.id, item] }.to_h - uncached.values.each do |item| + uncached.each_value do |item| Rails.cache.write(item.cache_key, item) end end diff --git a/app/controllers/auth/sessions_controller.rb b/app/controllers/auth/sessions_controller.rb index 463a183e4..a5acb6c36 100644 --- a/app/controllers/auth/sessions_controller.rb +++ b/app/controllers/auth/sessions_controller.rb @@ -62,7 +62,7 @@ class Auth::SessionsController < Devise::SessionsController if user_params[:otp_attempt].present? && session[:otp_user_id] authenticate_with_two_factor_via_otp(user) - elsif user && user.valid_password?(user_params[:password]) + elsif user&.valid_password?(user_params[:password]) prompt_for_two_factor(user) end end diff --git a/app/helpers/admin/filter_helper.rb b/app/helpers/admin/filter_helper.rb index 6a57b3d63..e0fae9d9a 100644 --- a/app/helpers/admin/filter_helper.rb +++ b/app/helpers/admin/filter_helper.rb @@ -18,7 +18,7 @@ module Admin::FilterHelper def selected?(more_params) new_url = filtered_url_for(more_params) - filter_link_class(new_url) == 'selected' ? true : false + filter_link_class(new_url) == 'selected' end private diff --git a/app/javascript/styles/mastodon/accounts.scss b/app/javascript/styles/mastodon/accounts.scss index b00dd8c1e..24a55c7bc 100644 --- a/app/javascript/styles/mastodon/accounts.scss +++ b/app/javascript/styles/mastodon/accounts.scss @@ -571,7 +571,19 @@ font-size: 12px; line-height: 12px; font-weight: 500; - color: $success-green; - background-color: rgba($success-green, 0.1); - border: 1px solid rgba($success-green, 0.5); + color: $ui-secondary-color; + background-color: rgba($ui-secondary-color, 0.1); + border: 1px solid rgba($ui-secondary-color, 0.5); + + &.moderator { + color: $success-green; + background-color: rgba($success-green, 0.1); + border-color: rgba($success-green, 0.5); + } + + &.admin { + color: $error-red; + background-color: rgba($error-red, 0.1); + border-color: rgba($error-red, 0.5); + } } diff --git a/app/lib/activitypub/activity/create.rb b/app/lib/activitypub/activity/create.rb index 376684c00..66e4f7c5e 100644 --- a/app/lib/activitypub/activity/create.rb +++ b/app/lib/activitypub/activity/create.rb @@ -173,7 +173,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity end def language_from_content - return nil unless language_map? + return LanguageDetector.instance.detect(text_from_content, @account) unless language_map? @object['contentMap'].keys.first end diff --git a/app/lib/extractor.rb b/app/lib/extractor.rb index 957364293..738ec89a0 100644 --- a/app/lib/extractor.rb +++ b/app/lib/extractor.rb @@ -5,7 +5,8 @@ module Extractor module_function - def extract_mentions_or_lists_with_indices(text) # :yields: username, list_slug, start, end + # :yields: username, list_slug, start, end + def extract_mentions_or_lists_with_indices(text) return [] unless text =~ Twitter::Regex[:at_signs] possible_entries = [] diff --git a/app/lib/language_detector.rb b/app/lib/language_detector.rb index a42460e10..c6f52f0c7 100644 --- a/app/lib/language_detector.rb +++ b/app/lib/language_detector.rb @@ -38,12 +38,31 @@ class LanguageDetector end def simplify_text(text) - text.dup.tap do |new_text| - new_text.gsub!(FetchLinkCardService::URL_PATTERN, '') - new_text.gsub!(Account::MENTION_RE, '') - new_text.gsub!(Tag::HASHTAG_RE, '') - new_text.gsub!(/\s+/, ' ') - end + new_text = remove_html(text) + new_text.gsub!(FetchLinkCardService::URL_PATTERN, '') + new_text.gsub!(Account::MENTION_RE, '') + new_text.gsub!(Tag::HASHTAG_RE, '') + new_text.gsub!(/:#{CustomEmoji::SHORTCODE_RE_FRAGMENT}:/, '') + new_text.gsub!(/\s+/, ' ') + new_text + end + + def new_scrubber + scrubber = Rails::Html::PermitScrubber.new + scrubber.tags = %w(br p) + scrubber + end + + def scrubber + @scrubber ||= new_scrubber + end + + def remove_html(text) + text = Loofah.fragment(text).scrub!(scrubber).to_s + text.gsub!('<br>', "\n") + text.gsub!('</p><p>', "\n\n") + text.gsub!(/(^<p>|<\/p>$)/, '') + text end def default_locale(account) diff --git a/app/models/account.rb b/app/models/account.rb index 863bfaa25..230a5d298 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -117,6 +117,8 @@ class Account < ApplicationRecord :current_sign_in_at, :confirmed?, :admin?, + :moderator?, + :staff?, :locale, to: :user, prefix: true, diff --git a/app/models/concerns/account_finder_concern.rb b/app/models/concerns/account_finder_concern.rb index 561c7ab9f..2e8a7fb37 100644 --- a/app/models/concerns/account_finder_concern.rb +++ b/app/models/concerns/account_finder_concern.rb @@ -44,7 +44,7 @@ module AccountFinderConcern end def with_usernames - Account.where.not(username: [nil, '']) + Account.where.not(username: '') end def matching_username diff --git a/app/models/web/push_subscription.rb b/app/models/web/push_subscription.rb index da67e7665..a41906227 100644 --- a/app/models/web/push_subscription.rb +++ b/app/models/web/push_subscription.rb @@ -24,12 +24,12 @@ class Web::PushSubscription < ApplicationRecord end def pushable?(notification) - data && data.key?('alerts') && data['alerts'][notification.type.to_s] + data&.key?('alerts') && data['alerts'][notification.type.to_s] end def as_payload payload = { id: id, endpoint: endpoint } - payload[:alerts] = data['alerts'] if data && data.key?('alerts') + payload[:alerts] = data['alerts'] if data&.key?('alerts') payload end diff --git a/app/services/batched_remove_status_service.rb b/app/services/batched_remove_status_service.rb index aa2229f13..f68fa8837 100644 --- a/app/services/batched_remove_status_service.rb +++ b/app/services/batched_remove_status_service.rb @@ -26,7 +26,7 @@ class BatchedRemoveStatusService < BaseService statuses.each(&:destroy) # Batch by source account - statuses.group_by(&:account_id).each do |_, account_statuses| + statuses.group_by(&:account_id).each_value do |account_statuses| account = account_statuses.first.account unpush_from_home_timelines(account, account_statuses) diff --git a/app/services/resolve_remote_account_service.rb b/app/services/resolve_remote_account_service.rb index 3d0a36f6c..3293fe40f 100644 --- a/app/services/resolve_remote_account_service.rb +++ b/app/services/resolve_remote_account_service.rb @@ -124,11 +124,11 @@ class ResolveRemoteAccountService < BaseService end def auto_suspend? - domain_block && domain_block.suspend? + domain_block&.suspend? end def auto_silence? - domain_block && domain_block.silence? + domain_block&.silence? end def domain_block diff --git a/app/views/accounts/_header.html.haml b/app/views/accounts/_header.html.haml index 47ee02cf0..94ec5ae5b 100644 --- a/app/views/accounts/_header.html.haml +++ b/app/views/accounts/_header.html.haml @@ -30,8 +30,12 @@ - if account.user_admin? .roles - .account-role + .account-role.admin = t 'accounts.roles.admin' + - elsif account.user_moderator? + .roles + .account-role.moderator + = t 'accounts.roles.moderator' .bio .account__header__content.p-note.emojify!=processed_bio[:text] - if processed_bio[:metadata].length > 0 diff --git a/app/views/settings/applications/new.html.haml b/app/views/settings/applications/new.html.haml index 5274a430c..aa2281fea 100644 --- a/app/views/settings/applications/new.html.haml +++ b/app/views/settings/applications/new.html.haml @@ -3,6 +3,6 @@ = simple_form_for @application, url: settings_applications_path do |f| = render 'fields', f: f - + .actions = f.button :button, t('doorkeeper.applications.buttons.submit'), type: :submit diff --git a/app/views/settings/applications/show.html.haml b/app/views/settings/applications/show.html.haml index 12baed088..390682d6f 100644 --- a/app/views/settings/applications/show.html.haml +++ b/app/views/settings/applications/show.html.haml @@ -25,7 +25,7 @@ = simple_form_for @application, url: settings_application_path(@application), method: :put do |f| = render 'fields', f: f - + .actions = f.button :button, t('generic.save_changes'), type: :submit |