Add internal page for spinning up group chats (and make jokes flare tag) (#3384)

This commit is contained in:
Ben Halpern 2019-07-09 13:04:58 -04:00 committed by GitHub
parent 1f97669e66
commit a8ef9663a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 66 additions and 2 deletions

View file

@ -0,0 +1,29 @@
class Internal::ChatChannelsController < Internal::ApplicationController
layout "internal"
def index
@group_chat_channels = ChatChannel.where(channel_type: "invite_only").includes(:users).page(params[:page]).per(50)
end
def create
ChatChannel.create_with_users(users_by_param, "invite_only", chat_channel_params[:channel_name])
redirect_back(fallback_location: "/internal/chat_channels")
end
def update
@chat_channel = ChatChannel.find(params[:id])
@chat_channel.add_users(users_by_param)
redirect_back(fallback_location: "/internal/chat_channels")
end
private
def users_by_param
User.where(username: chat_channel_params[:usernames_string].downcase.delete(" ").split(","))
end
def chat_channel_params
allowed_params = %i[usernames_string channel_name]
params.require(:chat_channel).permit(allowed_params)
end
end

View file

@ -1,5 +1,6 @@
class FlareTag
FLARES = %w[explainlikeimfive
jokes
ama
techtalks
help

View file

@ -1,6 +1,6 @@
class ChatChannel < ApplicationRecord
include AlgoliaSearch
attr_accessor :current_user
attr_accessor :current_user, :usernames_string
has_many :messages
has_many :chat_channel_memberships, dependent: :destroy

View file

@ -0,0 +1,23 @@
<h1>Group Connect Channels</h1>
<%= paginate @group_chat_channels %>
<% @group_chat_channels.each do |channel| %>
<div class="wrapper-3" style="border-bottom: 1px solid grey; padding: 10px;">
<div><a href="/connect/<%= channel.slug %>" target="_blank"><%= channel.channel_name %></a></div>
<div style="font-size: 0.8em;"><%= channel.users.pluck(:username).join(", ") %></div>
<div>
<%= form_for [:internal, channel] do |f| %>
<%= f.text_field :usernames_string, placeholder: "Usernames to add" %>
<%= f.submit %>
<% end %>
</div>
</div>
<% end %>
<%= paginate @group_chat_channels %>
<h1>Create New Connect Channel</h1>
<br />
<%= form_for [:internal, ChatChannel.new] do |f| %>
<%= f.text_field :channel_name, placeholder: "Channel Name" %>
<%= f.text_field :usernames_string, placeholder: "Usernames to add" %>
<%= f.submit %>
<% end %>

View file

@ -42,6 +42,16 @@
padding: 2px;
}
.wrapper-3 {
display: grid;
grid-template-columns: 25% 40% 25%%;
padding: 2px;
}
.wrapper-3 div {
padding: 8px;
}
.grid-item {
word-wrap: break-word;
}
@ -123,7 +133,7 @@
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<% controller_names = %w[comments articles users members dogfood tags welcome broadcasts reports pages classified_listings tools] %>
<% controller_names = %w[comments articles users tags welcome broadcasts reports pages classified_listings tools chat_channels] %>
<% controller_names.each do |name| %>
<li class="<%= "active" if controller_name == name %>"><a href="/internal/<%= name %>"><%= name %></a></li>
<% end %>

View file

@ -37,6 +37,7 @@ Rails.application.routes.draw do
resources :listings, only: %i[index edit update destroy], controller: "classified_listings"
resources :pages, only: %i[index new create edit update destroy]
resources :reactions, only: [:update]
resources :chat_channels, only: %i[index create update]
resources :reports, only: %i[index show], controller: "feedback_messages" do
collection do
post "send_email"