1use serde::{Deserialize, Serialize};
4
5use super::model::{ItemKind, MarkupFlavor};
6
7#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
10pub struct ConversationCaps {
11 pub read: bool,
12 pub comment: bool,
13 pub reply_in_thread: bool,
14 pub start_thread: bool,
15 pub edit_own: bool,
16 pub delete_own: bool,
17 pub resolve: bool,
18 pub reactions: bool,
19 pub events: bool,
20 pub internal_notes: bool,
21 pub read_flavor: MarkupFlavor,
22 pub write_flavor: MarkupFlavor,
23 pub max_body: Option<usize>,
24}
25
26impl ConversationCaps {
27 pub const NONE: Self = Self {
29 read: false,
30 comment: false,
31 reply_in_thread: false,
32 start_thread: false,
33 edit_own: false,
34 delete_own: false,
35 resolve: false,
36 reactions: false,
37 events: false,
38 internal_notes: false,
39 read_flavor: MarkupFlavor::PlainText,
40 write_flavor: MarkupFlavor::PlainText,
41 max_body: None,
42 };
43
44 pub fn github(kind: ItemKind) -> Self {
46 Self {
47 read: true,
48 comment: true,
49 reply_in_thread: kind == ItemKind::PullRequest,
50 start_thread: false,
51 edit_own: true,
52 delete_own: true,
53 resolve: kind == ItemKind::PullRequest,
54 reactions: true,
55 events: true,
56 internal_notes: false,
57 read_flavor: MarkupFlavor::Gfm,
58 write_flavor: MarkupFlavor::Gfm,
59 max_body: Some(65_536),
60 }
61 }
62
63 pub fn gitea(kind: ItemKind, can_resolve: bool) -> Self {
66 let pr = kind == ItemKind::PullRequest;
67 Self {
68 read: true,
69 comment: true,
70 reply_in_thread: pr,
71 start_thread: false,
72 edit_own: true,
73 delete_own: true,
74 resolve: pr && can_resolve,
75 reactions: false,
76 events: true,
77 internal_notes: false,
78 read_flavor: MarkupFlavor::GiteaMd,
79 write_flavor: MarkupFlavor::GiteaMd,
80 max_body: None,
81 }
82 }
83
84 pub fn azure_devops(kind: ItemKind, server: bool) -> Self {
91 let pr = kind == ItemKind::PullRequest;
92 Self {
93 read: true,
94 comment: true,
95 reply_in_thread: pr,
96 start_thread: false,
97 edit_own: true,
98 delete_own: true,
99 resolve: false,
100 reactions: false,
101 events: pr,
102 internal_notes: false,
103 read_flavor: MarkupFlavor::AzureMd,
104 write_flavor: if pr || !server {
105 MarkupFlavor::AzureMd
106 } else {
107 MarkupFlavor::Html
108 },
109 max_body: Some(150_000),
110 }
111 }
112
113 pub fn bitbucket(kind: ItemKind) -> Self {
117 if kind == ItemKind::Issue {
118 return Self::NONE;
119 }
120 Self {
121 read: true,
122 comment: true,
123 reply_in_thread: true,
124 start_thread: false,
125 edit_own: true,
126 delete_own: true,
127 resolve: false,
128 reactions: false,
129 events: true,
130 internal_notes: false,
131 read_flavor: MarkupFlavor::BitbucketMd,
132 write_flavor: MarkupFlavor::BitbucketMd,
133 max_body: None,
134 }
135 }
136
137 pub fn gerrit(kind: ItemKind) -> Self {
141 if kind == ItemKind::Issue {
142 return Self::NONE;
143 }
144 Self {
145 read: true,
146 comment: true,
147 reply_in_thread: true,
148 start_thread: false,
149 edit_own: false,
150 delete_own: false,
151 resolve: true,
152 reactions: false,
153 events: true,
154 internal_notes: false,
155 read_flavor: MarkupFlavor::PlainText,
156 write_flavor: MarkupFlavor::PlainText,
157 max_body: None,
158 }
159 }
160
161 pub fn gitlab(kind: ItemKind) -> Self {
163 Self {
164 read: true,
165 comment: true,
166 reply_in_thread: true,
167 start_thread: false,
168 edit_own: true,
169 delete_own: true,
170 resolve: kind == ItemKind::PullRequest,
171 reactions: false,
172 events: true,
173 internal_notes: true,
174 read_flavor: MarkupFlavor::GitlabMd,
175 write_flavor: MarkupFlavor::GitlabMd,
176 max_body: Some(1_000_000),
177 }
178 }
179
180 fn tracker(kind: ItemKind, caps: Self) -> Self {
183 if kind == ItemKind::Issue {
184 caps
185 } else {
186 Self::NONE
187 }
188 }
189
190 pub fn jira(kind: ItemKind) -> Self {
197 Self::tracker(
198 kind,
199 Self {
200 read: true,
201 comment: true,
202 edit_own: true,
203 delete_own: true,
204 events: true,
205 read_flavor: MarkupFlavor::Gfm,
206 write_flavor: MarkupFlavor::JiraWiki,
207 max_body: Some(32_767),
208 ..Self::NONE
209 },
210 )
211 }
212
213 pub fn linear(kind: ItemKind) -> Self {
215 Self::tracker(
216 kind,
217 Self {
218 read: true,
219 comment: true,
220 reply_in_thread: true,
221 edit_own: true,
222 delete_own: true,
223 events: true,
224 read_flavor: MarkupFlavor::Gfm,
225 write_flavor: MarkupFlavor::Gfm,
226 ..Self::NONE
227 },
228 )
229 }
230
231 pub fn youtrack(kind: ItemKind) -> Self {
234 Self::tracker(
235 kind,
236 Self {
237 read: true,
238 comment: true,
239 edit_own: true,
240 delete_own: true,
241 read_flavor: MarkupFlavor::YoutrackMd,
242 write_flavor: MarkupFlavor::YoutrackMd,
243 ..Self::NONE
244 },
245 )
246 }
247
248 pub fn redmine(kind: ItemKind, textile: bool) -> Self {
253 Self::tracker(
254 kind,
255 Self {
256 read: true,
257 comment: true,
258 edit_own: true,
259 events: true,
260 internal_notes: true,
261 read_flavor: MarkupFlavor::Gfm,
262 write_flavor: if textile {
263 MarkupFlavor::Textile
264 } else {
265 MarkupFlavor::Gfm
266 },
267 ..Self::NONE
268 },
269 )
270 }
271
272 pub fn trello(kind: ItemKind) -> Self {
274 Self::tracker(
275 kind,
276 Self {
277 read: true,
278 comment: true,
279 edit_own: true,
280 delete_own: true,
281 events: true,
282 read_flavor: MarkupFlavor::TrelloMd,
283 write_flavor: MarkupFlavor::TrelloMd,
284 max_body: Some(16_384),
285 ..Self::NONE
286 },
287 )
288 }
289
290 pub fn local_markdown(kind: ItemKind) -> Self {
294 Self::tracker(
295 kind,
296 Self {
297 read: true,
298 comment: true,
299 edit_own: true,
300 delete_own: true,
301 read_flavor: MarkupFlavor::ObsidianMd,
302 write_flavor: MarkupFlavor::ObsidianMd,
303 ..Self::NONE
304 },
305 )
306 }
307}