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

Accept any string as a key for m.direct account data #1946

Merged
merged 10 commits into from
Nov 13, 2024

Conversation

MatMaul
Copy link
Contributor

@MatMaul MatMaul commented Nov 6, 2024

This is because a lot of m.direct in the wild have non valid data, and an email or phone number can end up as a key here when doing 3pid invites.

Current behavior is that m.direct parsing fully failed in this case, so there is no DMs anymore.

You can trigger that easily by trying to invite an email with no MXID bound to it with Element Web.

@giomfo
Copy link

giomfo commented Nov 6, 2024

Putting the email in the m.direct was not clearly defined in the spec

But the email address is the only user ID, the client has when a new DM is created by inviting someone by email. So email address is currently supported in m.direct event in the existing implementation in the Legacy Mobile clients and in the Element Web.

See for example in Element-Web: https://github.com/element-hq/matrix-react-sdk/blob/develop/src/createRoom.ts#L325
where opts.dmUserId may be an email address

@MatMaul MatMaul changed the title Accept any string as a key for m.direct account data Accept any string as a key for m.direct account data Nov 6, 2024
@giomfo
Copy link

giomfo commented Nov 6, 2024

Note: This PR is aligned with the following Element-Web implementation: https://github.com/element-hq/element-web/blob/2f8e98242c6de16cbfb6ebb6bc29cfe404b343cb/src/utils/dm/filterValidMDirect.ts#L35 (where the m.direct content is filtered)

@zecakeh
Copy link
Contributor

zecakeh commented Nov 7, 2024

So what you are saying is that the 3pid addresses in m.direct have a valid use-case? Because an alternative to this change would be to ignore non-user ID strings during deserialization, which would avoid the breaking change while remaining strictly aligned with the spec. But that means that when the account data is updated and re-serialized, the 3PID adresses would be removed.

@jplatte
Copy link
Member

jplatte commented Nov 7, 2024

I don't like the idea of throwing away entries during deserialization. I think we should have an opaque struct that can represent any string, but allows easy access of it as a &UserId (and maybe OwnedUserId) if it's that. We'd also need a constructor from a user ID, but not necessarily from an arbitrary string (or if we do, make it a named c'tor). Also for access, probably have a &str / String accessor.

This would mean a breaking change of course (just like this PR). It's pretty unfortunate that this is coming up (again) just after we did a release, but such is life I guess 🤷🏼

@MatMaul MatMaul force-pushed the fix-dm branch 3 times, most recently from a1245bb to 0adfa1c Compare November 7, 2024 11:52
@MatMaul MatMaul marked this pull request as draft November 7, 2024 11:53
@MatMaul
Copy link
Contributor Author

MatMaul commented Nov 7, 2024

Following the discussion here, I've rework the approach to use existing UserIdentifier.

It looks a lot bigger but a lot of the changes are moving UserIdentifier to a common place.

I still have to write some logic to properly validate email and phone number (cf TODOs), but I am interested if you prefer this approach or the one you suggested, that looks fine for me too.

@MatMaul MatMaul force-pushed the fix-dm branch 2 times, most recently from fec3590 to 144ecc5 Compare November 7, 2024 11:56
@jplatte
Copy link
Member

jplatte commented Nov 7, 2024

As you can see in the (de)serialization tests for UserIdentifier, that types is not just a string on the wire. I don't think it's useful here.

W.r.t. which solution to go with, that's @zecakeh's call.

@MatMaul
Copy link
Contributor Author

MatMaul commented Nov 7, 2024

As you can see in the (de)serialization tests for UserIdentifier, that types is not just a string on the wire. I don't think it's useful here.

Yes I've seen that, but we basically want to represent the same thing (either a MXID or a 3PID), so I thought it would be nice to use the structure and customize the parsing.

@MatMaul MatMaul changed the title Accept any string as a key for m.direct account data Parse m.direct as an user identifier and not strictly an MXID Nov 7, 2024
@zecakeh
Copy link
Contributor

zecakeh commented Nov 7, 2024

From the Ruma room, to keep a trace of it here:

Because I like Jonas's suggestion, it seems to me that the simplest solution is to create a new type with our IdZst macro without validating the input (like DeviceId). It will generate all the code necessary for conversion to/from string types, we will only need to add methods/implementation to convert to/from (Owned)UserId.

@MatMaul MatMaul changed the title Parse m.direct as an user identifier and not strictly an MXID Accept any string as a key for m.direct account data Nov 8, 2024
@MatMaul MatMaul marked this pull request as ready for review November 8, 2024 10:36
crates/ruma-events/src/direct.rs Show resolved Hide resolved
crates/ruma-events/src/direct.rs Outdated Show resolved Hide resolved
crates/ruma-events/src/direct.rs Outdated Show resolved Hide resolved
crates/ruma-events/src/direct.rs Show resolved Hide resolved
crates/ruma-events/src/direct.rs Outdated Show resolved Hide resolved
@MatMaul MatMaul requested a review from zecakeh November 12, 2024 10:41
crates/ruma-events/src/direct.rs Outdated Show resolved Hide resolved
crates/ruma-events/src/direct.rs Outdated Show resolved Hide resolved
crates/ruma-events/src/direct.rs Outdated Show resolved Hide resolved
crates/ruma-events/src/direct.rs Show resolved Hide resolved
crates/ruma-events/src/direct.rs Outdated Show resolved Hide resolved
crates/ruma-events/src/direct.rs Outdated Show resolved Hide resolved
crates/ruma-events/src/direct.rs Outdated Show resolved Hide resolved
@MatMaul MatMaul requested a review from zecakeh November 12, 2024 14:39
@MatMaul MatMaul requested a review from zecakeh November 12, 2024 16:01
Copy link
Member

@jplatte jplatte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this has already gone through a lot of review rounds but.. A changelog entry would be nice 😅

@MatMaul MatMaul requested a review from jplatte November 13, 2024 11:38
Copy link
Contributor

@zecakeh zecakeh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this!

@zecakeh zecakeh merged commit 35fda7f into ruma:main Nov 13, 2024
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

4 participants