mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-21 00:45:18 +00:00
Can get the list of unread notifications
This commit is contained in:
@ -39,4 +39,5 @@ pub mod res_create_post;
|
||||
pub mod posts_targets_api;
|
||||
pub mod res_create_comment;
|
||||
pub mod res_number_unread_notifications;
|
||||
pub mod res_count_all_unreads;
|
||||
pub mod res_count_all_unreads;
|
||||
pub mod notification_api;
|
59
src/api_data/notification_api.rs
Normal file
59
src/api_data/notification_api.rs
Normal file
@ -0,0 +1,59 @@
|
||||
//! # API Notification object
|
||||
//!
|
||||
//! @author Pierre Hubert
|
||||
|
||||
use serde::{Serialize, Serializer};
|
||||
use serde::ser::SerializeMap;
|
||||
|
||||
use crate::data::notification::Notification;
|
||||
|
||||
struct TypeContainer {
|
||||
t: String,
|
||||
}
|
||||
|
||||
impl Serialize for TypeContainer {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
|
||||
S: Serializer {
|
||||
let mut map = serializer.serialize_map(Some(1))?;
|
||||
map.serialize_entry("type", &self.t)?;
|
||||
map.end()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct NotificationAPI {
|
||||
id: u64,
|
||||
time_create: u64,
|
||||
seen: bool,
|
||||
from_user_id: u64,
|
||||
dest_user_id: u64,
|
||||
on_elem_id: u64,
|
||||
on_elem_type: String,
|
||||
#[serde(flatten)]
|
||||
type_container: TypeContainer,
|
||||
event_visibility: String,
|
||||
from_container_id: Option<u64>,
|
||||
from_container_type: Option<String>,
|
||||
}
|
||||
|
||||
impl NotificationAPI {
|
||||
pub fn new(n: &Notification) -> NotificationAPI {
|
||||
NotificationAPI {
|
||||
id: n.id,
|
||||
time_create: n.time_create,
|
||||
seen: n.seen,
|
||||
from_user_id: n.from_user_id.id(),
|
||||
dest_user_id: n.dest_user_id.id(),
|
||||
on_elem_id: n.on_elem_id,
|
||||
on_elem_type: n.on_elem_type.to_api(),
|
||||
type_container: TypeContainer { t: n.kind.to_api() },
|
||||
event_visibility: n.visibility.to_api(),
|
||||
from_container_id: n.container_id,
|
||||
from_container_type: n.container_type.as_ref().map(|f| f.to_api()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn for_list(l: &Vec<Notification>) -> Vec<NotificationAPI> {
|
||||
l.iter().map(Self::new).collect()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user