slack_blocks/elems/select/multi/
user.rs

1//! # Multi-Select User List
2//!
3//! [slack api docs 🔗](https://api.slack.com/reference/block-kit/block-elements#users_multi_select)
4//!
5//! This multi-select menu will populate its options with
6//! a list of Slack users visible to the current user in the active workspace.
7
8use std::borrow::Cow;
9
10use serde::{Deserialize, Serialize};
11#[cfg(feature = "validation")]
12use validator::Validate;
13
14#[cfg(feature = "validation")]
15use crate::val_helpr::ValidationResult;
16use crate::{compose::Confirm, elems::select::user::build, text};
17
18/// # Multi-Select User List
19///
20/// [slack api docs 🔗](https://api.slack.com/reference/block-kit/block-elements#users_multi_select)
21///
22/// This multi-select menu will populate its options with
23/// a list of Slack users visible to the current user in the active workspace.
24#[derive(Clone, Debug, Deserialize, Hash, PartialEq, Serialize)]
25#[cfg_attr(feature = "validation", derive(Validate))]
26pub struct User<'a> {
27  #[cfg_attr(feature = "validation",
28             validate(custom = "crate::elems::select::validate::placeholder"))]
29  pub(in crate::elems::select) placeholder: text::Text,
30
31  #[cfg_attr(feature = "validation", validate(length(max = 255)))]
32  pub(in crate::elems::select) action_id: Cow<'a, str>,
33
34  #[serde(skip_serializing_if = "Option::is_none")]
35  #[cfg_attr(feature = "validation", validate)]
36  pub(in crate::elems::select) confirm: Option<Confirm>,
37
38  #[serde(skip_serializing_if = "Option::is_none")]
39  pub(in crate::elems::select) initial_users: Option<Vec<Cow<'a, str>>>,
40
41  #[cfg_attr(feature = "validation", validate(range(min = 1)))]
42  #[serde(skip_serializing_if = "Option::is_none")]
43  pub(in crate::elems::select) max_selected_items: Option<u32>,
44}
45
46impl<'a> User<'a> {
47  /// Build a new user multi-select element
48  ///
49  /// # Examples
50  /// ```
51  /// // TODO(#130)
52  /// ```
53  pub fn builder() -> build::MultiUserBuilderInit<'a> {
54    build::MultiUserBuilderInit::new()
55  }
56
57  /// Validate that this user select agrees with Slack's model requirements
58  ///
59  /// # Errors
60  /// - If `from_placeholder_and_action_id` was called with
61  ///     `placeholder` longer than 150 chars
62  /// - If `from_placeholder_and_action_id` was called with
63  ///     `action_id` longer than 255 chars
64  ///
65  /// # Example
66  /// ```
67  /// use slack_blocks::elems::select;
68  ///
69  /// let select = select::multi::User::builder().placeholder(
70  ///                           r#"Hey I really would appreciate it if you chose
71  ///         a channel relatively soon, so that we can figure out
72  ///         where we need to send this poll, ok? it's kind of
73  ///         important that you specify where this poll should be
74  ///         sent, in case we haven't made that super clear.
75  ///         If you understand, could you pick a channel, already??"#,
76  /// )
77  ///              .action_id("ABC123")
78  ///              .build();
79  ///
80  /// assert!(matches!(select.validate(), Err(_)))
81  /// ```
82  #[cfg(feature = "validation")]
83  #[cfg_attr(docsrs, doc(cfg(feature = "validation")))]
84  pub fn validate(&self) -> ValidationResult {
85    Validate::validate(&self)
86  }
87}