docbrown/app/controllers/sidebars_controller.rb
Ben Halpern 81dd1b867e
Add language constraint to sidebar (#20386)
* Add language constraint to sidebar

* Add language fallback
2023-11-22 19:00:48 +00:00

32 lines
1 KiB
Ruby

class SidebarsController < ApplicationController
layout false
def show
get_latest_campaign_articles
get_active_discussions if user_signed_in?
end
private
def get_latest_campaign_articles
@campaign_articles_count = Campaign.current.count
@latest_campaign_articles = Campaign.current.plucked_article_attributes
end
def get_active_discussions
tag_names = current_user.cached_followed_tag_names
languages = current_user.languages.pluck(:language)
languages = [I18n.default_locale.to_s] if languages.empty?
@active_discussions = Article.published
.where("published_at > ?", 1.week.ago)
.where("comments_count > ?", 0)
.with_at_least_home_feed_minimum_score
.cached_tagged_with_any(tag_names)
.where(language: languages)
.or(Article.featured.published.where("published_at > ?", 1.week.ago)
.with_at_least_home_feed_minimum_score)
.order("last_comment_at DESC")
.limit(5)
.pluck(:path, :title, :comments_count, :created_at)
end
end