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 {
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 {
pub id: String,
pub data_id: String,
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 {
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 {
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 {
pub id: String,
pub data_type: u32,
pub user_name: String,
pub author_name: String,
pub article_title: String,
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,
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 {
pub id: String,
pub title: String,
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 {
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 {
pub id: String,
pub user_id: UserId,
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,
pub user_id: UserId,
pub content: Option<String>,
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>;