FIX: Improve category hashtag lookup (#10133)

* FIX: Improve category hashtag lookup

This commit improves support for sub-sub-categories and does not include
the ID of the category in the slug, which fixes the composer preview.

* FIX: Sub-sub-categories can be mentioned using only two levels

* FIX: Remove support for three-level hashtags

* DEV: Simplify code
This commit is contained in:
Dan Ungureanu
2020-07-07 03:19:01 +03:00
committed by GitHub
parent 6ef0e98f4e
commit e08b860e88
3 changed files with 84 additions and 34 deletions

View File

@@ -8,10 +8,15 @@ class CategoryHashtagsController < ApplicationController
ids = category_slugs.map { |category_slug| Category.query_from_hashtag_slug(category_slug).try(:id) }
valid_categories = Category.secured(guardian).where(id: ids).map do |category|
{ slug: category.hashtag_slug, url: category.url }
end.compact
slugs_and_urls = {}
render json: { valid: valid_categories }
Category.secured(guardian).where(id: ids).each do |category|
slugs_and_urls[category.slug] ||= category.url
slugs_and_urls[category.slug_path.last(2).join(':')] ||= category.url
end
render json: {
valid: slugs_and_urls.map { |slug, url| { slug: slug, url: url } }
}
end
end