Small code cleanup in matrix.rs
continuous-integration/drone/push Build is passing Details

This commit is contained in:
projectmoon 2021-02-08 20:14:11 +00:00
parent d42e075c5c
commit ef4f1ef02f
1 changed files with 22 additions and 24 deletions

View File

@ -1,40 +1,38 @@
use log::error;
use matrix_sdk::events::{
use matrix_sdk::Error as MatrixError;
use matrix_sdk::{
events::{
room::message::{MessageEventContent::Notice, NoticeMessageEventContent},
AnyMessageEventContent::RoomMessage,
},
RoomMember,
};
use matrix_sdk::Error as MatrixError;
use matrix_sdk::{identifiers::RoomId, Client};
/// Extracts more detailed error messages out of a matrix SDK error.
fn extract_error_message(error: MatrixError) -> String {
use matrix_sdk::{Error::Http, HttpError};
match error {
Http(http_err) => match http_err {
HttpError::FromHttpResponse(ruma_err) => ruma_err.to_string(),
_ => http_err.to_string(),
},
_ => error.to_string(),
if let Http(HttpError::FromHttpResponse(ruma_err)) = error {
ruma_err.to_string()
} else {
error.to_string()
}
}
/// Retrieve a list of users in a given room.
pub async fn get_users_in_room(client: &Client, room_id: &RoomId) -> Vec<String> {
if let Some(joined_room) = client.get_joined_room(room_id) {
joined_room
.joined_members()
.await
.ok()
.unwrap_or_default()
.into_iter()
.map(|member| {
let members: Vec<RoomMember> = joined_room.joined_members().await.ok().unwrap_or_default();
let to_username = |member: RoomMember| {
format!(
"@{}:{}",
member.user_id().localpart(),
member.user_id().server_name()
)
})
.collect()
};
members.into_iter().map(to_username).collect()
} else {
vec![]
}