Unique identifier mechanic is broken
allaire opened this issue · comments
The last commit that adds the UID mechanic is not working correctly, since it's always relying on the first element of the identifier
dictionary. The issue happens when the order is different in the JSONSerializer.deserialize
method. We had a regression in iOS 10 because the order of the JSON is different than iOS 11. See below:
iOS 11
{"identifier":"{\"member_id\":\"20c5edcc-5dda-4f43-a0df-b86a908001b6\",\"channel\":\"ConversationsChannel\"}","type":"confirm_subscription"}
iOS 10
{"identifier":"{\"channel\":\"ConversationsChannel\",\"member_id\":\"20c5edcc-5dda-4f43-a0df-b86a908001b6\"}","type":"confirm_subscription"}
This cause a problem because the channel's key in unconfirmedChannels
in this example is the member's uuid (since it's always the first element of the identifier dictionary in the create
method, but the message.uid is ConversationsChannel
under iOS 10 because that's the first element of the onText text
JSON.
A quick fix would be to remove the channel
key, but I think the solution is not really elegant to be honest. We could also create a unique hash using a similar technique like this one:
https://github.com/rails/rails/blob/master/actioncable/app/assets/javascripts/action_cable/subscription.coffee#L54
After having to deal with this problem I've managed to solve this problem. At #56 in commit 5090754 should be a fix to this problem.
A dictionary (or hash) does not keep the keys in any particular order, so the solution is just sort the keys before using them and append every param to the identified (Channel#uid)
This is working fine for me, but I would like if someone else take a look before merging it
@NicosKaralis thanks for your PR! I was struggling with this bug and found this issue. It helped.