Challenge 1: A Notifications Channel — Solution # app/channels/notifications_channel.rb class NotificationsChannel < ApplicationCable::Channel def subscribed stream_for current_user end end =begin Notes: - current_user is available here because Connection#connect (from the chapter's example) set self.current_user during the WebSocket handshake, and identified_by :current_user makes it accessible to every channel built on that connection -- no params lookup needed, unlike CommentsChannel's post_id. - stream_for current_user derives a stream identifier from the user object itself, so each user's browser tab(s) join a stream unique to them -- two different logged-in users subscribing to NotificationsChannel end up on two separate streams automatically. - Because the stream is tied to the authenticated user rather than a client-supplied parameter, there's no way for a client to subscribe to another user's notification stream by passing a different ID -- the scoping is enforced server-side, from data already verified during connect. =end