cargo fmt/clippy no more warnings
parent
4ac9153be1
commit
db62c1fa25
|
@ -354,7 +354,6 @@ impl AsyncClient {
|
|||
let mut response = self.send(request).await?;
|
||||
|
||||
for (room_id, room) in &mut response.rooms.join {
|
||||
|
||||
let mut client = self.base_client.write().await;
|
||||
|
||||
let _matrix_room = {
|
||||
|
|
|
@ -31,7 +31,7 @@ use crate::events::collections::only::Event as NonRoomEvent;
|
|||
use crate::events::ignored_user_list::IgnoredUserListEvent;
|
||||
use crate::events::push_rules::{PushRulesEvent, Ruleset};
|
||||
use crate::events::EventResult;
|
||||
use crate::identifiers::{RoomId, RoomAliasId, UserId};
|
||||
use crate::identifiers::{RoomAliasId, RoomId, UserId};
|
||||
use crate::models::Room;
|
||||
use crate::session::Session;
|
||||
use crate::EventEmitter;
|
||||
|
@ -207,20 +207,11 @@ impl Client {
|
|||
pub(crate) fn handle_ignored_users(&mut self, event: &IgnoredUserListEvent) -> bool {
|
||||
// this avoids cloning every UserId for the eq check
|
||||
if self.ignored_users.iter().collect::<Vec<_>>()
|
||||
== event
|
||||
.content
|
||||
.ignored_users
|
||||
.iter()
|
||||
.collect::<Vec<_>>()
|
||||
== event.content.ignored_users.iter().collect::<Vec<_>>()
|
||||
{
|
||||
false
|
||||
} else {
|
||||
self.ignored_users = event
|
||||
.content
|
||||
.ignored_users
|
||||
.iter()
|
||||
.cloned()
|
||||
.collect::<Vec<_>>();
|
||||
self.ignored_users = event.content.ignored_users.to_vec();
|
||||
true
|
||||
}
|
||||
}
|
||||
|
@ -293,7 +284,11 @@ impl Client {
|
|||
/// * `room_id` - The unique id of the room the event belongs to.
|
||||
///
|
||||
/// * `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;
|
||||
room.receive_state_event(event)
|
||||
}
|
||||
|
@ -308,7 +303,11 @@ impl Client {
|
|||
/// * `room_id` - The unique id of the room the event belongs to.
|
||||
///
|
||||
/// * `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.
|
||||
if let Some(room) = self.get_room(room_id) {
|
||||
let mut room = room.lock().await;
|
||||
|
|
|
@ -8,4 +8,3 @@ pub use user::User;
|
|||
|
||||
#[allow(dead_code)]
|
||||
pub type Token = String;
|
||||
pub type UserId = String;
|
||||
|
|
|
@ -28,7 +28,7 @@ use crate::events::room::{
|
|||
name::NameEvent,
|
||||
power_levels::PowerLevelsEvent,
|
||||
};
|
||||
use crate::identifiers::{RoomId, RoomAliasId, UserId};
|
||||
use crate::identifiers::{RoomAliasId, RoomId, UserId};
|
||||
|
||||
use js_int::UInt;
|
||||
|
||||
|
@ -83,7 +83,11 @@ impl RoomName {
|
|||
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.
|
||||
// the order in which we check for a name ^^
|
||||
if let Some(name) = &self.name {
|
||||
|
@ -144,13 +148,17 @@ impl Room {
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
@ -179,7 +187,10 @@ impl Room {
|
|||
match event.membership_change() {
|
||||
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)
|
||||
} else {
|
||||
false
|
||||
|
@ -223,7 +234,10 @@ impl Room {
|
|||
///
|
||||
/// Returns true if the room name changed, false otherwise.
|
||||
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)
|
||||
} else {
|
||||
false
|
||||
|
@ -284,11 +298,7 @@ impl Room {
|
|||
///
|
||||
/// * `event` - The presence event for a specified room member.
|
||||
pub fn receive_presence_event(&mut self, event: &PresenceEvent) -> bool {
|
||||
if let Some(user) = self
|
||||
.members
|
||||
.get_mut(&event.sender)
|
||||
.map(|m| &mut m.user)
|
||||
{
|
||||
if let Some(user) = self.members.get_mut(&event.sender).map(|m| &mut m.user) {
|
||||
if user.did_update_presence(event) {
|
||||
false
|
||||
} else {
|
||||
|
|
|
@ -84,6 +84,8 @@ async fn room_names() {
|
|||
assert_eq!(vec!["tutorial"], client.get_room_names().await);
|
||||
assert_eq!(
|
||||
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
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue