mirror of
				https://github.com/pierre42100/ComunicAPI
				synced 2025-11-03 19:54:14 +00:00 
			
		
		
		
	Sent notifications for friendship requests
This commit is contained in:
		@@ -44,15 +44,42 @@ function delete_notifications_friendship_request(int $userOne, int $userTwo) : b
 | 
			
		||||
	//Delete notifications in the two ways
 | 
			
		||||
	$notification->set_dest_user_id($userOne);
 | 
			
		||||
	$notification->set_from_user_id($userTwo);
 | 
			
		||||
	$notification->set_on_elem_id(0);
 | 
			
		||||
	$notification->set_on_elem_id($userTwo);
 | 
			
		||||
	if(!components()->notifications->delete($notification))
 | 
			
		||||
		return false;
 | 
			
		||||
	
 | 
			
		||||
	$notification->set_dest_user_id($userTwo);
 | 
			
		||||
	$notification->set_from_user_id($userOne);
 | 
			
		||||
	$notification->set_on_elem_id(0);
 | 
			
		||||
	$notification->set_on_elem_id($userOne);
 | 
			
		||||
	if(!components()->notifications->delete($notification))
 | 
			
		||||
		return false;
 | 
			
		||||
 | 
			
		||||
	return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Create and push a friendship request notification
 | 
			
		||||
 * 
 | 
			
		||||
 * @param int $fromUser The ID of the user generating the notification
 | 
			
		||||
 * @param int $destUser The target user for the notification
 | 
			
		||||
 * @param string $kind The kind of notification to create
 | 
			
		||||
 * @return bool TRUE in case of success / FALSE else
 | 
			
		||||
 */
 | 
			
		||||
function create_friendship_notification(int $fromUser, int $destUser, string $kind) : bool {
 | 
			
		||||
 | 
			
		||||
	//Delete all the previous notifications
 | 
			
		||||
	if(!delete_notifications_friendship_request($fromUser, $destUser))
 | 
			
		||||
		return false;
 | 
			
		||||
	
 | 
			
		||||
	//Create the notification
 | 
			
		||||
	$notif = new Notification();
 | 
			
		||||
	$notif->set_time_create(time());
 | 
			
		||||
	$notif->set_from_user_id($fromUser);
 | 
			
		||||
	$notif->set_dest_user_id($destUser);
 | 
			
		||||
	$notif->set_on_elem_id($fromUser); //Same as from_user_id
 | 
			
		||||
	$notif->set_on_elem_type(Notification::FRIENDSHIP_REQUEST);
 | 
			
		||||
	$notif->set_type($kind);
 | 
			
		||||
 | 
			
		||||
	//Try to push the notification
 | 
			
		||||
	return components()->notifications->push($notif);
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user