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>(
&self,
component: &mut C,
own_participant: &FullJid,
own_occupant: &Occupant,
own_session: &Session,
own_nick: &Nick,
mode: BroadcastPresence,
) -> Result<(), Error> {
let leave = mode == BroadcastPresence::Leave;
@ -92,7 +91,7 @@ impl Room {
let presence_to_old = Presence::new(
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 {
status: Vec::new(),
items: vec![
@ -117,7 +116,7 @@ impl Room {
/*
// 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 {
affiliation: Affiliation::Owner,
role: Role::Moderator,
@ -132,7 +131,7 @@ impl Room {
for (_, other) in self.occupants.iter() {
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()
.with_from(Jid::Full(other.participant.clone()));
component.send_stanza(presence).await?;
@ -158,7 +157,7 @@ impl Room {
let self_presence = Presence::new(
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_payloads(vec![MucUser {
status: if leave { vec![
@ -255,9 +254,8 @@ impl Room {
Some(BroadcastPresence::Resync) => {
self.broadcast_presence(
component,
&occupant.participant,
&occupant,
&realjid,
&new_nick,
BroadcastPresence::Resync,
).await?;
},
@ -266,9 +264,8 @@ impl Room {
self.broadcast_presence(
component,
&occupant.participant,
&occupant,
&realjid,
&new_nick,
BroadcastPresence::Join,
).await?;
self.send_subject(component, realjid, occupant.clone()).await?;
@ -289,9 +286,8 @@ impl Room {
if let Some(mut occupant) = self.occupants.remove(&nick) {
self.broadcast_presence(
component,
&occupant.participant,
&occupant,
&realjid,
&nick,
BroadcastPresence::Leave,
).await?;
@ -386,7 +382,6 @@ mod tests {
#[tokio::test]
async fn test_broadcast_presence() {
let own_nick = String::from("nick3");
let roomjid = BareJid::from_str("room@muc").unwrap();
let realjid1 = FullJid::from_str("foo@bar/qxx").unwrap();
let participant1 = roomjid.clone().with_resource(String::from("nick1"));
@ -404,9 +399,8 @@ mod tests {
room.occupants.insert(
participant2.resource.clone(), Occupant::new(&room, realjid2.clone(), String::from("nick2")),
);
room.occupants.insert(
participant3.resource.clone(), Occupant::new(&room, realjid3.clone(), String::from("nick3")),
);
let occupant3 = Occupant::new(&room, realjid3.clone(), String::from("nick3"));
room.occupants.insert(participant3.resource.clone(), occupant3.clone());
// BroadcastPresence::Resync
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();
// 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();
// 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();
// 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();
}