Return SessionAlreadyExists error in Occupant::add_session
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
307a888a0b
commit
ef03c1b032
2 changed files with 9 additions and 0 deletions
|
@ -24,6 +24,7 @@ pub enum Error {
|
||||||
MismatchJids(Jid, Jid),
|
MismatchJids(Jid, Jid),
|
||||||
NickAlreadyAssigned(String),
|
NickAlreadyAssigned(String),
|
||||||
NonexistantSession(FullJid),
|
NonexistantSession(FullJid),
|
||||||
|
SessionAlreadyExists(FullJid),
|
||||||
XMPPError(TokioXMPPError),
|
XMPPError(TokioXMPPError),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +36,7 @@ impl fmt::Display for Error {
|
||||||
Error::MismatchJids(jid1, jid2) => write!(f, "Mismatch Jids: {}, {}", jid1, jid2),
|
Error::MismatchJids(jid1, jid2) => write!(f, "Mismatch Jids: {}, {}", jid1, jid2),
|
||||||
Error::NickAlreadyAssigned(err) => write!(f, "Nickname already assigned: {}", err),
|
Error::NickAlreadyAssigned(err) => write!(f, "Nickname already assigned: {}", err),
|
||||||
Error::NonexistantSession(err) => write!(f, "Session doesn't exist: {}", err),
|
Error::NonexistantSession(err) => write!(f, "Session doesn't exist: {}", err),
|
||||||
|
Error::SessionAlreadyExists(err) => write!(f, "Session already exist: {}", err),
|
||||||
Error::XMPPError(err) => write!(f, "XMPP error: {}", err),
|
Error::XMPPError(err) => write!(f, "XMPP error: {}", err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -224,6 +224,13 @@ impl Occupant {
|
||||||
return Err(Error::MismatchJids(Jid::from(self.real.clone()), Jid::from(real.clone())));
|
return Err(Error::MismatchJids(Jid::from(self.real.clone()), Jid::from(real.clone())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for session in &self.sessions {
|
||||||
|
if &real == session {
|
||||||
|
return Err(Error::SessionAlreadyExists(real))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.sessions.push(real);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue