diff --git a/src/controllers/notifications_controller.rs b/src/controllers/notifications_controller.rs index ca18ef4..8702725 100644 --- a/src/controllers/notifications_controller.rs +++ b/src/controllers/notifications_controller.rs @@ -8,7 +8,7 @@ use crate::api_data::res_number_unread_notifications::ResNumberUnreadNotificatio use crate::controllers::routes::RequestResult; use crate::data::error::ResultBoxError; use crate::data::http_request_handler::HttpRequestHandler; -use crate::data::notification::{Notification, PartialNotification}; +use crate::data::notification::Notification; use crate::helpers::{conversations_helper, friends_helper, notifications_helper}; impl HttpRequestHandler { @@ -59,17 +59,15 @@ pub fn mark_seen(r: &mut HttpRequestHandler) -> RequestResult { let notif = r.post_notif_id("notifID")?; let delete_similar = r.post_bool_opt("delete_similar", false); + let mut notif = notif.into_partial(); + // Check if we are targeting a precise notification or an undetermined number of similar // notifications - if !delete_similar { - notifications_helper::delete( - &PartialNotification::new() - .set_id(notif.id) - )?; - } else { - // TODO : implement me - unimplemented!(); + if delete_similar { + notif.id = None; } + notifications_helper::delete(¬if)?; + r.success("Notification deleted") } \ No newline at end of file diff --git a/src/data/notification.rs b/src/data/notification.rs index 0e334cd..8463f7a 100644 --- a/src/data/notification.rs +++ b/src/data/notification.rs @@ -153,6 +153,24 @@ pub struct Notification { pub container_type: Option, } +impl Notification { + pub fn into_partial(self) -> PartialNotification { + PartialNotification { + id: Some(self.id), + time_create: Some(self.time_create), + seen: Some(self.seen), + from_user_id: Some(self.from_user_id), + dest_user_id: Some(self.dest_user_id), + on_elem_id: Some(self.on_elem_id), + on_elem_type: Some(self.on_elem_type), + kind: Some(self.kind), + visibility: Some(self.visibility), + container_id: self.container_id, + container_type: self.container_type, + } + } +} + pub struct PartialNotification { pub id: Option, pub time_create: Option,