<file_sep>class ChatroomController < ApplicationController
    before_action :require_user
    
    def index
        @message = Message.new
        @messages = Message.custom_display # instead of Message.all, scope defined in the Message model
        @online_users = User.where("last_seen_at > ?", 3.minutes.ago)
    end
    
end<file_sep>class ApplicationController < ActionController::Base
    helper_method :current_user, :logged_in?
    # allows the use of these methods in my views
    
    before_action :update_last_seen_at, if: -> { logged_in? && (current_user.last_seen_at.nil? || current_user.last_seen_at < 1.minutes.ago) }
    # before every load, we only want to update the last seen column if the user is logged in and if the current user is logging in the first time or the value of last seen is more than 2 minutes old
    
    def current_user
        @current_user ||= User.find(session[:user_id]) if session[:user_id]
    end
    
    def logged_in?
        !!current_user
        # turns current_user to a boolean
    end
    
    def require_user
        if !logged_in?
           flash[:error] = "You must be logged in to perform that action."
           redirect_to login_path
        end
    end
    
    def update_last_seen_at
      current_user.update_attribute(:last_seen_at, Time.current)
    end
end<file_sep># README

Personal project. Simple live chatroom web-app using Semantic UI gem for the front-end part. Dependencies: NodeJS, Yarn, Webpacker.
<file_sep>class ChatroomChannel < ApplicationCable::Channel
  def subscribed
    # stream_from "some_channel"
    stream_from "chatroom_channel"
    # also need to create a route for this websocket connection (actioncable mounts the data in the routes.rb file)
  end

  def unsubscribed
    # Any cleanup needed when channel is unsubscribed
  end
end
