fishpi-sdk 1.0.0

A Rust SDK for interacting with the FishPi community API
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
use crate::ids::{ArticleId, UserId};
use crate::wire::notice::{
    WireNoticeAt, WireNoticeComment, WireNoticeCount, WireNoticeFollow, WireNoticeMsg,
    WireNoticePoint, WireNoticeReply, WireNoticeSystem, WireNoticeTag,
};

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum NoticeType {
    Point,
    Commented,
    Reply,
    At,
    Following,
    Broadcast,
    System,
}

impl NoticeType {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::Point => "point",
            Self::Commented => "commented",
            Self::Reply => "reply",
            Self::At => "at",
            Self::Following => "following",
            Self::Broadcast => "broadcast",
            Self::System => "sys-announce",
        }
    }
}

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum NoticeMsgType {
    Refresh,
    WarnBroadcast,
}

impl NoticeMsgType {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::Refresh => "refreshNotification",
            Self::WarnBroadcast => "warnBroadcast",
        }
    }

    pub fn values() -> [&'static str; 2] {
        ["refreshNotification", "warnBroadcast"]
    }

    pub fn from_command(command: &str) -> Option<Self> {
        match command {
            "refreshNotification" => Some(Self::Refresh),
            "warnBroadcast" => Some(Self::WarnBroadcast),
            _ => None,
        }
    }
}

#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct NoticeCount {
    /// 用户是否启用 Web 通知
    pub notify_status: bool,
    /// 未读通知数
    pub count: u64,
    /// 未读回复通知数
    pub reply: u64,
    /// 未读积分通知数
    pub point: u64,
    /// 未读 @ 通知数
    pub at: u64,
    /// 未读同城通知数
    pub broadcast: u64,
    /// 未读系统通知数
    pub sys_announce: u64,
    /// 未读关注者通知数
    pub new_follower: u64,
    /// 未读关注通知数
    pub following: u64,
    /// 未读评论通知数
    pub commented: u64,
}

impl From<WireNoticeCount> for NoticeCount {
    fn from(w: WireNoticeCount) -> Self {
        Self {
            notify_status: w.notify_status,
            count: w.count,
            reply: w.reply,
            point: w.point,
            at: w.at,
            broadcast: w.broadcast,
            sys_announce: w.sys_announce,
            new_follower: w.new_follower,
            following: w.following,
            commented: w.commented,
        }
    }
}

#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct NoticePoint {
    /// 通知 ID
    pub id: String,
    /// 数据 ID
    pub data_id: String,
    /// 用户 ID
    pub user_id: UserId,
    /// 数据类型
    pub data_type: u32,
    /// 通知描述
    pub description: String,
    /// 是否已读
    pub has_read: bool,
    /// 创建时间
    pub create_time: String,
}

impl From<WireNoticePoint> for NoticePoint {
    fn from(w: WireNoticePoint) -> Self {
        Self {
            id: w.o_id,
            data_id: w.data_id,
            user_id: w.user_id.into(),
            data_type: w.data_type,
            description: w.description,
            has_read: w.has_read,
            create_time: w.create_time,
        }
    }
}

#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct NoticeComment {
    /// 通知 ID
    pub id: String,
    /// 文章标题
    pub title: String,
    /// 文章作者
    pub author: String,
    /// 作者头像
    pub thumbnail_url: String,
    /// 文章类型
    pub type_: u32,
    /// 是否精选
    pub perfect: bool,
    /// 评论内容
    pub content: String,
    /// 评论地址
    pub sharp_url: String,
    /// 是否已读
    pub has_read: bool,
    /// 评论时间
    pub create_time: String,
}

impl From<WireNoticeComment> for NoticeComment {
    fn from(w: WireNoticeComment) -> Self {
        Self {
            id: w.o_id,
            title: w.title,
            author: w.author,
            thumbnail_url: w.thumbnail_url,
            type_: w.type_,
            perfect: w.perfect,
            content: w.content,
            sharp_url: w.sharp_url,
            has_read: w.has_read,
            create_time: w.create_time,
        }
    }
}

#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct NoticeReply {
    /// 通知 ID
    pub id: String,
    /// 文章标题
    pub title: String,
    /// 文章作者
    pub author: String,
    /// 作者头像
    pub thumbnail_url: String,
    /// 文章类型
    pub type_: u32,
    /// 是否精选
    pub perfect: bool,
    /// 回复内容
    pub content: String,
    /// 回复地址
    pub sharp_url: String,
    /// 是否已读
    pub has_read: bool,
    /// 回复时间
    pub create_time: String,
    /// 数据类型
    pub data_type: u32,
}

impl From<WireNoticeReply> for NoticeReply {
    fn from(w: WireNoticeReply) -> Self {
        Self {
            id: w.o_id,
            title: w.title,
            author: w.author,
            thumbnail_url: w.thumbnail_url,
            type_: w.type_,
            perfect: w.perfect,
            content: w.content,
            sharp_url: w.sharp_url,
            has_read: w.has_read,
            create_time: w.create_time,
            data_type: w.data_type,
        }
    }
}

#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct NoticeAt {
    /// 通知 ID
    pub id: String,
    /// 数据类型
    pub data_type: u32,
    /// 用户名
    pub user_name: String,
    /// 文章 @ 的作者用户名
    pub author_name: String,
    /// 文章 @ 的文章标题
    pub article_title: String,
    /// 文章 @ 的文章 ID
    pub article_id: ArticleId,
    /// 文章 @ 的跳转地址
    pub url: String,
    /// 是否是文章内 @
    pub at_in_article: bool,
    /// 用户头像(点赞类消息)
    pub avatar_url: String,
    /// 用户头像(@ 消息/红包)
    pub user_avatar_url: String,
    /// 通知内容
    pub content: String,
    /// 通知描述
    pub description: String,
    /// 是否已读
    pub has_read: bool,
    /// 创建时间
    pub create_time: String,
    /// 数据 ID
    pub data_id: String,
    /// 是否已删除
    pub deleted: bool,
}

impl From<WireNoticeAt> for NoticeAt {
    fn from(w: WireNoticeAt) -> Self {
        Self {
            id: w.o_id,
            data_type: w.data_type,
            user_name: w.user_name,
            author_name: w.author_name,
            article_title: w.article_title,
            article_id: w.article_id.into(),
            url: w.url,
            at_in_article: w.at_in_article,
            avatar_url: w.avatar_url,
            user_avatar_url: w.user_avatar_url,
            content: w.content,
            description: w.description,
            has_read: w.has_read,
            create_time: w.create_time,
            data_id: w.data_id,
            deleted: w.deleted,
        }
    }
}

#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct NoticeTag {
    /// 标签 ID
    pub id: String,
    /// 标签名
    pub title: String,
    /// icon 地址
    pub icon_path: String,
    /// 标签地址
    pub uri: String,
}

impl From<WireNoticeTag> for NoticeTag {
    fn from(w: WireNoticeTag) -> Self {
        Self {
            id: w.o_id,
            title: w.title,
            icon_path: w.icon_path,
            uri: w.uri,
        }
    }
}

#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct NoticeFollow {
    /// 通知 ID
    pub id: String,
    /// 文章地址
    pub url: String,
    /// 数据类型
    pub data_type: u32,
    /// 文章标题
    pub title: String,
    /// 作者
    pub author: String,
    /// 通知内容
    pub content: String,
    /// 是否评论
    pub is_comment: bool,
    /// 作者头像
    pub thumbnail_url: String,
    /// 文章评论数
    pub comment_count: u32,
    /// 是否精选
    pub perfect: bool,
    /// 文章标签列表
    pub tag_objs: Vec<NoticeTag>,
    /// 文章标签
    pub tags: String,
    /// 文章类型
    pub type_: u32,
    /// 是否已读
    pub has_read: bool,
    /// 通知创建时间
    pub create_time: String,
}

impl From<WireNoticeFollow> for NoticeFollow {
    fn from(w: WireNoticeFollow) -> Self {
        Self {
            id: w.o_id,
            url: w.url,
            data_type: w.data_type,
            title: w.title,
            author: w.author,
            content: w.content,
            is_comment: w.is_comment,
            thumbnail_url: w.thumbnail_url,
            comment_count: w.comment_count,
            perfect: w.perfect,
            tag_objs: w.tag_objs.into_iter().map(NoticeTag::from).collect(),
            tags: w.tags,
            type_: w.type_,
            has_read: w.has_read,
            create_time: w.create_time,
        }
    }
}

#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct NoticeSystem {
    /// 通知 ID
    pub id: String,
    /// 用户 ID
    pub user_id: UserId,
    /// 数据 ID
    pub data_id: String,
    /// 数据类型
    pub data_type: u32,
    /// 消息描述
    pub description: String,
    /// 消息内容
    pub content: String,
    /// 是否已读
    pub has_read: bool,
    /// 创建日期
    pub create_time: String,
}

impl From<WireNoticeSystem> for NoticeSystem {
    fn from(w: WireNoticeSystem) -> Self {
        Self {
            id: w.o_id,
            user_id: w.user_id.into(),
            data_id: w.data_id,
            data_type: w.data_type,
            description: w.description,
            content: w.content,
            has_read: w.has_read,
            create_time: w.create_time,
        }
    }
}

#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct NoticeMsg {
    /// 通知类型
    pub command: String,
    /// 通知接收者用户 ID
    pub user_id: UserId,
    /// 全局公告内容,仅 `warnBroadcast` 有信息
    pub content: Option<String>,
    /// 全局公告发布者,仅 `warnBroadcast` 有信息
    pub who: Option<String>,
}

impl From<WireNoticeMsg> for NoticeMsg {
    fn from(w: WireNoticeMsg) -> Self {
        Self {
            command: w.command,
            user_id: w.user_id.into(),
            content: w.content,
            who: w.who,
        }
    }
}

#[derive(Clone, Debug)]
pub enum NoticeItem {
    /// 积分通知
    Point(NoticePoint),
    /// 评论/回帖通知
    Comment(NoticeComment),
    /// 回复通知
    Reply(NoticeReply),
    /// 提到我通知
    At(NoticeAt),
    /// 关注通知
    Follow(NoticeFollow),
    /// 系统通知
    System(NoticeSystem),
}

pub type NoticeList = Vec<NoticeItem>;