-
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 6 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 | ||||
---|---|---|---|---|---|---|
|
@@ -574,6 +574,17 @@ impl ClientBuilder { | |||||
|
||||||
let sdk_client = inner_builder.build().await?; | ||||||
|
||||||
// Log server version information at info level | ||||||
if let Ok(server_info) = sdk_client.server_version().await { | ||||||
tracing::info!( | ||||||
server_name = %server_info.server_name, | ||||||
version = %server_info.version, | ||||||
"Connected to Matrix server" | ||||||
); | ||||||
} else { | ||||||
tracing::debug!("Could not retrieve server version information"); | ||||||
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.
Suggested change
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 log level from |
||||||
} | ||||||
|
||||||
Ok(Arc::new( | ||||||
Client::new( | ||||||
sdk_client, | ||||||
|
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 { | ||
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 name this 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 |
||
/// The server name. | ||
pub server_name: String, | ||
/// 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,35 @@ 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()); | ||
|
||
Ok(ServerVersionInfo { server_name: server_name_str, version }) | ||
} | ||
|
||
/// Get a copy of the default request config. | ||
/// | ||
/// The default request config is what's used when sending requests if no | ||
|
Uh oh!
There was an error while loading. Please reload this page.