Room::broadcast_presence: change parameters again

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2022-09-18 18:28:49 +02:00
parent e7d31e41dc
commit 4ec1aa42b4

View file

@ -70,9 +70,8 @@ impl Room {
pub async fn broadcast_presence<C: ComponentTrait>( pub async fn broadcast_presence<C: ComponentTrait>(
&self, &self,
component: &mut C, component: &mut C,
own_participant: &FullJid, own_occupant: &Occupant,
own_session: &Session, own_session: &Session,
own_nick: &Nick,
mode: BroadcastPresence, mode: BroadcastPresence,
) -> Result<(), Error> { ) -> Result<(), Error> {
let leave = mode == BroadcastPresence::Leave; let leave = mode == BroadcastPresence::Leave;
@ -92,7 +91,7 @@ impl Room {
let presence_to_old = Presence::new( let presence_to_old = Presence::new(
if leave { PresenceType::Unavailable } else { PresenceType::None } if leave { PresenceType::Unavailable } else { PresenceType::None }
) )
.with_from(Jid::Full(own_participant.clone())) .with_from(Jid::Full(own_occupant.participant.clone()))
.with_payloads(vec![MucUser { .with_payloads(vec![MucUser {
status: Vec::new(), status: Vec::new(),
items: vec![ items: vec![
@ -117,7 +116,7 @@ impl Room {
/* /*
// MucItems to be sent to sessions of this occupant // MucItems to be sent to sessions of this occupant
let self_items = occupant.iter().map(|session| { let self_items = own_occupant.iter().map(|session| {
MucItem { MucItem {
affiliation: Affiliation::Owner, affiliation: Affiliation::Owner,
role: Role::Moderator, role: Role::Moderator,
@ -132,7 +131,7 @@ impl Room {
for (_, other) in self.occupants.iter() { for (_, other) in self.occupants.iter() {
if sync { // Send presences from others to participant. if sync { // Send presences from others to participant.
if own_nick != &other.nick { if own_occupant.nick != &other.nick {
let presence = presence_to_new.clone() let presence = presence_to_new.clone()
.with_from(Jid::Full(other.participant.clone())); .with_from(Jid::Full(other.participant.clone()));
component.send_stanza(presence).await?; component.send_stanza(presence).await?;
@ -158,7 +157,7 @@ impl Room {
let self_presence = Presence::new( let self_presence = Presence::new(
if leave { PresenceType::Unavailable } else { PresenceType::None } if leave { PresenceType::Unavailable } else { PresenceType::None }
) )
.with_from(Jid::Full(own_participant.clone())) .with_from(Jid::Full(own_occupant.participant.clone()))
.with_to(own_session.clone()) .with_to(own_session.clone())
.with_payloads(vec![MucUser { .with_payloads(vec![MucUser {
status: if leave { vec![ status: if leave { vec![
@ -255,9 +254,8 @@ impl Room {
Some(BroadcastPresence::Resync) => { Some(BroadcastPresence::Resync) => {
self.broadcast_presence( self.broadcast_presence(
component, component,
&occupant.participant, &occupant,
&realjid, &realjid,
&new_nick,
BroadcastPresence::Resync, BroadcastPresence::Resync,
).await?; ).await?;
}, },
@ -266,9 +264,8 @@ impl Room {
self.broadcast_presence( self.broadcast_presence(
component, component,
&occupant.participant, &occupant,
&realjid, &realjid,
&new_nick,
BroadcastPresence::Join, BroadcastPresence::Join,
).await?; ).await?;
self.send_subject(component, realjid, occupant.clone()).await?; self.send_subject(component, realjid, occupant.clone()).await?;
@ -289,9 +286,8 @@ impl Room {
if let Some(mut occupant) = self.occupants.remove(&nick) { if let Some(mut occupant) = self.occupants.remove(&nick) {
self.broadcast_presence( self.broadcast_presence(
component, component,
&occupant.participant, &occupant,
&realjid, &realjid,
&nick,
BroadcastPresence::Leave, BroadcastPresence::Leave,
).await?; ).await?;
@ -386,7 +382,6 @@ mod tests {
#[tokio::test] #[tokio::test]
async fn test_broadcast_presence() { async fn test_broadcast_presence() {
let own_nick = String::from("nick3");
let roomjid = BareJid::from_str("room@muc").unwrap(); let roomjid = BareJid::from_str("room@muc").unwrap();
let realjid1 = FullJid::from_str("foo@bar/qxx").unwrap(); let realjid1 = FullJid::from_str("foo@bar/qxx").unwrap();
let participant1 = roomjid.clone().with_resource(String::from("nick1")); let participant1 = roomjid.clone().with_resource(String::from("nick1"));
@ -404,9 +399,8 @@ mod tests {
room.occupants.insert( room.occupants.insert(
participant2.resource.clone(), Occupant::new(&room, realjid2.clone(), String::from("nick2")), participant2.resource.clone(), Occupant::new(&room, realjid2.clone(), String::from("nick2")),
); );
room.occupants.insert( let occupant3 = Occupant::new(&room, realjid3.clone(), String::from("nick3"));
participant3.resource.clone(), Occupant::new(&room, realjid3.clone(), String::from("nick3")), room.occupants.insert(participant3.resource.clone(), occupant3.clone());
);
// BroadcastPresence::Resync // BroadcastPresence::Resync
let mut component = TestComponent::new(vec![]); let mut component = TestComponent::new(vec![]);
@ -447,7 +441,7 @@ mod tests {
]) ])
); );
room.broadcast_presence(&mut component, &participant3, &realjid3, &own_nick, BroadcastPresence::Resync).await.unwrap(); room.broadcast_presence(&mut component, &occupant3, &realjid3, BroadcastPresence::Resync).await.unwrap();
component.assert(); component.assert();
// BroadcastPresence::Update // BroadcastPresence::Update
@ -477,7 +471,7 @@ mod tests {
]) ])
); );
room.broadcast_presence(&mut component, &participant3, &realjid3, &own_nick, BroadcastPresence::Update).await.unwrap(); room.broadcast_presence(&mut component, &occupant3, &realjid3, BroadcastPresence::Update).await.unwrap();
component.assert(); component.assert();
// BroadcastPresence::Join // BroadcastPresence::Join
@ -543,7 +537,7 @@ mod tests {
]) ])
); );
room.broadcast_presence(&mut component, &participant3, &realjid3, &own_nick, BroadcastPresence::Join).await.unwrap(); room.broadcast_presence(&mut component, &occupant3, &realjid3, BroadcastPresence::Join).await.unwrap();
component.assert(); component.assert();
// BroadcastPresence::Leave // BroadcastPresence::Leave
@ -585,7 +579,7 @@ mod tests {
]) ])
); );
room.broadcast_presence(&mut component, &participant3, &realjid3, &own_nick, BroadcastPresence::Leave).await.unwrap(); room.broadcast_presence(&mut component, &occupant3, &realjid3, BroadcastPresence::Leave).await.unwrap();
component.assert(); component.assert();
} }