1
0
mirror of https://github.com/funamitech/mastodon synced 2024-11-28 06:48:45 +09:00

Add not_featured_by scope to Tag (#28815)

This commit is contained in:
Matt Jankowski 2024-04-17 06:05:38 -04:00 committed by GitHub
parent 1d3ecd3fba
commit 650c548c31
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 23 additions and 6 deletions

View File

@ -12,10 +12,6 @@ class Api::V1::FeaturedTags::SuggestionsController < Api::BaseController
private
def set_recently_used_tags
@recently_used_tags = Tag.recently_used(current_account).where.not(id: featured_tag_ids).limit(10)
end
def featured_tag_ids
current_account.featured_tags.pluck(:tag_id)
@recently_used_tags = Tag.suggestions_for_account(current_account).limit(10)
end
end

View File

@ -38,7 +38,7 @@ class Settings::FeaturedTagsController < Settings::BaseController
end
def set_recently_used_tags
@recently_used_tags = Tag.recently_used(current_account).where.not(id: @featured_tags.map(&:id)).limit(10)
@recently_used_tags = Tag.suggestions_for_account(current_account).limit(10)
end
def featured_tag_params

View File

@ -53,6 +53,8 @@ class Tag < ApplicationRecord
scope :listable, -> { where(listable: [true, nil]) }
scope :trendable, -> { Setting.trendable_by_default ? where(trendable: [true, nil]) : where(trendable: true) }
scope :not_trendable, -> { where(trendable: false) }
scope :suggestions_for_account, ->(account) { recently_used(account).not_featured_by(account) }
scope :not_featured_by, ->(account) { where.not(id: account.featured_tags.select(:tag_id)) }
scope :recently_used, lambda { |account|
joins(:statuses)
.where(statuses: { id: account.statuses.select(:id).limit(RECENT_STATUS_LIMIT) })

View File

@ -142,6 +142,25 @@ RSpec.describe Tag do
end
end
describe '.not_featured_by' do
let!(:account) { Fabricate(:account) }
let!(:fun) { Fabricate(:tag, name: 'fun') }
let!(:games) { Fabricate(:tag, name: 'games') }
before do
Fabricate :featured_tag, account: account, name: 'games'
Fabricate :featured_tag, name: 'fun'
end
it 'returns tags not featured by the account' do
results = described_class.not_featured_by(account)
expect(results)
.to include(fun)
.and not_include(games)
end
end
describe '.matches_name' do
it 'returns tags for multibyte case-insensitive names' do
upcase_string = 'abcABCやゆよ'