diff options
author | Thibaut Girka <thib@sitedethib.com> | 2019-08-07 13:56:48 +0200 |
---|---|---|
committer | Thibaut Girka <thib@sitedethib.com> | 2019-08-07 13:56:48 +0200 |
commit | 04534604c654060eca24628247fdb51b7ff5372a (patch) | |
tree | f8ae222e84056fb2674d23187e66517da1fc2af9 /app/models | |
parent | 8400ddca7155005ab79485ed6054c04ea3ca5667 (diff) | |
parent | ac33f1aedd9a6c72c6c176afb1f5d62a1ce5d44d (diff) |
Merge branch 'master' into glitch-soc/merge-upstream
Conflicts: - app/models/user.rb - app/serializers/initial_state_serializer.rb - app/views/admin/dashboard/index.html.haml - config/locales/simple_form.en.yml
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/account.rb | 12 | ||||
-rw-r--r-- | app/models/featured_tag.rb | 2 | ||||
-rw-r--r-- | app/models/form/admin_settings.rb | 2 | ||||
-rw-r--r-- | app/models/tag.rb | 3 | ||||
-rw-r--r-- | app/models/trending_tags.rb | 4 | ||||
-rw-r--r-- | app/models/user.rb | 4 |
6 files changed, 13 insertions, 14 deletions
diff --git a/app/models/account.rb b/app/models/account.rb index 3370fbc5e..92e60f747 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -231,17 +231,7 @@ class Account < ApplicationRecord end def tags_as_strings=(tag_names) - tag_names.map! { |name| name.mb_chars.downcase.to_s } - tag_names.uniq! - - # Existing hashtags - hashtags_map = Tag.where(name: tag_names).each_with_object({}) { |tag, h| h[tag.name] = tag } - - # Initialize not yet existing hashtags - tag_names.each do |name| - next if hashtags_map.key?(name) - hashtags_map[name] = Tag.new(name: name) - end + hashtags_map = Tag.find_or_create_by_names(tag_names).each_with_object({}) { |tag, h| h[tag.name] = tag } # Remove hashtags that are to be deleted tags.each do |tag| diff --git a/app/models/featured_tag.rb b/app/models/featured_tag.rb index d06ae26a8..e02ae0705 100644 --- a/app/models/featured_tag.rb +++ b/app/models/featured_tag.rb @@ -23,7 +23,7 @@ class FeaturedTag < ApplicationRecord validate :validate_featured_tags_limit, on: :create def name=(str) - self.tag = Tag.find_or_initialize_by(name: str.strip.delete('#').mb_chars.downcase.to_s) + self.tag = Tag.find_or_create_by_names(str.strip)&.first end def increment(timestamp) diff --git a/app/models/form/admin_settings.rb b/app/models/form/admin_settings.rb index ecaed44f6..2c3a7f13b 100644 --- a/app/models/form/admin_settings.rb +++ b/app/models/form/admin_settings.rb @@ -35,6 +35,7 @@ class Form::AdminSettings show_reblogs_in_public_timelines show_replies_in_public_timelines spam_check_enabled + trends ).freeze BOOLEAN_KEYS = %i( @@ -51,6 +52,7 @@ class Form::AdminSettings show_reblogs_in_public_timelines show_replies_in_public_timelines spam_check_enabled + trends ).freeze UPLOAD_KEYS = %i( diff --git a/app/models/tag.rb b/app/models/tag.rb index 6a02581fa..e2fe91da1 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -31,7 +31,8 @@ class Tag < ApplicationRecord scope :reviewed, -> { where.not(reviewed_at: nil) } scope :pending_review, -> { where(reviewed_at: nil).where.not(requested_review_at: nil) } - scope :discoverable, -> { where.not(listable: false).joins(:account_tag_stat).where(AccountTagStat.arel_table[:accounts_count].gt(0)).order(Arel.sql('account_tag_stats.accounts_count desc')) } + scope :usable, -> { where(usable: [true, nil]) } + scope :discoverable, -> { where(listable: [true, nil]).joins(:account_tag_stat).where(AccountTagStat.arel_table[:accounts_count].gt(0)).order(Arel.sql('account_tag_stats.accounts_count desc')) } scope :most_used, ->(account) { joins(:statuses).where(statuses: { account: account }).group(:id).order(Arel.sql('count(*) desc')) } delegate :accounts_count, diff --git a/app/models/trending_tags.rb b/app/models/trending_tags.rb index e9b9b25e3..0a7e2feac 100644 --- a/app/models/trending_tags.rb +++ b/app/models/trending_tags.rb @@ -66,6 +66,10 @@ class TrendingTags end def request_review!(tag) + return unless Setting.trends + + tag.touch(:requested_review_at) + User.staff.includes(:account).find_each { |u| AdminMailer.new_trending_tag(u.account, tag).deliver_later! if u.allows_trending_tag_emails? } end end diff --git a/app/models/user.rb b/app/models/user.rb index 67cf92307..45a4b8989 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -107,7 +107,9 @@ class User < ApplicationRecord delegate :auto_play_gif, :default_sensitive, :unfollow_modal, :boost_modal, :favourite_modal, :delete_modal, :reduce_motion, :system_font_ui, :noindex, :flavour, :skin, :display_media, :hide_network, :hide_followers_count, :expand_spoilers, :default_language, :aggregate_reblogs, :show_application, - :advanced_layout, :default_content_type, :use_blurhash, :use_pending_items, :use_pending_items, to: :settings, prefix: :setting, allow_nil: false + :advanced_layout, :use_blurhash, :use_pending_items, :trends, + :default_content_type, + to: :settings, prefix: :setting, allow_nil: false attr_reader :invite_code attr_writer :external |