mirror of
				https://gitlab.com/comunic/comunicapiv2
				synced 2025-11-04 11:34:04 +00:00 
			
		
		
		
	Can get the list of notifications of the user
This commit is contained in:
		@@ -2,6 +2,7 @@ import { RequestHandler } from "../entities/RequestHandler";
 | 
			
		||||
import { NotificationsHelper } from "../helpers/NotificationsHelper";
 | 
			
		||||
import { ConversationsHelper } from "../helpers/ConversationsHelper";
 | 
			
		||||
import { FriendsHelper } from "../helpers/FriendsHelper";
 | 
			
		||||
import { Notif } from "../entities/Notification";
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Notifications controller
 | 
			
		||||
@@ -40,4 +41,36 @@ export class NotificationsController {
 | 
			
		||||
 | 
			
		||||
		h.send(data);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Get the list of unread notifications
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param h Request handler
 | 
			
		||||
	 */
 | 
			
		||||
	public static async GetListUnread(h: RequestHandler) {
 | 
			
		||||
		const list = await NotificationsHelper.GetListUnread(h.getUserId());
 | 
			
		||||
 | 
			
		||||
		h.send(list.map(this.NotifToAPI));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Transform a notification into an API entry
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param n The notification to transform
 | 
			
		||||
	 */
 | 
			
		||||
	private static NotifToAPI(n: Notif) : Object {
 | 
			
		||||
		return {
 | 
			
		||||
			id: n.id,
 | 
			
		||||
			time_create: n.timeCreate,
 | 
			
		||||
			seen: n.seen,
 | 
			
		||||
			from_user_id: n.fromUserID,
 | 
			
		||||
			dest_user_id: n.destUserID,
 | 
			
		||||
			on_elem_id: n.onElemID,
 | 
			
		||||
			on_elem_type: n.onElemType,
 | 
			
		||||
			type: n.type,
 | 
			
		||||
			event_visibility: n.eventVisibility,
 | 
			
		||||
			from_container_id: n.fromContainerID,
 | 
			
		||||
			from_container_type: n.fromContainerType
 | 
			
		||||
		};
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -138,4 +138,6 @@ export const Routes : Route[] = [
 | 
			
		||||
	{path: "/notifications/count_unread", cb: (h) => NotificationsController.CountUnread(h)},
 | 
			
		||||
 | 
			
		||||
	{path: "/notifications/count_all_news", cb: (h) => NotificationsController.CountAllNews(h)},
 | 
			
		||||
 | 
			
		||||
	{path: "/notifications/get_list_unread", cb: (h) => NotificationsController.GetListUnread(h)},
 | 
			
		||||
]
 | 
			
		||||
		Reference in New Issue
	
	Block a user