Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unique identifier mechanic is broken #43

Open
allaire opened this issue Mar 15, 2018 · 3 comments
Open

Unique identifier mechanic is broken #43

allaire opened this issue Mar 15, 2018 · 3 comments

Comments

@allaire
Copy link

allaire commented Mar 15, 2018

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

NicosKaralis added a commit to NicosKaralis/Swift-ActionCableClient that referenced this issue Nov 28, 2018
@NicosKaralis
Copy link

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

@agordeev
Copy link

agordeev commented Mar 6, 2019

@NicosKaralis thanks for your PR! I was struggling with this bug and found this issue. It helped.

@nerzh
Copy link

nerzh commented Mar 15, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants