diff --git a/src/handlers/presence.rs b/src/handlers/presence.rs index a25c7a6..c8fd166 100644 --- a/src/handlers/presence.rs +++ b/src/handlers/presence.rs @@ -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( 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()]); diff --git a/src/room.rs b/src/room.rs index e29f02b..0a28f3a 100644 --- a/src/room.rs +++ b/src/room.rs @@ -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()]), ); diff --git a/src/tests/presence.rs b/src/tests/presence.rs index 1182e0b..1afa6cf 100644 --- a/src/tests/presence.rs +++ b/src/tests/presence.rs @@ -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()]), diff --git a/src/tests/presence_msn.rs b/src/tests/presence_msn.rs index 72276b5..9acd544 100644 --- a/src/tests/presence_msn.rs +++ b/src/tests/presence_msn.rs @@ -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()]), );