muc::user::Item Use parsers' new helpers

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2022-12-27 18:15:31 +01:00
parent 6f7f55a72f
commit 27a0e1523d
Signed by: pep
GPG key ID: DEDA74AEECA9D0F2
4 changed files with 45 additions and 74 deletions

View file

@ -24,7 +24,7 @@ use std::ops::ControlFlow;
use log::debug;
use xmpp_parsers::{
muc::{
user::{Affiliation, Item as MucItem, Reason, Role, Status as MucStatus},
user::{Affiliation, Item as MucItem, Role, Status as MucStatus},
Muc, MucUser,
},
presence::{Presence, Type as PresenceType},
@ -116,10 +116,8 @@ async fn handle_presence_full_available<C: ComponentTrait>(
MucStatus::ServiceErrorKick,
],
items: {
let mut item = MucItem::new(Affiliation::None, Role::None);
item.reason =
Some(Reason(String::from("You are not in the room.")));
vec![item]
vec![MucItem::new(Affiliation::None, Role::None)
.with_reason("You are not in the room.")]
},
}
.into()]);

View file

@ -787,11 +787,9 @@ mod tests {
.with_to(ROSA_FULL1.clone())
.with_payloads(vec![MucUser {
status: vec![MucStatus::SelfPresence],
items: vec![{
let mut item = MucItem::new(Affiliation::Owner, Role::None);
item.jid = Some(ROSA_FULL1.clone());
item
}],
items: vec![
MucItem::new(Affiliation::Owner, Role::None).with_jid(ROSA_FULL1.clone())
],
}
.into()]),
);

View file

@ -29,7 +29,7 @@ use xmpp_parsers::{
delay::Delay,
message::{Message, MessageType, Subject as MessageSubject},
muc::{
user::{Affiliation, Item as MucItem, Reason, Role, Status as MucStatus},
user::{Affiliation, Item as MucItem, Role, Status as MucStatus},
Muc, MucUser,
},
presence::{Presence, Show as PresenceShow, Type as PresenceType},
@ -59,11 +59,8 @@ async fn join_empty_room() {
.with_to(Jid::Full(LOUISE_FULL1.clone()))
.with_payloads(vec![MucUser {
status: vec![MucStatus::SelfPresence, MucStatus::AssignedNick],
items: vec![{
let mut item = MucItem::new(Affiliation::Owner, Role::Moderator);
item.jid = Some(LOUISE_FULL1.clone());
item
}],
items: vec![MucItem::new(Affiliation::Owner, Role::Moderator)
.with_jid(LOUISE_FULL1.clone())],
}
.into()]),
);
@ -220,11 +217,8 @@ async fn join_existing_room() {
.with_to(Jid::Full(SUGAKO_FULL1.clone()))
.with_payloads(vec![MucUser {
status: vec![MucStatus::SelfPresence, MucStatus::AssignedNick],
items: vec![{
let mut item = MucItem::new(Affiliation::Owner, Role::Moderator);
item.jid = Some(SUGAKO_FULL1.clone());
item
}],
items: vec![MucItem::new(Affiliation::Owner, Role::Moderator)
.with_jid(SUGAKO_FULL1.clone())],
}
.into()]),
);
@ -336,11 +330,8 @@ async fn resync() {
.with_to(Jid::Full(LOUISE_FULL1.clone()))
.with_payloads(vec![MucUser {
status: vec![MucStatus::SelfPresence, MucStatus::AssignedNick],
items: vec![{
let mut item = MucItem::new(Affiliation::Owner, Role::Moderator);
item.jid = Some(LOUISE_FULL1.clone());
item
}],
items: vec![MucItem::new(Affiliation::Owner, Role::Moderator)
.with_jid(LOUISE_FULL1.clone())],
}
.into()]),
);
@ -401,11 +392,9 @@ async fn leave_last_participant() {
.with_to(Jid::Full(LOUISE_FULL1.clone()))
.with_payloads(vec![MucUser {
status: vec![MucStatus::SelfPresence],
items: vec![{
let mut item = MucItem::new(Affiliation::Owner, Role::None);
item.jid = Some(LOUISE_FULL1.clone());
item
}],
items: vec![
MucItem::new(Affiliation::Owner, Role::None).with_jid(LOUISE_FULL1.clone())
],
}
.into()]),
);
@ -486,11 +475,9 @@ async fn leave_room_not_last() {
.with_to(Jid::Full(SUGAKO_FULL1.clone()))
.with_payloads(vec![MucUser {
status: vec![MucStatus::SelfPresence],
items: vec![{
let mut item = MucItem::new(Affiliation::Owner, Role::None);
item.jid = Some(SUGAKO_FULL1.clone());
item
}],
items: vec![
MucItem::new(Affiliation::Owner, Role::None).with_jid(SUGAKO_FULL1.clone())
],
}
.into()]),
);
@ -566,9 +553,8 @@ async fn update_not_joined() {
MucStatus::ServiceErrorKick,
],
items: {
let mut item = MucItem::new(Affiliation::None, Role::None);
item.reason = Some(Reason(String::from("You are not in the room.")));
vec![item]
vec![MucItem::new(Affiliation::None, Role::None)
.with_reason("You are not in the room.")]
},
}
.into()]),

View file

@ -55,11 +55,8 @@ async fn join() {
.with_to(Jid::Full(LOUISE_FULL1.clone()))
.with_payloads(vec![MucUser {
status: vec![MucStatus::SelfPresence, MucStatus::AssignedNick],
items: vec![{
let mut item = MucItem::new(Affiliation::Owner, Role::Moderator);
item.jid = Some(LOUISE_FULL1.clone());
item
}],
items: vec![MucItem::new(Affiliation::Owner, Role::Moderator)
.with_jid(LOUISE_FULL1.clone())],
}
.into()]),
);
@ -78,14 +75,12 @@ async fn join() {
.with_to(Jid::Full(LOUISE_FULL1.clone()))
.with_payloads(vec![MucUser {
status: Vec::new(),
items: {
let item = MucItem::new(Affiliation::Owner, Role::Moderator);
let mut item1 = item.clone();
item1.jid = Some(LOUISE_FULL1.clone());
let mut item2 = item.clone();
item2.jid = Some(LOUISE_FULL2.clone());
vec![item1, item2]
},
items: vec![
MucItem::new(Affiliation::Owner, Role::Moderator)
.with_jid(LOUISE_FULL1.clone()),
MucItem::new(Affiliation::Owner, Role::Moderator)
.with_jid(LOUISE_FULL2.clone()),
],
}
.into()]),
);
@ -97,14 +92,12 @@ async fn join() {
.with_to(Jid::Full(LOUISE_FULL2.clone()))
.with_payloads(vec![MucUser {
status: vec![MucStatus::SelfPresence, MucStatus::AssignedNick],
items: {
let item = MucItem::new(Affiliation::Owner, Role::Moderator);
let mut item1 = item.clone();
item1.jid = Some(LOUISE_FULL1.clone());
let mut item2 = item.clone();
item2.jid = Some(LOUISE_FULL2.clone());
vec![item1, item2]
},
items: vec![
MucItem::new(Affiliation::Owner, Role::Moderator)
.with_jid(LOUISE_FULL1.clone()),
MucItem::new(Affiliation::Owner, Role::Moderator)
.with_jid(LOUISE_FULL2.clone()),
],
}
.into()]),
);
@ -167,13 +160,11 @@ async fn leave() {
.with_to(Jid::Full(LOUISE_FULL2.clone()))
.with_payloads(vec![MucUser {
status: vec![MucStatus::SelfPresence],
items: {
let mut item1 = MucItem::new(Affiliation::Owner, Role::Moderator);
item1.jid = Some(LOUISE_FULL1.clone());
let mut item2 = MucItem::new(Affiliation::Owner, Role::None);
item2.jid = Some(LOUISE_FULL2.clone());
vec![item1, item2]
},
items: vec![
MucItem::new(Affiliation::Owner, Role::Moderator)
.with_jid(LOUISE_FULL1.clone()),
MucItem::new(Affiliation::Owner, Role::None).with_jid(LOUISE_FULL2.clone()),
],
}
.into()]),
);
@ -185,13 +176,11 @@ async fn leave() {
.with_to(Jid::Full(LOUISE_FULL1.clone()))
.with_payloads(vec![MucUser {
status: vec![],
items: {
let mut item1 = MucItem::new(Affiliation::Owner, Role::Moderator);
item1.jid = Some(LOUISE_FULL1.clone());
let mut item2 = MucItem::new(Affiliation::Owner, Role::None);
item2.jid = Some(LOUISE_FULL2.clone());
vec![item1, item2]
},
items: vec![
MucItem::new(Affiliation::Owner, Role::Moderator)
.with_jid(LOUISE_FULL1.clone()),
MucItem::new(Affiliation::Owner, Role::None).with_jid(LOUISE_FULL2.clone()),
],
}
.into()]),
);