docbrown/app/controllers/pages_controller.rb
Ben Halpern 10c3b52b0a
Add chat channel indicator (#379)
* Add new message indicator to chat

* Add indicator switch to chat

* Add chat switch indicator
2018-06-01 18:16:10 -04:00

79 lines
2.2 KiB
Ruby

class PagesController < ApplicationController
before_action :set_cache_control_headers, only: [:rlyweb, :now, :events, :membership]
def phishing
@user = current_user
end
def now
set_surrogate_key_header "now_page"
end
def about
set_surrogate_key_header "about_page"
end
def membership
flash[:notice] = ""
flash[:error] = ""
@members = members_for_display
set_surrogate_key_header "membership_page"
end
def membership_form
render "membership_form", layout: false
end
def rlyweb
set_surrogate_key_header "rlyweb"
end
def welcome
daily_thread = latest_published_welcome_thread
if daily_thread
redirect_to daily_thread.path
else
# fail safe if we haven't made the first welcome thread
redirect_to "/notifications"
end
end
def live
@chat_channels = [ChatChannel.find_by_channel_name("Workshop")].to_json
end
def chat
@chat_channels = current_user.chat_channels.
order("last_message_at DESC").
includes(:chat_channel_memberships)
@chat_channels.each do |channel|
channel.current_user = current_user
end
slug = if params[:slug] && params[:slug].start_with?("@")
[current_user.username, params[:slug].gsub("@", "")].sort.join("/")
else
params[:slug]
end
@active_channel = ChatChannel.find_by_slug(slug) || @chat_channels.first
end
private # helpers
def latest_published_welcome_thread
Article.where(user_id: ENV["DEVTO_USER_ID"], published: true).
tagged_with("welcome").last
end
def members_for_display
Rails.cache.fetch("members-for-display-on-membership-page", expires_in: 6.hours) do
members = User.with_any_role(:level_1_member,
:level_2_member,
:level_3_member,
:level_4_member,
:triple_unicorn_member,
:workshop_pass)
team_ids = [1, 264, 6, 3, 31047, 510, 560, 1075, 48943, 13962]
members.reject { |user| team_ids.include?(user.id) }.shuffle
end
end
end