diff --git a/src/room.rs b/src/room.rs index f02237b..f537bc0 100644 --- a/src/room.rs +++ b/src/room.rs @@ -94,7 +94,7 @@ impl Room { .into()]); // New participant to all other sessions - let presence_to_old = Presence::new(if leave { + let mut presence_to_old = Presence::new(if leave { PresenceType::Unavailable } else { PresenceType::None @@ -109,6 +109,9 @@ impl Room { } .into()]); + // Populate presence with newly received payloads + own_session.fill_presence(&mut presence_to_old); + for (_, other) in self.occupants.iter() { // Skip sending to all our sessions, we do it later. if own_occupant.nick == other.nick { diff --git a/src/session.rs b/src/session.rs index 1ff3123..bd2a182 100644 --- a/src/session.rs +++ b/src/session.rs @@ -54,6 +54,15 @@ impl Session { _ => unreachable!(), } } + + pub fn fill_presence(&self, presence: &mut Presence) { + presence.priority = self.presence.priority; + presence.show = self.presence.show.clone(); + presence.statuses = self.presence.statuses.clone(); + for elem in self.presence.payloads.clone().into_iter() { + presence.payloads.push(elem); + } + } } impl PartialEq for Session { diff --git a/src/tests/presence.rs b/src/tests/presence.rs index c093a78..604f36b 100644 --- a/src/tests/presence.rs +++ b/src/tests/presence.rs @@ -18,7 +18,8 @@ use crate::handlers::handle_stanza; use crate::room::Room; use crate::tests::templates::{ new_room, two_participant_room, LOUISE_FULL1, LOUISE_FULL2, LOUISE_NICK, LOUISE_ROOM1_PART, - ROOM1_BARE, ROSA_FULL1, ROSA_ROOM1_PART, SUGAKO_FULL1, SUGAKO_NICK, SUGAKO_ROOM1_PART, + PETER_FULL1, PETER_NICK, PETER_ROOM1_PART, ROOM1_BARE, ROSA_FULL1, ROSA_ROOM1_PART, + SUGAKO_FULL1, SUGAKO_NICK, SUGAKO_ROOM1_PART, }; use std::collections::{BTreeMap, HashMap}; @@ -604,15 +605,24 @@ async fn test_join_msn() { } } -#[ignore] #[tokio::test] async fn test_presence_update_joined() { let mut rooms: HashMap = HashMap::new(); - rooms.insert(ROOM1_BARE.clone(), two_participant_room(ROOM1_BARE.clone())); + rooms.insert( + ROOM1_BARE.clone(), + new_room( + ROOM1_BARE.clone(), + vec![ + (SUGAKO_FULL1.clone(), SUGAKO_NICK), + (PETER_FULL1.clone(), PETER_NICK), + ], + ) + .await, + ); let update1: Element = Presence::new(PresenceType::None) - .with_from(Jid::Full(SUGAKO_FULL1.clone())) - .with_to(Jid::Full(SUGAKO_ROOM1_PART.clone())) + .with_from(Jid::Full(PETER_FULL1.clone())) + .with_to(Jid::Full(PETER_ROOM1_PART.clone())) .with_show(PresenceShow::Away) .into(); @@ -620,8 +630,8 @@ async fn test_presence_update_joined() { component.expect( Presence::new(PresenceType::None) - .with_from(Jid::Full(SUGAKO_ROOM1_PART.clone())) - .with_to(Jid::Full(LOUISE_FULL1.clone())) + .with_from(Jid::Full(PETER_ROOM1_PART.clone())) + .with_to(Jid::Full(SUGAKO_FULL1.clone())) .with_payloads(vec![MucUser { status: Vec::new(), items: vec![MucItem::new(Affiliation::Owner, Role::Moderator)],