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

feat(sdk): Add Client::server #3908

Merged

Conversation

Hywan
Copy link
Member

@Hywan Hywan commented Aug 28, 2024

This patch adds Client::server as an Option<Url>. This should not be confused with the homeserver. For example, in the case of Matrix, matrix.org is the server, and matrix-client.matrix.org is the homeserver.

This patch should be reviewed commit-by-commit for the sake of simplicity. Code is moved into their own module for clarity.

@Hywan Hywan force-pushed the feat-sdk-client-builder-homeserver-config branch from b2b8543 to b1474f4 Compare August 28, 2024 19:06
Copy link

codecov bot commented Aug 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.14%. Comparing base (9edca06) to head (b073f28).
Report is 27 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3908   +/-   ##
=======================================
  Coverage   84.13%   84.14%           
=======================================
  Files         266      267    +1     
  Lines       28005    28027   +22     
=======================================
+ Hits        23563    23583   +20     
- Misses       4442     4444    +2     

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

This patch adds `Client::server`: the URL of the server.

Not to be confused with the `Client::homeserver`. The `server`
holds some information, like the `.well-known` file, to discover the
homeserver. The homeserver is the client-server Matrix API.

`server` is usually the server part in a user ID, e.g. with
`@mnt_io:matrix.org`, here `matrix.org` is the server, whilst
`matrix-client.matrix.org` is the homeserver.

This patch also moves the code about homeserver discovery in the
`HomeserverConfig::discover` new method. A new struct is introduced to
hold the result, to replace a 4-tuples.

`Client::server` is also now a `Option<_>` because in the case of
`HomeserverConfig::Url`, the server cannot be known.

This patch also removes several clones here and there.

Finally, this patch updates a test to quickly test the new behaviour. A
next patch will introduce proper tests.
This patch moves `client/builder.rs` into `client/builder/mod.rs`.
This patch also moves the `HomeserverConfig` type and its siblings
(`discover_homeserver`, `UrlScheme` etc.) into its own module `client/
builder/homeserver_config.rs`.

This is purely for cleaning up.
@Hywan Hywan force-pushed the feat-sdk-client-builder-homeserver-config branch from b1474f4 to 5fedc09 Compare September 2, 2024 09:46
This API is tested via `Client` and `ClientBuilder` but it's preferable
to unit testing it too, it makes things clearer and cleaner.
@Hywan Hywan force-pushed the feat-sdk-client-builder-homeserver-config branch from dfd78be to 171e06a Compare September 2, 2024 09:58
@Hywan Hywan marked this pull request as ready for review September 2, 2024 10:07
@Hywan Hywan requested a review from a team as a code owner September 2, 2024 10:07
@Hywan Hywan requested review from jmartinesp and removed request for a team September 2, 2024 10:07
Copy link
Contributor

@jmartinesp jmartinesp left a comment

Choose a reason for hiding this comment

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

The changes look good, although the distinction between 'server' and 'home server' is a bit difficult to grasp at first. I might have found an issue with the docs though, if I understood the API correctly.

@@ -30,14 +30,14 @@ use crate::{
/// Configuration for the homeserver.
#[derive(Clone, Debug)]
pub(super) enum HomeserverConfig {
/// A precise URL, including the protocol.
/// A server name URL, including the protocol.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be a homeserver URL?

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed! I want to rename all these variants in another PR because it is so confusing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed and rebased.

This patch fixes an error where the `homeserver` is used for the
`server` value.
@Hywan Hywan force-pushed the feat-sdk-client-builder-homeserver-config branch from 171e06a to b073f28 Compare September 2, 2024 11:46
@Hywan Hywan requested a review from jmartinesp September 2, 2024 11:47
Copy link
Contributor

@jmartinesp jmartinesp left a comment

Choose a reason for hiding this comment

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

Thanks for the changes!

@Hywan Hywan enabled auto-merge (rebase) September 2, 2024 11:53
@Hywan Hywan merged commit 99c44ee into matrix-org:main Sep 2, 2024
39 checks passed
@Hywan Hywan mentioned this pull request Sep 2, 2024
32 tasks
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.

2 participants