Skip to content

Commit 52189d2

Browse files
authored
Include identifier in ActionCable channel notifications (rails#52421)
1 parent 9d8ae6d commit 52189d2

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

actioncable/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
* Add an `identifier` to the event payload for the ActiveSupport::Notification `transmit_subscription_confirmation.action_cable` and `transmit_subscription_rejection.action_cable`.
2+
3+
*Keith Schacht*
14

25
Please check [7-2-stable](https://github.com/rails/rails/blob/7-2-stable/actioncable/CHANGELOG.md) for previous changes.

actioncable/lib/action_cable/channel/base.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ def transmit_subscription_confirmation
309309
unless subscription_confirmation_sent?
310310
logger.debug "#{self.class.name} is transmitting the subscription confirmation"
311311

312-
ActiveSupport::Notifications.instrument("transmit_subscription_confirmation.action_cable", channel_class: self.class.name) do
312+
ActiveSupport::Notifications.instrument("transmit_subscription_confirmation.action_cable", channel_class: self.class.name, identifier: @identifier) do
313313
connection.transmit identifier: @identifier, type: ActionCable::INTERNAL[:message_types][:confirmation]
314314
@subscription_confirmation_sent = true
315315
end
@@ -324,7 +324,7 @@ def reject_subscription
324324
def transmit_subscription_rejection
325325
logger.debug "#{self.class.name} is transmitting the subscription rejection"
326326

327-
ActiveSupport::Notifications.instrument("transmit_subscription_rejection.action_cable", channel_class: self.class.name) do
327+
ActiveSupport::Notifications.instrument("transmit_subscription_rejection.action_cable", channel_class: self.class.name, identifier: @identifier) do
328328
connection.transmit identifier: @identifier, type: ActionCable::INTERNAL[:message_types][:rejection]
329329
end
330330
end

actioncable/test/channel/base_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ def error_handler
242242
assert_equal 1, events.length
243243
assert_equal "transmit_subscription_confirmation.action_cable", events[0].name
244244
assert_equal "ActionCable::Channel::BaseTest::ChatChannel", events[0].payload[:channel_class]
245+
assert_equal "{id: 1}", events[0].payload[:identifier]
245246
end
246247
ensure
247248
ActiveSupport::Notifications.unsubscribe "transmit_subscription_confirmation.action_cable"
@@ -256,6 +257,7 @@ def error_handler
256257
assert_equal 1, events.length
257258
assert_equal "transmit_subscription_rejection.action_cable", events[0].name
258259
assert_equal "ActionCable::Channel::BaseTest::ChatChannel", events[0].payload[:channel_class]
260+
assert_equal "{id: 1}", events[0].payload[:identifier]
259261
ensure
260262
ActiveSupport::Notifications.unsubscribe "transmit_subscription_rejection.action_cable"
261263
end

0 commit comments

Comments
 (0)