From 4d9392dd1f499a2a40eea9bf9c410291ea3f33a8 Mon Sep 17 00:00:00 2001 From: Pierre Date: Mon, 19 Feb 2018 15:14:34 +0100 Subject: [PATCH] Can extract users ID from a notification. --- assets/js/components/notifications/utils.js | 33 +++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 assets/js/components/notifications/utils.js diff --git a/assets/js/components/notifications/utils.js b/assets/js/components/notifications/utils.js new file mode 100644 index 00000000..6c2d3eb1 --- /dev/null +++ b/assets/js/components/notifications/utils.js @@ -0,0 +1,33 @@ +/** + * 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 = []; + + for (let 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; + + } + +} \ No newline at end of file