1use crate::ids::{ArticleId, UserId};
2use crate::wire::notice::{
3 WireNoticeAt, WireNoticeComment, WireNoticeCount, WireNoticeFollow, WireNoticeMsg,
4 WireNoticePoint, WireNoticeReply, WireNoticeSystem, WireNoticeTag,
5};
6
7#[derive(Clone, Copy, Debug, PartialEq, Eq)]
8pub enum NoticeType {
9 Point,
10 Commented,
11 Reply,
12 At,
13 Following,
14 Broadcast,
15 System,
16}
17
18impl NoticeType {
19 pub fn as_str(&self) -> &'static str {
20 match self {
21 Self::Point => "point",
22 Self::Commented => "commented",
23 Self::Reply => "reply",
24 Self::At => "at",
25 Self::Following => "following",
26 Self::Broadcast => "broadcast",
27 Self::System => "sys-announce",
28 }
29 }
30}
31
32#[derive(Clone, Copy, Debug, PartialEq, Eq)]
33pub enum NoticeMsgType {
34 Refresh,
35 WarnBroadcast,
36}
37
38impl NoticeMsgType {
39 pub fn as_str(&self) -> &'static str {
40 match self {
41 Self::Refresh => "refreshNotification",
42 Self::WarnBroadcast => "warnBroadcast",
43 }
44 }
45
46 pub fn values() -> [&'static str; 2] {
47 ["refreshNotification", "warnBroadcast"]
48 }
49
50 pub fn from_command(command: &str) -> Option<Self> {
51 match command {
52 "refreshNotification" => Some(Self::Refresh),
53 "warnBroadcast" => Some(Self::WarnBroadcast),
54 _ => None,
55 }
56 }
57}
58
59#[derive(Clone, Debug)]
60#[non_exhaustive]
61pub struct NoticeCount {
62 pub notify_status: bool,
64 pub count: u64,
66 pub reply: u64,
68 pub point: u64,
70 pub at: u64,
72 pub broadcast: u64,
74 pub sys_announce: u64,
76 pub new_follower: u64,
78 pub following: u64,
80 pub commented: u64,
82}
83
84impl From<WireNoticeCount> for NoticeCount {
85 fn from(w: WireNoticeCount) -> Self {
86 Self {
87 notify_status: w.notify_status,
88 count: w.count,
89 reply: w.reply,
90 point: w.point,
91 at: w.at,
92 broadcast: w.broadcast,
93 sys_announce: w.sys_announce,
94 new_follower: w.new_follower,
95 following: w.following,
96 commented: w.commented,
97 }
98 }
99}
100
101#[derive(Clone, Debug)]
102#[non_exhaustive]
103pub struct NoticePoint {
104 pub id: String,
106 pub data_id: String,
108 pub user_id: UserId,
110 pub data_type: u32,
112 pub description: String,
114 pub has_read: bool,
116 pub create_time: String,
118}
119
120impl From<WireNoticePoint> for NoticePoint {
121 fn from(w: WireNoticePoint) -> Self {
122 Self {
123 id: w.o_id,
124 data_id: w.data_id,
125 user_id: w.user_id.into(),
126 data_type: w.data_type,
127 description: w.description,
128 has_read: w.has_read,
129 create_time: w.create_time,
130 }
131 }
132}
133
134#[derive(Clone, Debug)]
135#[non_exhaustive]
136pub struct NoticeComment {
137 pub id: String,
139 pub title: String,
141 pub author: String,
143 pub thumbnail_url: String,
145 pub type_: u32,
147 pub perfect: bool,
149 pub content: String,
151 pub sharp_url: String,
153 pub has_read: bool,
155 pub create_time: String,
157}
158
159impl From<WireNoticeComment> for NoticeComment {
160 fn from(w: WireNoticeComment) -> Self {
161 Self {
162 id: w.o_id,
163 title: w.title,
164 author: w.author,
165 thumbnail_url: w.thumbnail_url,
166 type_: w.type_,
167 perfect: w.perfect,
168 content: w.content,
169 sharp_url: w.sharp_url,
170 has_read: w.has_read,
171 create_time: w.create_time,
172 }
173 }
174}
175
176#[derive(Clone, Debug)]
177#[non_exhaustive]
178pub struct NoticeReply {
179 pub id: String,
181 pub title: String,
183 pub author: String,
185 pub thumbnail_url: String,
187 pub type_: u32,
189 pub perfect: bool,
191 pub content: String,
193 pub sharp_url: String,
195 pub has_read: bool,
197 pub create_time: String,
199 pub data_type: u32,
201}
202
203impl From<WireNoticeReply> for NoticeReply {
204 fn from(w: WireNoticeReply) -> Self {
205 Self {
206 id: w.o_id,
207 title: w.title,
208 author: w.author,
209 thumbnail_url: w.thumbnail_url,
210 type_: w.type_,
211 perfect: w.perfect,
212 content: w.content,
213 sharp_url: w.sharp_url,
214 has_read: w.has_read,
215 create_time: w.create_time,
216 data_type: w.data_type,
217 }
218 }
219}
220
221#[derive(Clone, Debug)]
222#[non_exhaustive]
223pub struct NoticeAt {
224 pub id: String,
226 pub data_type: u32,
228 pub user_name: String,
230 pub author_name: String,
232 pub article_title: String,
234 pub article_id: ArticleId,
236 pub url: String,
238 pub at_in_article: bool,
240 pub avatar_url: String,
242 pub user_avatar_url: String,
244 pub content: String,
246 pub description: String,
248 pub has_read: bool,
250 pub create_time: String,
252 pub data_id: String,
254 pub deleted: bool,
256}
257
258impl From<WireNoticeAt> for NoticeAt {
259 fn from(w: WireNoticeAt) -> Self {
260 Self {
261 id: w.o_id,
262 data_type: w.data_type,
263 user_name: w.user_name,
264 author_name: w.author_name,
265 article_title: w.article_title,
266 article_id: w.article_id.into(),
267 url: w.url,
268 at_in_article: w.at_in_article,
269 avatar_url: w.avatar_url,
270 user_avatar_url: w.user_avatar_url,
271 content: w.content,
272 description: w.description,
273 has_read: w.has_read,
274 create_time: w.create_time,
275 data_id: w.data_id,
276 deleted: w.deleted,
277 }
278 }
279}
280
281#[derive(Clone, Debug)]
282#[non_exhaustive]
283pub struct NoticeTag {
284 pub id: String,
286 pub title: String,
288 pub icon_path: String,
290 pub uri: String,
292}
293
294impl From<WireNoticeTag> for NoticeTag {
295 fn from(w: WireNoticeTag) -> Self {
296 Self {
297 id: w.o_id,
298 title: w.title,
299 icon_path: w.icon_path,
300 uri: w.uri,
301 }
302 }
303}
304
305#[derive(Clone, Debug)]
306#[non_exhaustive]
307pub struct NoticeFollow {
308 pub id: String,
310 pub url: String,
312 pub data_type: u32,
314 pub title: String,
316 pub author: String,
318 pub content: String,
320 pub is_comment: bool,
322 pub thumbnail_url: String,
324 pub comment_count: u32,
326 pub perfect: bool,
328 pub tag_objs: Vec<NoticeTag>,
330 pub tags: String,
332 pub type_: u32,
334 pub has_read: bool,
336 pub create_time: String,
338}
339
340impl From<WireNoticeFollow> for NoticeFollow {
341 fn from(w: WireNoticeFollow) -> Self {
342 Self {
343 id: w.o_id,
344 url: w.url,
345 data_type: w.data_type,
346 title: w.title,
347 author: w.author,
348 content: w.content,
349 is_comment: w.is_comment,
350 thumbnail_url: w.thumbnail_url,
351 comment_count: w.comment_count,
352 perfect: w.perfect,
353 tag_objs: w.tag_objs.into_iter().map(NoticeTag::from).collect(),
354 tags: w.tags,
355 type_: w.type_,
356 has_read: w.has_read,
357 create_time: w.create_time,
358 }
359 }
360}
361
362#[derive(Clone, Debug)]
363#[non_exhaustive]
364pub struct NoticeSystem {
365 pub id: String,
367 pub user_id: UserId,
369 pub data_id: String,
371 pub data_type: u32,
373 pub description: String,
375 pub content: String,
377 pub has_read: bool,
379 pub create_time: String,
381}
382
383impl From<WireNoticeSystem> for NoticeSystem {
384 fn from(w: WireNoticeSystem) -> Self {
385 Self {
386 id: w.o_id,
387 user_id: w.user_id.into(),
388 data_id: w.data_id,
389 data_type: w.data_type,
390 description: w.description,
391 content: w.content,
392 has_read: w.has_read,
393 create_time: w.create_time,
394 }
395 }
396}
397
398#[derive(Clone, Debug)]
399#[non_exhaustive]
400pub struct NoticeMsg {
401 pub command: String,
403 pub user_id: UserId,
405 pub content: Option<String>,
407 pub who: Option<String>,
409}
410
411impl From<WireNoticeMsg> for NoticeMsg {
412 fn from(w: WireNoticeMsg) -> Self {
413 Self {
414 command: w.command,
415 user_id: w.user_id.into(),
416 content: w.content,
417 who: w.who,
418 }
419 }
420}
421
422#[derive(Clone, Debug)]
423pub enum NoticeItem {
424 Point(NoticePoint),
426 Comment(NoticeComment),
428 Reply(NoticeReply),
430 At(NoticeAt),
432 Follow(NoticeFollow),
434 System(NoticeSystem),
436}
437
438pub type NoticeList = Vec<NoticeItem>;