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 #4228

Merged
merged 4 commits into from
Dec 5, 2024

Conversation

MatMaul
Copy link
Contributor

@MatMaul MatMaul commented Nov 6, 2024

This is the follow up of this Ruma PR for the SDK.

Ruma PR needs to be merged first.

@MatMaul MatMaul requested a review from a team as a code owner November 6, 2024 16:01
@MatMaul MatMaul requested review from bnjbvr and removed request for a team November 6, 2024 16:01
Copy link
Member

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

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

I don't think losing static typing is an option, instead we should introduce an enum that can be one of all the types we expect (owned user id OR email address, if I understand correctly).

Also, BaseRoomInfo is serialized in the database, so we'd need a test making sure that we don't need a migration there, when the previous content was serialized as a OwneduserId; if the test fails, we need a migration.

@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
@MatMaul
Copy link
Contributor Author

MatMaul commented Nov 6, 2024

I don't think losing static typing is an option, instead we should introduce an enum that can be one of all the types we expect (owned user id OR email address, if I understand correctly).

Fine for me, but it also needs to support phone numbers I think, basically any identifier types.

Fine for you ?

@MatMaul
Copy link
Contributor Author

MatMaul commented Nov 6, 2024

Beware that it will not solve the trouble for some legacy buggy behavior of Element Web.

@bnjbvr
Copy link
Member

bnjbvr commented Nov 6, 2024

Fine for you ?

Fine if we do have some type checking / upfront validation for all these other id types indeed :)

@MatMaul
Copy link
Contributor Author

MatMaul commented Nov 6, 2024

Is there a way to not fully failed m.direct parsing when only some entries are invalid ?

The entry should just be omitted in this case I believe.

Should I keep implementing FromIterator<(String, Vec<OwnedRoomId>)>, try to .from the string with the UserIdentifier enum we are talking about, and then put that in a BTreeMap<UserIdentifier, Vec<OwnedRoomId>> ?

@MatMaul
Copy link
Contributor Author

MatMaul commented Nov 6, 2024

So I think the question is, will serde uses FromIterator<(String, Vec<OwnedRoomId>)> or not to deserialize the JSON in this case ?

If not, what would be suited to do to still deserialize m.direct account data with invalid entries in it ?

@spaetz
Copy link

spaetz commented Nov 7, 2024

If introducing ENUMS can we have an "UNKNOWN" too please which could catch either nonsense, such as "[object Object]": or other id's that this SDK perhaps does not know about (yet)?

@MatMaul
Copy link
Contributor Author

MatMaul commented Nov 7, 2024

Yes I think I have a way with something like that @spaetz , thanks.

Copy link

codecov bot commented Nov 13, 2024

Codecov Report

Attention: Patch coverage is 90.90909% with 1 line in your changes missing coverage. Please review.

Project coverage is 85.17%. Comparing base (22cb8a1) to head (b4e9586).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...tes/matrix-sdk-base/src/store/migration_helpers.rs 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4228      +/-   ##
==========================================
+ Coverage   85.15%   85.17%   +0.02%     
==========================================
  Files         280      280              
  Lines       30858    30861       +3     
==========================================
+ Hits        26278    26287       +9     
+ Misses       4580     4574       -6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Cargo.toml Show resolved Hide resolved
@MatMaul MatMaul force-pushed the fix-dm branch 4 times, most recently from bdff7aa to a624790 Compare December 3, 2024 23:10
@MatMaul MatMaul requested a review from poljar December 4, 2024 00:23
Copy link
Member

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

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

Does OwnedDirectUserIdentifier deserialize cleanly from an OwnedUserId? Otherwise this needs a migration, since we're storing the BaseRoomInfo in db

crates/matrix-sdk-base/src/store/migration_helpers.rs Outdated Show resolved Hide resolved
@bnjbvr
Copy link
Member

bnjbvr commented Dec 4, 2024

Does OwnedDirectUserIdentifier deserialize cleanly from an OwnedUserId? Otherwise this needs a migration, since we're storing the BaseRoomInfo in db

GOOD NEWS, EVERYONE! Since both are encoded as strings, and use the IdZst derive macro, they serialize and deserialize as a string, so this shouldn't require a migration. I would be grateful if a tiny test were added for this, to confirm my understanding: it would serialize an OwnedUserId and deserialize it as a OwnedDirectUserIdentifier cleanly. With that and the other review comment I've made above, LGTM 👍

@MatMaul
Copy link
Contributor Author

MatMaul commented Dec 4, 2024

I would be grateful if a tiny test were added for this

This feels like something that should be in Ruma, here is the PR.

@MatMaul MatMaul requested a review from bnjbvr December 4, 2024 14:02
Copy link
Member

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

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

lgtm, thanks.

crates/matrix-sdk-base/src/store/migration_helpers.rs Outdated Show resolved Hide resolved
@bnjbvr bnjbvr enabled auto-merge (squash) December 5, 2024 12:21
@bnjbvr bnjbvr removed the request for review from poljar December 5, 2024 12:21
@bnjbvr bnjbvr merged commit ee30008 into matrix-org:main Dec 5, 2024
41 checks passed
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

Successfully merging this pull request may close these issues.

5 participants