diff --git a/crates/ruma-common/src/events.rs b/crates/ruma-common/src/events.rs index 27cde056..ff805e0b 100644 --- a/crates/ruma-common/src/events.rs +++ b/crates/ruma-common/src/events.rs @@ -102,6 +102,8 @@ //! )); //! ``` +use std::collections::BTreeSet; + use serde::{de::IgnoredAny, Deserialize, Serialize, Serializer}; use crate::{EventEncryptionAlgorithm, OwnedUserId, RoomVersionId}; @@ -231,9 +233,9 @@ pub fn serialize_custom_event_error(_: &T, _: S) -> Result, + /// Defaults to an empty `BTreeSet`. + #[serde(default, skip_serializing_if = "BTreeSet::is_empty")] + pub user_ids: BTreeSet, /// Whether the whole room is mentioned. /// @@ -249,8 +251,8 @@ impl Mentions { } /// Create a `Mentions` for the given user IDs. - pub fn with_user_ids(user_ids: Vec) -> Self { - Self { user_ids, ..Default::default() } + pub fn with_user_ids(user_ids: impl IntoIterator) -> Self { + Self { user_ids: BTreeSet::from_iter(user_ids), ..Default::default() } } /// Create a `Mentions` for a room mention.