1 # frozen_string_literal: true
3 # Mobile / Flutter feed stream for a single circle.
4 # Subscribe: { channel: "CircleFeedChannel", circle_id: 123 }
5 # Events: squak.created, squak.deleted
6 class CircleFeedChannel < ApplicationCable::Channel
7 def subscribed
8 reject unless current_user
9
10 circle_id = params[:circle_id].to_i
11 circle = accessible_circle(circle_id)
12 unless circle
13 reject
14 return
15 end
16
17 @circle_id = circle.id
18 ViewingPresence.mark!(user_id: current_user.id, circle_id: @circle_id)
19 stream_from self.class.stream_name(circle.id)
20 end
21
22 def unsubscribed
23 return unless current_user && @circle_id
24 ViewingPresence.clear!(user_id: current_user.id, circle_id: @circle_id)
25 end
26
27 def self.stream_name(circle_id)
28 "circle_feed:#{circle_id}"
29 end
30
31 private
32
33 def accessible_circle(circle_id)
34 current_user.circles.find_by(id: circle_id)
35 end
36 end
Novasector
Engineering LLC
- Web Development
- Software Development
Bio