slack_blocks/elems/select/multi/
conversation.rs

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