Skip to main content

rustigram_types/
checklist.rs

1use serde::{Deserialize, Serialize};
2
3use crate::chat::Chat;
4use crate::message::{MessageEntity, ParseMode};
5use crate::user::User;
6
7/// A single task in a checklist.
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct ChecklistTask {
10    /// Unique identifier of the task.
11    pub id: i64,
12    /// Text of the task.
13    pub text: String,
14    /// Special entities that appear in the task text.
15    #[serde(skip_serializing_if = "Option::is_none")]
16    pub text_entities: Option<Vec<MessageEntity>>,
17    /// User that completed the task; omitted if not completed by a user.
18    #[serde(skip_serializing_if = "Option::is_none")]
19    pub completed_by_user: Option<User>,
20    /// Chat that completed the task; omitted if not completed by a chat.
21    #[serde(skip_serializing_if = "Option::is_none")]
22    pub completed_by_chat: Option<Chat>,
23    /// Unix timestamp when the task was completed; `0` if not completed.
24    #[serde(skip_serializing_if = "Option::is_none")]
25    pub completion_date: Option<i64>,
26}
27
28/// A checklist message content type.
29#[derive(Debug, Clone, Serialize, Deserialize)]
30pub struct Checklist {
31    /// Title of the checklist.
32    pub title: String,
33    /// Special entities in the checklist title.
34    #[serde(skip_serializing_if = "Option::is_none")]
35    pub title_entities: Option<Vec<MessageEntity>>,
36    /// List of tasks in the checklist.
37    pub tasks: Vec<ChecklistTask>,
38    /// `true` if users other than the creator can add tasks.
39    #[serde(skip_serializing_if = "Option::is_none")]
40    pub others_can_add_tasks: Option<bool>,
41    /// `true` if users other than the creator can mark tasks as done or not done.
42    #[serde(skip_serializing_if = "Option::is_none")]
43    pub others_can_mark_tasks_as_done: Option<bool>,
44}
45
46/// A task to add when creating or editing a checklist.
47#[derive(Debug, Clone, Serialize, Deserialize)]
48pub struct InputChecklistTask {
49    /// Unique identifier of the task; must be positive and unique within the checklist.
50    pub id: i64,
51    /// Text of the task (1–100 characters after entities parsing).
52    pub text: String,
53    /// Parse mode for entities in the task text.
54    #[serde(skip_serializing_if = "Option::is_none")]
55    pub parse_mode: Option<ParseMode>,
56    /// Special entities in the task text; alternative to `parse_mode`.
57    #[serde(skip_serializing_if = "Option::is_none")]
58    pub text_entities: Option<Vec<MessageEntity>>,
59}
60
61/// A checklist to send or create.
62#[derive(Debug, Clone, Serialize, Deserialize)]
63pub struct InputChecklist {
64    /// Title of the checklist (1–255 characters after entities parsing).
65    pub title: String,
66    /// Parse mode for entities in the title.
67    #[serde(skip_serializing_if = "Option::is_none")]
68    pub parse_mode: Option<ParseMode>,
69    /// Special entities in the title; alternative to `parse_mode`.
70    #[serde(skip_serializing_if = "Option::is_none")]
71    pub title_entities: Option<Vec<MessageEntity>>,
72    /// List of 1–30 tasks in the checklist.
73    pub tasks: Vec<InputChecklistTask>,
74    /// Pass `true` if other users can add tasks to the checklist.
75    #[serde(skip_serializing_if = "Option::is_none")]
76    pub others_can_add_tasks: Option<bool>,
77    /// Pass `true` if other users can mark tasks as done or not done.
78    #[serde(skip_serializing_if = "Option::is_none")]
79    pub others_can_mark_tasks_as_done: Option<bool>,
80}
81
82/// Service message: tasks in a checklist were marked as done or not done.
83#[derive(Debug, Clone, Serialize, Deserialize)]
84pub struct ChecklistTasksDone {
85    /// Message containing the checklist whose tasks were updated.
86    ///
87    /// Boxed to break the recursive `Message → ChecklistTasksDone → Message` cycle.
88    /// Will not contain `reply_to_message` even if the message itself is a reply.
89    #[serde(skip_serializing_if = "Option::is_none")]
90    pub checklist_message: Option<Box<crate::message::Message>>,
91    /// Identifiers of the tasks that were marked as done.
92    #[serde(skip_serializing_if = "Option::is_none")]
93    pub marked_as_done_task_ids: Option<Vec<i64>>,
94    /// Identifiers of the tasks that were marked as not done.
95    #[serde(skip_serializing_if = "Option::is_none")]
96    pub marked_as_not_done_task_ids: Option<Vec<i64>>,
97}
98
99/// Service message: new tasks were added to a checklist.
100#[derive(Debug, Clone, Serialize, Deserialize)]
101pub struct ChecklistTasksAdded {
102    /// Message containing the checklist to which tasks were added.
103    ///
104    /// Boxed to break the recursive cycle. Will not contain `reply_to_message`.
105    #[serde(skip_serializing_if = "Option::is_none")]
106    pub checklist_message: Option<Box<crate::message::Message>>,
107    /// The tasks that were added.
108    pub tasks: Vec<ChecklistTask>,
109}