1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-12-27 22:18:51 +00:00

Can create friendship notifications

This commit is contained in:
Pierre HUBERT 2021-01-23 15:04:52 +01:00
parent 4d6ff8fef3
commit fd5000aef9
2 changed files with 28 additions and 4 deletions

View File

@ -6,7 +6,8 @@ use crate::api_data::friend_api::FriendAPI;
use crate::api_data::friendship_status_api::FriendshipStatusAPI;
use crate::controllers::routes::RequestResult;
use crate::data::http_request_handler::HttpRequestHandler;
use crate::helpers::{account_helper, friends_helper, user_helper};
use crate::data::notification::NotifEventType;
use crate::helpers::{account_helper, friends_helper, notifications_helper, user_helper};
/// Get the list of friends of the current user
pub fn get_list(r: &mut HttpRequestHandler) -> RequestResult {
@ -82,7 +83,11 @@ pub fn send_request(r: &mut HttpRequestHandler) -> RequestResult {
friends_helper::send_request(&r.user_id()?, &friend_id)?;
// TODO : create a notification
// Create a notification
notifications_helper::create_friends_notification(
r.user_id_ref()?,
&friend_id,
NotifEventType::SENT_FRIEND_REQUEST)?;
r.success("The friendship request was successfully sent!")
}

View File

@ -17,7 +17,6 @@ use crate::utils::date_utils;
/// Create post notification
pub fn create_post_notification(from_user: &UserID, post_id: u64, action: NotifEventType) -> ResultBoxError {
let mut n = PartialNotification::new()
.set_time_create(date_utils::time())
.set_from_user_id(from_user)
.set_on_elem_id(post_id)
.set_on_elem_type(NotifElemType::POST)
@ -26,8 +25,20 @@ pub fn create_post_notification(from_user: &UserID, post_id: u64, action: NotifE
push(&mut n)
}
/// Create & push friend notification
pub fn create_friends_notification(from_user: &UserID, dest_user: &UserID, action: NotifEventType) -> ResultBoxError {
let mut n = PartialNotification::new()
.set_from_user_id(from_user)
.set_dest_user_id(dest_user)
.set_on_elem_id(from_user.id())
.set_on_elem_type(NotifElemType::FRIENDSHIP_REQUEST)
.set_type(action);
push(&mut n)
}
/// Push a new notification
pub fn push(n: &mut PartialNotification) -> ResultBoxError
fn push(n: &mut PartialNotification) -> ResultBoxError
{
if n.time_create.is_none()
{
@ -100,6 +111,14 @@ pub fn push(n: &mut PartialNotification) -> ResultBoxError
else {
unimplemented!();
}
}
// Friendship notification
else if matches!(n.on_elem_type, Some(NotifElemType::FRIENDSHIP_REQUEST)) {
n.container_id = None;
n.container_type = None;
return push_private(n);
} else {
unimplemented!();
}