@@ -30,11 +30,16 @@ internal sealed class SubscribeState : State<SubscribeEffectInvocation, Subscrib
30
30
}
31
31
}
32
32
33
- data class Handshaking (
34
- val channels : Set <String >,
35
- val channelGroups : Set <String >,
33
+ class Handshaking (
34
+ channels : Set <String >,
35
+ channelGroups : Set <String >,
36
36
val subscriptionCursor : SubscriptionCursor ? = null ,
37
37
) : SubscribeState() {
38
+ // toSet() is a must because we want to make sure that channels is immutable, and Handshaking constructor
39
+ // doesn't prevent from providing "channels" that is mutable set.
40
+ val channels: Set <String > = channels.toSet()
41
+ val channelGroups: Set <String > = channelGroups.toSet()
42
+
38
43
override fun onEntry () = setOf (SubscribeEffectInvocation .Handshake (channels, channelGroups))
39
44
override fun onExit () = setOf (SubscribeEffectInvocation .CancelHandshake )
40
45
@@ -87,13 +92,16 @@ internal sealed class SubscribeState : State<SubscribeEffectInvocation, Subscrib
87
92
}
88
93
}
89
94
90
- data class HandshakeReconnecting (
91
- val channels : Set <String >,
92
- val channelGroups : Set <String >,
95
+ class HandshakeReconnecting (
96
+ channels : Set <String >,
97
+ channelGroups : Set <String >,
93
98
val attempts : Int ,
94
99
val reason : PubNubException ? ,
95
100
val subscriptionCursor : SubscriptionCursor ? = null
96
101
) : SubscribeState() {
102
+ val channels: Set <String > = channels.toSet()
103
+ val channelGroups: Set <String > = channelGroups.toSet()
104
+
97
105
override fun onEntry () =
98
106
setOf (SubscribeEffectInvocation .HandshakeReconnect (channels, channelGroups, attempts, reason))
99
107
@@ -135,7 +143,12 @@ internal sealed class SubscribeState : State<SubscribeEffectInvocation, Subscrib
135
143
136
144
is SubscribeEvent .HandshakeReconnectSuccess -> {
137
145
transitionTo(
138
- state = Receiving (channels, channelGroups, subscriptionCursor?.copy(region = event.subscriptionCursor.region) ? : event.subscriptionCursor),
146
+ state = Receiving (
147
+ channels,
148
+ channelGroups,
149
+ subscriptionCursor?.copy(region = event.subscriptionCursor.region)
150
+ ? : event.subscriptionCursor
151
+ ),
139
152
SubscribeEffectInvocation .EmitStatus (
140
153
PNStatus (
141
154
category = PNStatusCategory .PNConnectedCategory ,
@@ -163,11 +176,13 @@ internal sealed class SubscribeState : State<SubscribeEffectInvocation, Subscrib
163
176
}
164
177
}
165
178
166
- data class HandshakeStopped (
167
- val channels : Set <String >,
168
- val channelGroups : Set <String >,
179
+ class HandshakeStopped (
180
+ channels : Set <String >,
181
+ channelGroups : Set <String >,
169
182
val reason : PubNubException ?
170
183
) : SubscribeState() {
184
+ val channels: Set <String > = channels.toSet()
185
+ val channelGroups: Set <String > = channelGroups.toSet()
171
186
172
187
override fun transition (event : SubscribeEvent ): Pair <SubscribeState , Set <SubscribeEffectInvocation >> {
173
188
return when (event) {
@@ -206,12 +221,14 @@ internal sealed class SubscribeState : State<SubscribeEffectInvocation, Subscrib
206
221
}
207
222
}
208
223
209
- data class HandshakeFailed (
210
- val channels : Set <String >,
211
- val channelGroups : Set <String >,
224
+ class HandshakeFailed (
225
+ channels : Set <String >,
226
+ channelGroups : Set <String >,
212
227
val reason : PubNubException ,
213
228
val subscriptionCursor : SubscriptionCursor ? = null
214
229
) : SubscribeState() {
230
+ val channels: Set <String > = channels.toSet()
231
+ val channelGroups: Set <String > = channelGroups.toSet()
215
232
216
233
override fun transition (event : SubscribeEvent ): Pair <SubscribeState , Set <SubscribeEffectInvocation >> {
217
234
return when (event) {
@@ -242,11 +259,15 @@ internal sealed class SubscribeState : State<SubscribeEffectInvocation, Subscrib
242
259
}
243
260
}
244
261
245
- data class Receiving (
246
- private val channels : Set <String >,
247
- private val channelGroups : Set <String >,
248
- private val subscriptionCursor : SubscriptionCursor
262
+ class Receiving (
263
+ channels : Set <String >,
264
+ channelGroups : Set <String >,
265
+ val subscriptionCursor : SubscriptionCursor
249
266
) : SubscribeState() {
267
+
268
+ val channels: Set <String > = channels.toSet()
269
+ val channelGroups: Set <String > = channelGroups.toSet()
270
+
250
271
override fun onEntry () = setOf (
251
272
SubscribeEffectInvocation .ReceiveMessages (
252
273
channels, channelGroups, subscriptionCursor
@@ -286,7 +307,13 @@ internal sealed class SubscribeState : State<SubscribeEffectInvocation, Subscrib
286
307
}
287
308
288
309
is SubscribeEvent .SubscriptionRestored -> {
289
- transitionTo(Receiving (event.channels, event.channelGroups, SubscriptionCursor (event.subscriptionCursor.timetoken, subscriptionCursor.region)))
310
+ transitionTo(
311
+ Receiving (
312
+ event.channels,
313
+ event.channelGroups,
314
+ SubscriptionCursor (event.subscriptionCursor.timetoken, subscriptionCursor.region)
315
+ )
316
+ )
290
317
}
291
318
292
319
is SubscribeEvent .ReceiveSuccess -> {
@@ -318,13 +345,16 @@ internal sealed class SubscribeState : State<SubscribeEffectInvocation, Subscrib
318
345
}
319
346
}
320
347
321
- data class ReceiveReconnecting (
322
- val channels : Set <String >,
323
- val channelGroups : Set <String >,
348
+ class ReceiveReconnecting (
349
+ channels : Set <String >,
350
+ channelGroups : Set <String >,
324
351
val subscriptionCursor : SubscriptionCursor ,
325
352
val attempts : Int ,
326
353
val reason : PubNubException ?
327
354
) : SubscribeState() {
355
+ val channels: Set <String > = channels.toSet()
356
+ val channelGroups: Set <String > = channelGroups.toSet()
357
+
328
358
override fun onEntry () =
329
359
setOf (
330
360
SubscribeEffectInvocation .ReceiveReconnect (
@@ -392,7 +422,13 @@ internal sealed class SubscribeState : State<SubscribeEffectInvocation, Subscrib
392
422
}
393
423
394
424
is SubscribeEvent .SubscriptionRestored -> {
395
- transitionTo(Receiving (event.channels, event.channelGroups, SubscriptionCursor (event.subscriptionCursor.timetoken, subscriptionCursor.region)))
425
+ transitionTo(
426
+ Receiving (
427
+ event.channels,
428
+ event.channelGroups,
429
+ SubscriptionCursor (event.subscriptionCursor.timetoken, subscriptionCursor.region)
430
+ )
431
+ )
396
432
}
397
433
398
434
is SubscribeEvent .UnsubscribeAll -> {
@@ -417,11 +453,14 @@ internal sealed class SubscribeState : State<SubscribeEffectInvocation, Subscrib
417
453
}
418
454
}
419
455
420
- data class ReceiveStopped (
421
- private val channels : Set <String >,
422
- val channelGroups : Set <String >,
456
+ class ReceiveStopped (
457
+ channels : Set <String >,
458
+ channelGroups : Set <String >,
423
459
val subscriptionCursor : SubscriptionCursor
424
460
) : SubscribeState() {
461
+ val channels: Set <String > = channels.toSet()
462
+ val channelGroups: Set <String > = channelGroups.toSet()
463
+
425
464
override fun transition (event : SubscribeEvent ): Pair <SubscribeState , Set <SubscribeEffectInvocation >> {
426
465
return when (event) {
427
466
is SubscribeEvent .Reconnect -> {
@@ -459,12 +498,15 @@ internal sealed class SubscribeState : State<SubscribeEffectInvocation, Subscrib
459
498
}
460
499
}
461
500
462
- data class ReceiveFailed (
463
- private val channels : Set <String >,
464
- val channelGroups : Set <String >,
501
+ class ReceiveFailed (
502
+ channels : Set <String >,
503
+ channelGroups : Set <String >,
465
504
val subscriptionCursor : SubscriptionCursor ,
466
505
val reason : PubNubException
467
506
) : SubscribeState() {
507
+ val channels: Set <String > = channels.toSet()
508
+ val channelGroups: Set <String > = channelGroups.toSet()
509
+
468
510
override fun transition (event : SubscribeEvent ): Pair <SubscribeState , Set <SubscribeEffectInvocation >> {
469
511
return when (event) {
470
512
is SubscribeEvent .Reconnect -> {
0 commit comments