mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-22 21:39:21 +00:00
Can create friendship notifications
This commit is contained in:
parent
4d6ff8fef3
commit
fd5000aef9
@ -6,7 +6,8 @@ use crate::api_data::friend_api::FriendAPI;
|
|||||||
use crate::api_data::friendship_status_api::FriendshipStatusAPI;
|
use crate::api_data::friendship_status_api::FriendshipStatusAPI;
|
||||||
use crate::controllers::routes::RequestResult;
|
use crate::controllers::routes::RequestResult;
|
||||||
use crate::data::http_request_handler::HttpRequestHandler;
|
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
|
/// Get the list of friends of the current user
|
||||||
pub fn get_list(r: &mut HttpRequestHandler) -> RequestResult {
|
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)?;
|
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!")
|
r.success("The friendship request was successfully sent!")
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@ use crate::utils::date_utils;
|
|||||||
/// Create post notification
|
/// Create post notification
|
||||||
pub fn create_post_notification(from_user: &UserID, post_id: u64, action: NotifEventType) -> ResultBoxError {
|
pub fn create_post_notification(from_user: &UserID, post_id: u64, action: NotifEventType) -> ResultBoxError {
|
||||||
let mut n = PartialNotification::new()
|
let mut n = PartialNotification::new()
|
||||||
.set_time_create(date_utils::time())
|
|
||||||
.set_from_user_id(from_user)
|
.set_from_user_id(from_user)
|
||||||
.set_on_elem_id(post_id)
|
.set_on_elem_id(post_id)
|
||||||
.set_on_elem_type(NotifElemType::POST)
|
.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)
|
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
|
/// Push a new notification
|
||||||
pub fn push(n: &mut PartialNotification) -> ResultBoxError
|
fn push(n: &mut PartialNotification) -> ResultBoxError
|
||||||
{
|
{
|
||||||
if n.time_create.is_none()
|
if n.time_create.is_none()
|
||||||
{
|
{
|
||||||
@ -100,6 +111,14 @@ pub fn push(n: &mut PartialNotification) -> ResultBoxError
|
|||||||
else {
|
else {
|
||||||
unimplemented!();
|
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 {
|
} else {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user