From f0fdb3b3788682c91fa2d1c2720653c41dff7edc Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Fri, 1 Nov 2019 15:31:44 +0100 Subject: [PATCH] Create new methods in NotificationsList object --- lib/lists/notifications_list.dart | 43 ++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/lib/lists/notifications_list.dart b/lib/lists/notifications_list.dart index f0d4ff1..f0ef100 100644 --- a/lib/lists/notifications_list.dart +++ b/lib/lists/notifications_list.dart @@ -5,4 +5,45 @@ import 'package:comunic/models/notification.dart'; /// /// @author Pierre HUBERT -class NotificationsList extends AbstractList {} +class NotificationsList extends AbstractList { + /// Get the ID of all the users related to the notifications + /// included in the list + List get usersIds { + final list = List(); + + forEach((n) { + if (!list.contains(n.fromUser)) list.add(n.fromUser); + + if (n.onElemType == NotificationElementType.FRIENDSHIP_REQUEST || + n.onElemType == NotificationElementType.USER_PAGE) { + if (!list.contains(n.onElemId)) list.add(n.onElemId); + } + + if (n.fromContainerType == NotificationElementType.FRIENDSHIP_REQUEST || + n.fromContainerType == NotificationElementType.USER_PAGE) { + if (!list.contains(n.fromContainerId)) list.add(n.fromContainerId); + } + }); + + return list; + } + + /// Get the ID of all the groups related to the notifications + /// included in the list + List get groupsIds { + final list = List(); + + forEach((n) { + if (n.onElemType == NotificationElementType.GROUP_PAGE && + !list.contains(n.onElemId)) list.add(n.onElemId); + + if (n.fromContainerType == NotificationElementType.GROUP_PAGE && + !list.contains(n.fromContainerId)) list.add(n.fromContainerId); + + if (n.onElemType == NotificationElementType.GROUP_MEMBERSHIP && + !list.contains(n.onElemId)) list.add(n.onElemId); + }); + + return list; + } +}