cargo fmt/clippy no more warnings

master
Devin R 2020-04-03 09:14:46 -04:00
parent 4ac9153be1
commit db62c1fa25
5 changed files with 37 additions and 28 deletions

View File

@ -354,7 +354,6 @@ impl AsyncClient {
let mut response = self.send(request).await?; let mut response = self.send(request).await?;
for (room_id, room) in &mut response.rooms.join { for (room_id, room) in &mut response.rooms.join {
let mut client = self.base_client.write().await; let mut client = self.base_client.write().await;
let _matrix_room = { let _matrix_room = {

View File

@ -31,7 +31,7 @@ use crate::events::collections::only::Event as NonRoomEvent;
use crate::events::ignored_user_list::IgnoredUserListEvent; use crate::events::ignored_user_list::IgnoredUserListEvent;
use crate::events::push_rules::{PushRulesEvent, Ruleset}; use crate::events::push_rules::{PushRulesEvent, Ruleset};
use crate::events::EventResult; use crate::events::EventResult;
use crate::identifiers::{RoomId, RoomAliasId, UserId}; use crate::identifiers::{RoomAliasId, RoomId, UserId};
use crate::models::Room; use crate::models::Room;
use crate::session::Session; use crate::session::Session;
use crate::EventEmitter; use crate::EventEmitter;
@ -207,20 +207,11 @@ impl Client {
pub(crate) fn handle_ignored_users(&mut self, event: &IgnoredUserListEvent) -> bool { pub(crate) fn handle_ignored_users(&mut self, event: &IgnoredUserListEvent) -> bool {
// this avoids cloning every UserId for the eq check // this avoids cloning every UserId for the eq check
if self.ignored_users.iter().collect::<Vec<_>>() if self.ignored_users.iter().collect::<Vec<_>>()
== event == event.content.ignored_users.iter().collect::<Vec<_>>()
.content
.ignored_users
.iter()
.collect::<Vec<_>>()
{ {
false false
} else { } else {
self.ignored_users = event self.ignored_users = event.content.ignored_users.to_vec();
.content
.ignored_users
.iter()
.cloned()
.collect::<Vec<_>>();
true true
} }
} }
@ -293,7 +284,11 @@ impl Client {
/// * `room_id` - The unique id of the room the event belongs to. /// * `room_id` - The unique id of the room the event belongs to.
/// ///
/// * `event` - The event that should be handled by the client. /// * `event` - The event that should be handled by the client.
pub async fn receive_joined_state_event(&mut self, room_id: &RoomId, event: &StateEvent) -> bool { pub async fn receive_joined_state_event(
&mut self,
room_id: &RoomId,
event: &StateEvent,
) -> bool {
let mut room = self.get_or_create_room(room_id).lock().await; let mut room = self.get_or_create_room(room_id).lock().await;
room.receive_state_event(event) room.receive_state_event(event)
} }
@ -308,7 +303,11 @@ impl Client {
/// * `room_id` - The unique id of the room the event belongs to. /// * `room_id` - The unique id of the room the event belongs to.
/// ///
/// * `event` - The event that should be handled by the client. /// * `event` - The event that should be handled by the client.
pub async fn receive_presence_event(&mut self, room_id: &RoomId, event: &PresenceEvent) -> bool { pub async fn receive_presence_event(
&mut self,
room_id: &RoomId,
event: &PresenceEvent,
) -> bool {
// this should be the room that was just created in the `Client::sync` loop. // this should be the room that was just created in the `Client::sync` loop.
if let Some(room) = self.get_room(room_id) { if let Some(room) = self.get_room(room_id) {
let mut room = room.lock().await; let mut room = room.lock().await;

View File

@ -8,4 +8,3 @@ pub use user::User;
#[allow(dead_code)] #[allow(dead_code)]
pub type Token = String; pub type Token = String;
pub type UserId = String;

View File

@ -28,7 +28,7 @@ use crate::events::room::{
name::NameEvent, name::NameEvent,
power_levels::PowerLevelsEvent, power_levels::PowerLevelsEvent,
}; };
use crate::identifiers::{RoomId, RoomAliasId, UserId}; use crate::identifiers::{RoomAliasId, RoomId, UserId};
use js_int::UInt; use js_int::UInt;
@ -83,7 +83,11 @@ impl RoomName {
true true
} }
pub fn calculate_name(&self, room_id: &RoomId, members: &HashMap<UserId, RoomMember>) -> String { pub fn calculate_name(
&self,
room_id: &RoomId,
members: &HashMap<UserId, RoomMember>,
) -> String {
// https://matrix.org/docs/spec/client_server/latest#calculating-the-display-name-for-a-room. // https://matrix.org/docs/spec/client_server/latest#calculating-the-display-name-for-a-room.
// the order in which we check for a name ^^ // the order in which we check for a name ^^
if let Some(name) = &self.name { if let Some(name) = &self.name {
@ -144,13 +148,17 @@ impl Room {
} }
fn add_member(&mut self, event: &MemberEvent) -> bool { fn add_member(&mut self, event: &MemberEvent) -> bool {
if self.members.contains_key(&UserId::try_from(event.state_key.as_str()).unwrap()) { if self
.members
.contains_key(&UserId::try_from(event.state_key.as_str()).unwrap())
{
return false; return false;
} }
let member = RoomMember::new(event); let member = RoomMember::new(event);
self.members.insert(UserId::try_from(event.state_key.as_str()).unwrap(), member); self.members
.insert(UserId::try_from(event.state_key.as_str()).unwrap(), member);
true true
} }
@ -179,7 +187,10 @@ impl Room {
match event.membership_change() { match event.membership_change() {
MembershipChange::Invited | MembershipChange::Joined => self.add_member(event), MembershipChange::Invited | MembershipChange::Joined => self.add_member(event),
_ => { _ => {
if let Some(member) = self.members.get_mut(&UserId::try_from(event.state_key.as_str()).unwrap()) { if let Some(member) = self
.members
.get_mut(&UserId::try_from(event.state_key.as_str()).unwrap())
{
member.update_member(event) member.update_member(event)
} else { } else {
false false
@ -223,7 +234,10 @@ impl Room {
/// ///
/// Returns true if the room name changed, false otherwise. /// Returns true if the room name changed, false otherwise.
pub fn handle_power_level(&mut self, event: &PowerLevelsEvent) -> bool { pub fn handle_power_level(&mut self, event: &PowerLevelsEvent) -> bool {
if let Some(member) = self.members.get_mut(&UserId::try_from(event.state_key.as_str()).unwrap()) { if let Some(member) = self
.members
.get_mut(&UserId::try_from(event.state_key.as_str()).unwrap())
{
member.update_power(event) member.update_power(event)
} else { } else {
false false
@ -284,11 +298,7 @@ impl Room {
/// ///
/// * `event` - The presence event for a specified room member. /// * `event` - The presence event for a specified room member.
pub fn receive_presence_event(&mut self, event: &PresenceEvent) -> bool { pub fn receive_presence_event(&mut self, event: &PresenceEvent) -> bool {
if let Some(user) = self if let Some(user) = self.members.get_mut(&event.sender).map(|m| &mut m.user) {
.members
.get_mut(&event.sender)
.map(|m| &mut m.user)
{
if user.did_update_presence(event) { if user.did_update_presence(event) {
false false
} else { } else {

View File

@ -84,6 +84,8 @@ async fn room_names() {
assert_eq!(vec!["tutorial"], client.get_room_names().await); assert_eq!(vec!["tutorial"], client.get_room_names().await);
assert_eq!( assert_eq!(
Some("tutorial".into()), Some("tutorial".into()),
client.get_room_name(&RoomId::try_from("!SVkFJHzfwvuaIEawgC:localhost").unwrap()).await client
.get_room_name(&RoomId::try_from("!SVkFJHzfwvuaIEawgC:localhost").unwrap())
.await
); );
} }