Occupant: Allow any session to be updated always

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2022-12-26 16:54:06 +01:00
parent cca88740c7
commit 1b74fce690
Signed by: pep
GPG key ID: DEDA74AEECA9D0F2
3 changed files with 9 additions and 24 deletions

View file

@ -33,9 +33,6 @@ pub enum Error {
SessionAlreadyExists(Session),
/// Raised when fetching an occupant with a nickname that isn't assigned in the room.
ParticipantNotFound(String),
/// Raised whenever an operation is applied to a session which isn't the primary session, used
/// for Multi-Session Nick support.
SecondarySession(Session),
/// The origin (from) JID isn't of the expected for (bare or full)
InvalidOriginJid,
/// The destination (to) JID isn't of the expected for (bare or full)
@ -60,7 +57,6 @@ impl fmt::Display for Error {
Error::NonexistantSession(err) => write!(f, "Session doesn't exist: {:?}", err),
Error::SessionAlreadyExists(err) => write!(f, "Session already exist: {:?}", err),
Error::ParticipantNotFound(err) => write!(f, "Participant not found: {}", err),
Error::SecondarySession(err) => write!(f, "Secondary session: {:?}", err),
Error::InvalidOriginJid => write!(f, "Invalid origin JID"),
Error::InvalidDestinationJid => write!(f, "Invalid destination JID"),
Error::UnhandledIq(err) => write!(f, "Unhandled Iq: {:?}", err),

View file

@ -92,12 +92,8 @@ impl Occupant {
for (i, session) in self.sessions.iter().enumerate() {
if &own_session == session {
if i == 0 {
// Primary session
self.sessions[0] = own_session;
return Ok(());
}
return Err(Error::SecondarySession(own_session));
self.sessions[i] = own_session;
return Ok(());
}
}
@ -130,9 +126,7 @@ impl Occupant {
#[cfg(test)]
mod tests {
use super::*;
use crate::tests::templates::{
LOUISE_FULL1, LOUISE_FULL2, LOUISE_NICK, LOUISE_ROOM1_PART, ROOM1_BARE,
};
use crate::tests::templates::{LOUISE_FULL1, LOUISE_FULL2, LOUISE_ROOM1_PART};
use xmpp_parsers::{
muc::{
user::{Affiliation, Item as MucItem, Role},
@ -191,16 +185,11 @@ mod tests {
.unwrap();
match occupant.update_presence(presence2.clone()) {
Err(Error::SecondarySession(session)) if session.real() == &*LOUISE_FULL2 => (),
err => panic!(
"Should return Error::SecondarySession(Session {{ {:?} }}), returned: {:?}",
*LOUISE_FULL2, err,
),
Ok(()) => (),
err => panic!("Error: {:?}", err),
}
assert_eq!(
occupant.sessions[1],
Session::try_from(presence2.clone()).unwrap()
);
assert_eq!(occupant.sessions[1].presence, presence2);
let presence_leave_louise2 = PresenceFull::try_from(
Presence::new(PresenceType::Unavailable)
@ -213,7 +202,7 @@ mod tests {
match occupant.update_presence(presence2) {
Err(Error::NonexistantSession(session)) if session.real() == &*LOUISE_FULL2 => (),
err => panic!(
"Should return Error::SecondarySession(Session {{ {:?} }}), returned: {:?}",
"Should return Error::NonexistantSession(Session {{ {:?} }}), returned: {:?}",
*LOUISE_FULL2, err,
),
}

View file

@ -317,7 +317,7 @@ impl Room {
let occupant = self.get_mut_occupant(&session)?;
match occupant.update_presence(session.presence.clone()) {
Ok(_) | Err(Error::SecondarySession(_)) => (),
Ok(_) => (),
err => err?,
}