drive_v3/objects/
comment.rs

1use std::fmt;
2use serde::{Serialize, Deserialize};
3
4use super::{Reply, User};
5
6/// The file content to which the comment refers, typically within the anchor
7/// region.
8///
9/// For a text file, for example, this would be the text at the location of the
10/// comment.
11#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
12#[serde(rename_all = "camelCase")]
13pub struct QuotedFileContent {
14    /// The MIME type of the quoted content.
15    #[serde(skip_serializing_if = "Option::is_none")]
16    pub mime_type: Option<String>,
17
18    /// The quoted content itself.
19    ///
20    /// This is interpreted as plain text if set through the API.
21    #[serde(skip_serializing_if = "Option::is_none")]
22    pub value: Option<String>,
23}
24
25impl fmt::Display for QuotedFileContent {
26    fn fmt( &self, f: &mut fmt::Formatter<'_> ) -> fmt::Result {
27        let json = serde_json::to_string_pretty(&self)
28            .unwrap_or( format!("unable to parse JSON, this is the debug view:\n{:#?}", self) );
29
30        write!(f, "{}", json)
31    }
32}
33
34impl QuotedFileContent {
35    /// Creates a new, empty instance of this struct.
36    pub fn new() -> Self {
37        Self { ..Default::default() }
38    }
39}
40
41/// A comment on a file.
42#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
43#[serde(rename_all = "camelCase")]
44pub struct Comment {
45    /// The ID of the comment.
46    #[serde(skip_serializing_if = "Option::is_none")]
47    pub id: Option<String>,
48
49    /// Identifies what kind of resource this is.
50    ///
51    /// This is always `drive#comment`.
52    #[serde(skip_serializing_if = "Option::is_none")]
53    pub kind: Option<String>,
54
55    /// The time at which the comment was created (RFC 3339 date-time).
56    #[serde(skip_serializing_if = "Option::is_none")]
57    pub created_time: Option<String>,
58
59    /// The last time the comment or any of its replies was modified
60    /// (RFC 3339 date-time).
61    #[serde(skip_serializing_if = "Option::is_none")]
62    pub modified_time: Option<String>,
63
64    /// Whether the comment has been resolved by one of its replies.
65    #[serde(skip_serializing_if = "Option::is_none")]
66    pub resolved: Option<bool>,
67
68    /// A region of the document represented as a JSON string.
69    ///
70    /// For details on defining anchor properties, refer to Google's
71    /// [Manage comments and replies](https://developers.google.com/drive/api/v3/manage-comments)
72    /// documentation.
73    #[serde(skip_serializing_if = "Option::is_none")]
74    pub anchor: Option<String>,
75
76    /// The full list of replies to the comment in chronological order.
77    #[serde(skip_serializing_if = "Option::is_none")]
78    pub replies: Option<Vec<Reply>>,
79
80    /// The author of the reply.
81    ///
82    /// The author's email address and permission ID will not be populated.
83    #[serde(skip_serializing_if = "Option::is_none")]
84    pub author: Option<User>,
85
86    /// Whether the reply has been deleted.
87    ///
88    /// A deleted reply has no content.
89    #[serde(skip_serializing_if = "Option::is_none")]
90    pub deleted: Option<bool>,
91
92    /// The content of the reply with HTML formatting.
93    #[serde(skip_serializing_if = "Option::is_none")]
94    pub html_content: Option<String>,
95
96    /// The plain text content of the reply.
97    ///
98    /// This field is used for setting the content, while
99    /// [`html_content`](Reply::html_content) should be displayed. This is
100    /// required on creates if no `action` is specified.
101    #[serde(skip_serializing_if = "Option::is_none")]
102    pub content: Option<String>,
103
104    /// The file content to which the comment refers, typically within the
105    /// anchor region.
106    ///
107    /// For a text file, for example, this would be the text at the location of
108    /// the comment.
109    #[serde(skip_serializing_if = "Option::is_none")]
110    pub quoted_file_content: Option<QuotedFileContent>,
111}
112
113#[doc(hidden)]
114impl From<&Self> for Comment {
115    fn from( reference: &Self ) -> Self {
116        reference.clone()
117    }
118}
119
120impl fmt::Display for Comment {
121    fn fmt( &self, f: &mut fmt::Formatter<'_> ) -> fmt::Result {
122        let json = serde_json::to_string_pretty(&self)
123            .unwrap_or( format!("unable to parse JSON, this is the debug view:\n{:#?}", self) );
124
125        write!(f, "{}", json)
126    }
127}
128
129impl Comment {
130    /// Creates a new, empty instance of this struct.
131    pub fn new() -> Self {
132        Self { ..Default::default() }
133    }
134}
135
136/// A list of comments on a file.
137#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
138#[serde(rename_all = "camelCase")]
139pub struct CommentList {
140    /// Identifies what kind of resource this is.
141    ///
142    /// This is always `drive#commentList`.
143    #[serde(skip_serializing_if = "Option::is_none")]
144    pub kind: Option<String>,
145
146    /// The list of comments.
147    ///
148    /// If [`next_page_token`](CommentList::next_page_token) is populated, then
149    /// this list may be incomplete and an additional page of results should be
150    /// fetched.
151    #[serde(skip_serializing_if = "Option::is_none")]
152    pub comments: Option<Vec<Comment>>,
153
154    /// The page token for the next page of comments.
155    ///
156    /// This will be absent if the end of the comments list has been reached. If
157    /// the token is rejected for any reason, it should be discarded, and
158    /// pagination should be restarted from the first page of results. The page
159    /// token is typically valid for several hours. However, if new items are
160    /// added or removed, your expected results might differ.
161    #[serde(skip_serializing_if = "Option::is_none")]
162    pub next_page_token: Option<String>,
163}
164
165impl fmt::Display for CommentList {
166    fn fmt( &self, f: &mut fmt::Formatter<'_> ) -> fmt::Result {
167        let json = serde_json::to_string_pretty(&self)
168            .unwrap_or( format!("unable to parse JSON, this is the debug view:\n{:#?}", self) );
169
170        write!(f, "{}", json)
171    }
172}
173
174impl CommentList {
175    /// Creates a new, empty instance of this struct.
176    pub fn new() -> Self {
177        Self { ..Default::default() }
178    }
179}