room: clippy
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
3b59bd1312
commit
12d23e2283
1 changed files with 10 additions and 16 deletions
26
src/room.rs
26
src/room.rs
|
@ -36,7 +36,7 @@ use xmpp_parsers::{
|
|||
pub type Nick = String;
|
||||
type Session = FullJid;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum BroadcastPresence {
|
||||
/// Resource joined the room. It needs to know about all other participants, and other
|
||||
/// participants needs to know about it.
|
||||
|
@ -74,7 +74,7 @@ impl Room {
|
|||
own_session: &Session,
|
||||
mode: BroadcastPresence,
|
||||
) -> Result<(), Error> {
|
||||
let leave = mode == BroadcastPresence::Leave;
|
||||
let leave = matches!(mode, BroadcastPresence::Leave);
|
||||
|
||||
// All participants to new participant
|
||||
let presence_to_new = Presence::new(if leave {
|
||||
|
@ -105,14 +105,8 @@ impl Room {
|
|||
}
|
||||
.into()]);
|
||||
|
||||
let sync = match mode {
|
||||
BroadcastPresence::Join | BroadcastPresence::Resync => true,
|
||||
_ => false,
|
||||
};
|
||||
let update = match mode {
|
||||
BroadcastPresence::Join | BroadcastPresence::Update => true,
|
||||
_ => false,
|
||||
};
|
||||
let sync = matches!(mode, BroadcastPresence::Join | BroadcastPresence::Resync);
|
||||
let update = matches!(mode, BroadcastPresence::Join | BroadcastPresence::Update);
|
||||
|
||||
for (_, other) in self.occupants.iter() {
|
||||
if own_occupant.nick == other.nick {
|
||||
|
@ -245,7 +239,7 @@ impl Room {
|
|||
new_nick: Nick,
|
||||
) -> Result<(), Error> {
|
||||
// Ensure nick isn't already assigned
|
||||
let _ = self.occupants.iter().try_for_each(|(nick, occupant)| {
|
||||
self.occupants.iter().try_for_each(|(nick, occupant)| {
|
||||
let new_nick = new_nick.as_str();
|
||||
if new_nick == nick && occupant.real != BareJid::from(realjid.clone()) {
|
||||
return Err(Error::NickAlreadyAssigned(String::from(new_nick)));
|
||||
|
@ -268,20 +262,20 @@ impl Room {
|
|||
if !self.occupants.contains_key(&new_nick) {
|
||||
let _ = self.occupants.insert(
|
||||
new_nick.clone(),
|
||||
Occupant::new(&self, realjid.clone(), new_nick.clone()),
|
||||
Occupant::new(self, realjid.clone(), new_nick.clone()),
|
||||
);
|
||||
}
|
||||
let occupant = self.occupants.get(&new_nick).unwrap();
|
||||
|
||||
match mode {
|
||||
Some(BroadcastPresence::Resync) => {
|
||||
self.broadcast_presence(component, &occupant, &realjid, BroadcastPresence::Resync)
|
||||
self.broadcast_presence(component, occupant, &realjid, BroadcastPresence::Resync)
|
||||
.await?;
|
||||
}
|
||||
Some(BroadcastPresence::Join) => {
|
||||
debug!("{} is joining {}", realjid, self.jid);
|
||||
|
||||
self.broadcast_presence(component, &occupant, &realjid, BroadcastPresence::Join)
|
||||
self.broadcast_presence(component, occupant, &realjid, BroadcastPresence::Join)
|
||||
.await?;
|
||||
self.send_subject(component, realjid, occupant.clone())
|
||||
.await?;
|
||||
|
@ -316,7 +310,7 @@ impl Room {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Occupant {
|
||||
/// Public Jid for the Occupant
|
||||
pub real: BareJid,
|
||||
|
@ -339,7 +333,7 @@ impl Occupant {
|
|||
if BareJid::from(real.clone()) != self.real {
|
||||
return Err(Error::MismatchJids(
|
||||
Jid::from(self.real.clone()),
|
||||
Jid::from(real.clone()),
|
||||
Jid::from(real),
|
||||
));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue