ComunicWeb/assets/js/components/notifications/utils.js

57 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

/**
* Notifications utilities
*
* @author Pierre HUBERT
*/
ComunicWeb.components.notifications.utils = {
/**
* Get the users ID that might be required to display the notifications
*
* @param {array} list The list of notifications to process
* @return {array} The list of users id
*/
get_users_id: function(list){
var users = [];
2018-04-24 18:19:00 +00:00
for (var index = 0; index < list.length; index++) {
const notif = list[index];
if(!users.includes(notif.from_user_id))
users.push(notif.from_user_id);
if(!users.includes(notif.from_container_id) && notif.from_container_type == "user_page")
users.push(notif.from_container_id);
}
return users;
},
/**
* Get the ID of the groups related to the notifications
*
* @param {Array} list The list to process
* @return {Array} The list of target groups IDs
*/
get_groups_id: function(list){
var groups = [];
list.forEach(function(notif){
if(!groups.includes(notif.from_container_id) && notif.from_container_type == "group_page")
groups.push(notif.from_container_id);
2018-08-02 07:23:38 +00:00
if(!groups.includes(notif.on_elem_id) && notif.on_elem_type == "group_membership")
groups.push(notif.on_elem_id);
});
return groups;
},
}