mirror of
https://github.com/glitch-soc/mastodon.git
synced 2024-11-27 10:30:15 -05:00
Add not_featured_by
scope to Tag (#28815)
This commit is contained in:
parent
1d3ecd3fba
commit
650c548c31
@ -12,10 +12,6 @@ class Api::V1::FeaturedTags::SuggestionsController < Api::BaseController
|
|||||||
private
|
private
|
||||||
|
|
||||||
def set_recently_used_tags
|
def set_recently_used_tags
|
||||||
@recently_used_tags = Tag.recently_used(current_account).where.not(id: featured_tag_ids).limit(10)
|
@recently_used_tags = Tag.suggestions_for_account(current_account).limit(10)
|
||||||
end
|
|
||||||
|
|
||||||
def featured_tag_ids
|
|
||||||
current_account.featured_tags.pluck(:tag_id)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -38,7 +38,7 @@ class Settings::FeaturedTagsController < Settings::BaseController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def set_recently_used_tags
|
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
|
end
|
||||||
|
|
||||||
def featured_tag_params
|
def featured_tag_params
|
||||||
|
@ -53,6 +53,8 @@ class Tag < ApplicationRecord
|
|||||||
scope :listable, -> { where(listable: [true, nil]) }
|
scope :listable, -> { where(listable: [true, nil]) }
|
||||||
scope :trendable, -> { Setting.trendable_by_default ? where(trendable: [true, nil]) : where(trendable: true) }
|
scope :trendable, -> { Setting.trendable_by_default ? where(trendable: [true, nil]) : where(trendable: true) }
|
||||||
scope :not_trendable, -> { where(trendable: false) }
|
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|
|
scope :recently_used, lambda { |account|
|
||||||
joins(:statuses)
|
joins(:statuses)
|
||||||
.where(statuses: { id: account.statuses.select(:id).limit(RECENT_STATUS_LIMIT) })
|
.where(statuses: { id: account.statuses.select(:id).limit(RECENT_STATUS_LIMIT) })
|
||||||
|
@ -142,6 +142,25 @@ RSpec.describe Tag do
|
|||||||
end
|
end
|
||||||
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
|
describe '.matches_name' do
|
||||||
it 'returns tags for multibyte case-insensitive names' do
|
it 'returns tags for multibyte case-insensitive names' do
|
||||||
upcase_string = 'abcABCabcABCやゆよ'
|
upcase_string = 'abcABCabcABCやゆよ'
|
||||||
|
Loading…
Reference in New Issue
Block a user