-
Notifications
You must be signed in to change notification settings - Fork 330
feat(sdk,ffi): Add server_vendor_info method to matrix-sdk with automatic logging in FFI #5515
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
Changes from 2 commits
31c0d8f
2929ffa
7bed5ea
80d868b
9a15775
f5669ce
c89a9cc
d81a541
7d13bd6
2e3f822
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,7 @@ use ruma::{ | |
uiaa, | ||
user_directory::search_users, | ||
}, | ||
federation::discovery::get_server_version, | ||
error::FromHttpResponseError, | ||
FeatureFlag, MatrixVersion, OutgoingRequest, SupportedVersions, | ||
}, | ||
|
@@ -151,6 +152,15 @@ pub enum SessionChange { | |
TokensRefreshed, | ||
} | ||
|
||
/// Information about the server version obtained from the federation API. | ||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
pub struct ServerVersionInfo { | ||
/// The server name. | ||
pub server_name: OwnedServerName, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @copilot This should be a plain There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed |
||
/// The server version. | ||
pub version: String, | ||
} | ||
|
||
/// An async/await enabled Matrix client. | ||
/// | ||
/// All of the state is held in an `Arc` so the `Client` can be cloned freely. | ||
|
@@ -521,6 +531,40 @@ impl Client { | |
Ok(res.capabilities) | ||
} | ||
|
||
/// Get the server version information from the federation API. | ||
/// | ||
/// This method calls the `/_matrix/federation/v1/version` endpoint to get | ||
/// both the server name and version. | ||
bnjbvr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// | ||
/// # Examples | ||
/// | ||
/// ```no_run | ||
/// # use matrix_sdk::Client; | ||
/// # use url::Url; | ||
/// # async { | ||
/// # let homeserver = Url::parse("http://example.com")?; | ||
/// let client = Client::new(homeserver).await?; | ||
/// | ||
/// let server_info = client.server_version().await?; | ||
/// println!("Server: {}, Version: {}", server_info.server_name, server_info.version); | ||
/// # anyhow::Ok(()) }; | ||
/// ``` | ||
pub async fn server_version(&self) -> HttpResult<ServerVersionInfo> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we rename this method There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed method from |
||
let res = self.send(get_server_version::v1::Request::new()).await?; | ||
|
||
// Extract server info, using defaults if fields are missing | ||
bnjbvr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let server = res.server.unwrap_or_default(); | ||
let server_name_str = server.name.unwrap_or_else(|| "unknown".to_string()); | ||
let version = server.version.unwrap_or_else(|| "unknown".to_string()); | ||
|
||
// Try to parse the server name, fallback to a safe default if parsing fails | ||
let server_name = server_name_str | ||
.try_into() | ||
.unwrap_or_else(|_| "unknown.server".try_into().unwrap()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As per the other comment: this isn't required, as the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed the parsing logic for |
||
|
||
Ok(ServerVersionInfo { server_name, version }) | ||
} | ||
|
||
/// Get a copy of the default request config. | ||
/// | ||
/// The default request config is what's used when sending requests if no | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we name this
ServerVendorInfo
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed
ServerVersionInfo
toServerVendorInfo
as requested in commit c89a9cc.