Skip to content

Commit 90ab115

Browse files
authored
fix: SlackRichTextList elements type (#359)
* fix: SlackRichTextList elements type * chore: An example update
1 parent cf3a611 commit 90ab115

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

examples/socket_mode.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,34 @@ impl SlackBlocksTemplate for SlackHomeTabBlocksTemplateExample {
194194
.into()
195195
)
196196
.into(),
197+
SlackRichTextList::new(
198+
SlackRichTextListStyle::Bullet,
199+
vec![
200+
SlackRichTextSection::new(
201+
vec![SlackRichTextInlineElement::Text(SlackRichTextText::new(
202+
"Item 1".into()
203+
))]
204+
.into(),
205+
)
206+
.into(),
207+
SlackRichTextSection::new(
208+
vec![SlackRichTextInlineElement::Text(SlackRichTextText::new(
209+
"Item 2".into()
210+
))]
211+
.into(),
212+
)
213+
.into()
214+
]
215+
.into()
216+
)
217+
.into(),
218+
SlackRichTextPreformatted::new(
219+
vec![SlackRichTextInlineElement::Text(SlackRichTextText::new(
220+
"Let's use some preformatted text: ".into()
221+
))]
222+
.into(),
223+
)
224+
.into(),
197225
]
198226
.into()
199227
))

src/models/blocks/kit.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1133,12 +1133,25 @@ pub struct SlackRichTextSection {
11331133
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Builder)]
11341134
pub struct SlackRichTextList {
11351135
pub style: SlackRichTextListStyle,
1136-
pub elements: Vec<SlackRichTextSection>,
1136+
pub elements: Vec<SlackRichTextListElement>,
11371137
pub indent: Option<u64>,
11381138
pub offset: Option<u64>,
11391139
pub border: Option<u64>,
11401140
}
11411141

1142+
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
1143+
#[serde(tag = "type")]
1144+
pub enum SlackRichTextListElement {
1145+
#[serde(rename = "rich_text_section")]
1146+
Section(SlackRichTextSection),
1147+
}
1148+
1149+
impl From<SlackRichTextSection> for SlackRichTextListElement {
1150+
fn from(element: SlackRichTextSection) -> Self {
1151+
SlackRichTextListElement::Section(element)
1152+
}
1153+
}
1154+
11421155
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
11431156
#[serde(rename_all = "snake_case")]
11441157
pub enum SlackRichTextListStyle {
@@ -1492,6 +1505,16 @@ mod test {
14921505
assert_eq!(list.style, SlackRichTextListStyle::Bullet);
14931506
assert_eq!(list.elements.len(), 2);
14941507

1508+
// list items are SlackRichTextElement::Section
1509+
assert!(matches!(
1510+
&list.elements[0],
1511+
SlackRichTextListElement::Section(_)
1512+
));
1513+
assert!(matches!(
1514+
&list.elements[1],
1515+
SlackRichTextListElement::Section(_)
1516+
));
1517+
14951518
// preformatted
14961519
assert!(matches!(
14971520
&rich.elements[2],

0 commit comments

Comments
 (0)