Room::broadcast_presence: change parameters again
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
1b5e80529b
commit
74214352bd
1 changed files with 18 additions and 43 deletions
61
src/room.rs
61
src/room.rs
|
@ -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;
|
||||
|
@ -96,7 +95,7 @@ impl Room {
|
|||
} 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![MucItem::new(
|
||||
|
@ -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,
|
||||
|
@ -133,7 +132,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()));
|
||||
|
@ -162,7 +161,7 @@ impl Room {
|
|||
} 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 {
|
||||
|
@ -251,26 +250,14 @@ impl Room {
|
|||
|
||||
match mode {
|
||||
Some(BroadcastPresence::Resync) => {
|
||||
self.broadcast_presence(
|
||||
component,
|
||||
&occupant.participant,
|
||||
&realjid,
|
||||
&new_nick,
|
||||
BroadcastPresence::Resync,
|
||||
)
|
||||
.await?;
|
||||
self.broadcast_presence(component, &occupant, &realjid, BroadcastPresence::Resync)
|
||||
.await?;
|
||||
}
|
||||
Some(BroadcastPresence::Join) => {
|
||||
debug!("{} is joining {}", realjid, self.jid);
|
||||
|
||||
self.broadcast_presence(
|
||||
component,
|
||||
&occupant.participant,
|
||||
&realjid,
|
||||
&new_nick,
|
||||
BroadcastPresence::Join,
|
||||
)
|
||||
.await?;
|
||||
self.broadcast_presence(component, &occupant, &realjid, BroadcastPresence::Join)
|
||||
.await?;
|
||||
self.send_subject(component, realjid, occupant.clone())
|
||||
.await?;
|
||||
}
|
||||
|
@ -288,14 +275,8 @@ impl Room {
|
|||
) -> Result<(), Error> {
|
||||
// If occupant doesn't exist, ignore.
|
||||
if let Some(mut occupant) = self.occupants.remove(&nick) {
|
||||
self.broadcast_presence(
|
||||
component,
|
||||
&occupant.participant,
|
||||
&realjid,
|
||||
&nick,
|
||||
BroadcastPresence::Leave,
|
||||
)
|
||||
.await?;
|
||||
self.broadcast_presence(component, &occupant, &realjid, BroadcastPresence::Leave)
|
||||
.await?;
|
||||
|
||||
occupant.remove_session(realjid)?;
|
||||
} else {
|
||||
|
@ -394,7 +375,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"));
|
||||
|
@ -414,10 +394,9 @@ mod tests {
|
|||
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![]);
|
||||
|
@ -457,9 +436,8 @@ mod tests {
|
|||
|
||||
room.broadcast_presence(
|
||||
&mut component,
|
||||
&participant3,
|
||||
&occupant3,
|
||||
&realjid3,
|
||||
&own_nick,
|
||||
BroadcastPresence::Resync,
|
||||
)
|
||||
.await
|
||||
|
@ -493,9 +471,8 @@ mod tests {
|
|||
|
||||
room.broadcast_presence(
|
||||
&mut component,
|
||||
&participant3,
|
||||
&occupant3,
|
||||
&realjid3,
|
||||
&own_nick,
|
||||
BroadcastPresence::Update,
|
||||
)
|
||||
.await
|
||||
|
@ -562,9 +539,8 @@ mod tests {
|
|||
|
||||
room.broadcast_presence(
|
||||
&mut component,
|
||||
&participant3,
|
||||
&occupant3,
|
||||
&realjid3,
|
||||
&own_nick,
|
||||
BroadcastPresence::Join,
|
||||
)
|
||||
.await
|
||||
|
@ -609,9 +585,8 @@ mod tests {
|
|||
|
||||
room.broadcast_presence(
|
||||
&mut component,
|
||||
&participant3,
|
||||
&occupant3,
|
||||
&realjid3,
|
||||
&own_nick,
|
||||
BroadcastPresence::Leave,
|
||||
)
|
||||
.await
|
||||
|
|
Loading…
Reference in a new issue