diff --git a/app/assets/javascripts/initializers/initNotifications.js b/app/assets/javascripts/initializers/initNotifications.js index 9c587873e..b30a85874 100644 --- a/app/assets/javascripts/initializers/initNotifications.js +++ b/app/assets/javascripts/initializers/initNotifications.js @@ -23,7 +23,7 @@ function markNotificationsAsRead() { xmlhttp.setRequestHeader('X-CSRF-Token', csrfToken); xmlhttp.send(); } - }, 120); + }, 250); } function fetchNotificationsCount() { diff --git a/app/assets/stylesheets/chat.scss b/app/assets/stylesheets/chat.scss index e1a64d109..319c07d77 100644 --- a/app/assets/stylesheets/chat.scss +++ b/app/assets/stylesheets/chat.scss @@ -1,14 +1,28 @@ @import 'variables'; // High level class +.chat-page-header{ + background: $green; + text-align: center; + padding: 5px; + margin-top: -25px; + border-radius: 3px; + margin-bottom: 5px; + font-size:0.8em; + font-weight: bold; +} + .chat { display: flex; height: inherit; } .chat__channels { - width: 160px; + width: 80px; height: inherit; + @media screen and ( min-width: 550px ){ + width: 160px; + } } .chat__channels--hidden { @@ -89,9 +103,10 @@ width: inherit; } .chatchanneltabbutton{ - width: 92%; + width: 93%; border: none; background: transparent; + padding:0; &:hover { .chatchanneltab--inactive { border: 1px solid $outline-color; @@ -101,19 +116,22 @@ } .chatchanneltab { display:inline-block; - width: 95%; + width: 90%; margin-bottom: 5px; - border-left: 8px solid transparent; background: inherit; text-align: start; - font-size: 14px; + font-size: 11px; font-weight: 500; padding: 8px; border: 1px solid transparent; border-radius: 3px; white-space: nowrap; overflow: hidden; - text-overflow: ellipsis;} + text-overflow: ellipsis; + @media screen and ( min-width: 550px ){ + font-size: 13px; + } +} .chatchanneltab--active { background: white; @@ -125,9 +143,9 @@ display: inline-block; background: white; border: 2px solid $light-medium-gray; - padding: 5px; + padding: 0.3em; border-radius: 100px; - vertical-align: -2px; + vertical-align: -0.05em; margin-right: 3px; } @@ -136,18 +154,6 @@ border: 2px solid $black; } -@keyframes example { - // animation-name: example; - // animation-duration: 4s; - // animation-iteration-count: infinite; - from { - border-left: 8px solid transparent; - } - to { - border-left: 8px solid #ffb6c1; - } -} - .chatchannels__channelslist { padding: 10px 0; flex-grow: 1; diff --git a/app/controllers/chat_channels_controller.rb b/app/controllers/chat_channels_controller.rb index e06f8cc65..f39ad60ac 100644 --- a/app/controllers/chat_channels_controller.rb +++ b/app/controllers/chat_channels_controller.rb @@ -1,6 +1,15 @@ class ChatChannelsController < ApplicationController before_action :authenticate_user!, only: [:moderate] + def index + if params[:state] == "unopened" + render_unopened_json_response + return + else + render_channels_html + end + end + def show @chat_channel = ChatChannel.includes(:messages).find_by(id: params[:id]) if @chat_channel @@ -15,7 +24,8 @@ class ChatChannelsController < ApplicationController def open @chat_channel = ChatChannel.find(params[:id]) raise unless @chat_channel.has_member?(current_user) - @chat_channel.chat_channel_memberships.where(user_id: current_user.id).first.touch(:last_opened_at) + membership = @chat_channel.chat_channel_memberships.where(user_id: current_user.id).first + membership.update(last_opened_at: 1.seconds.from_now, has_unopened_messages: false) render json: { status: "success", channel: params[:id] }, status: 200 end @@ -55,4 +65,30 @@ class ChatChannelsController < ApplicationController def chat_channel_params params.require(:chat_channel).permit(:command) end + + def render_unopened_json_response + if current_user.has_role?(:super_admin) || Rails.env.development? + @chat_channels_memberships = current_user. + chat_channel_memberships. + where(has_unopened_messages: true).order("updated_at DESC") + else + @chat_channels_memberships = [] + end + render "index.json" + end + + def render_channels_html + @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 end diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 71dc1329e..2da56fba0 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -41,22 +41,7 @@ class PagesController < ApplicationController 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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 50d7bb04d..a19b07cfb 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -19,7 +19,7 @@ module ApplicationHelper controller_name == "registrations" || controller_name == "users" || controller_name == "pages" || - + controller_name == "chat_channels" || controller_name == "dashboards"|| controller_name == "moderations"|| controller_name == "videos"|| diff --git a/app/javascript/chat/channels.jsx b/app/javascript/chat/channels.jsx index 8babc03fb..96e77083a 100644 --- a/app/javascript/chat/channels.jsx +++ b/app/javascript/chat/channels.jsx @@ -9,19 +9,22 @@ const Channels = ({ activeChannelId, chatChannels, handleSwitchChannel }) => { : 'chatchanneltab--inactive'; const name = channel.channel_type === "direct" ? '@'+channel.slug.replace(`${window.currentUser.username}/`, '').replace(`/${window.currentUser.username}`, '') : channel.channel_name const newMessagesIndicatorClass = new Date(channel.last_opened_at) < new Date(channel.last_message_at) ? "chatchanneltabindicator--new" : "chatchanneltabindicator--old" + const modififedSlug = channel.channel_type === "direct" ? name : channel.slug; return ( ); diff --git a/app/javascript/chat/chat.jsx b/app/javascript/chat/chat.jsx index 78eb4d914..bef48eb82 100644 --- a/app/javascript/chat/chat.jsx +++ b/app/javascript/chat/chat.jsx @@ -162,12 +162,15 @@ export default class Chat extends Component { handleSwitchChannel = e => { e.preventDefault(); this.setState({ - activeChannelId: e.target.dataset.channelId, + activeChannelId: parseInt(e.target.dataset.channelId), scrolled: false, showAlert: false, }); - window.history.replaceState(null, null, "/chat/"+e.target.dataset.channelName); + window.history.replaceState(null, null, "/chat/"+e.target.dataset.channelSlug); document.getElementById("messageform").focus(); + if (window.ga && ga.create) { + ga('send', 'pageview', location.pathname + location.search); + } sendOpen( e.target.dataset.channelId, this.handleChannelOpenSuccess, @@ -258,7 +261,9 @@ export default class Chat extends Component { return (