1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 12:59:21 +00:00

Get information about users & groups related to the notifications

This commit is contained in:
Pierre HUBERT 2019-11-01 15:37:27 +01:00
parent f0fdb3b378
commit 0b204afff9
3 changed files with 58 additions and 17 deletions

View File

@ -54,6 +54,17 @@ class GroupsHelper {
return list; return list;
} }
/// Get a list of groups from the server. In case of error, this method throws
/// an exception
Future<GroupsList> getListOrThrow(Set<int> groups,
{bool force = false}) async {
final list = await getList(groups, force: force);
if (list == null) throw Exception("Could not get the list of groups!");
return list;
}
/// Get a list of groups from the server /// Get a list of groups from the server
Future<GroupsList> getList(Set<int> groups, {bool force = false}) async { Future<GroupsList> getList(Set<int> groups, {bool force = false}) async {
final list = GroupsList(); final list = GroupsList();

View File

@ -8,21 +8,19 @@ import 'package:comunic/models/notification.dart';
class NotificationsList extends AbstractList<Notification> { class NotificationsList extends AbstractList<Notification> {
/// Get the ID of all the users related to the notifications /// Get the ID of all the users related to the notifications
/// included in the list /// included in the list
List<int> get usersIds { Set<int> get usersIds {
final list = List<int>(); final list = Set<int>();
forEach((n) { forEach((n) {
if (!list.contains(n.fromUser)) list.add(n.fromUser); list.add(n.fromUser);
if (n.onElemType == NotificationElementType.FRIENDSHIP_REQUEST || if (n.onElemType == NotificationElementType.FRIENDSHIP_REQUEST ||
n.onElemType == NotificationElementType.USER_PAGE) { n.onElemType == NotificationElementType.USER_PAGE)
if (!list.contains(n.onElemId)) list.add(n.onElemId); list.add(n.onElemId);
}
if (n.fromContainerType == NotificationElementType.FRIENDSHIP_REQUEST || if (n.fromContainerType == NotificationElementType.FRIENDSHIP_REQUEST ||
n.fromContainerType == NotificationElementType.USER_PAGE) { n.fromContainerType == NotificationElementType.USER_PAGE)
if (!list.contains(n.fromContainerId)) list.add(n.fromContainerId); list.add(n.fromContainerId);
}
}); });
return list; return list;
@ -30,18 +28,18 @@ class NotificationsList extends AbstractList<Notification> {
/// Get the ID of all the groups related to the notifications /// Get the ID of all the groups related to the notifications
/// included in the list /// included in the list
List<int> get groupsIds { Set<int> get groupsIds {
final list = List<int>(); final list = Set<int>();
forEach((n) { forEach((n) {
if (n.onElemType == NotificationElementType.GROUP_PAGE && if (n.onElemType == NotificationElementType.GROUP_PAGE)
!list.contains(n.onElemId)) list.add(n.onElemId); list.add(n.onElemId);
if (n.fromContainerType == NotificationElementType.GROUP_PAGE && if (n.fromContainerType == NotificationElementType.GROUP_PAGE)
!list.contains(n.fromContainerId)) list.add(n.fromContainerId); list.add(n.fromContainerId);
if (n.onElemType == NotificationElementType.GROUP_MEMBERSHIP && if (n.onElemType == NotificationElementType.GROUP_MEMBERSHIP)
!list.contains(n.onElemId)) list.add(n.onElemId); list.add(n.onElemId);
}); });
return list; return list;

View File

@ -1,4 +1,9 @@
import 'package:comunic/helpers/groups_helper.dart';
import 'package:comunic/helpers/notifications_helper.dart';
import 'package:comunic/helpers/users_helper.dart';
import 'package:comunic/lists/groups_list.dart';
import 'package:comunic/lists/notifications_list.dart'; import 'package:comunic/lists/notifications_list.dart';
import 'package:comunic/lists/users_list.dart';
import 'package:comunic/utils/intl_utils.dart'; import 'package:comunic/utils/intl_utils.dart';
import 'package:comunic/utils/ui_utils.dart'; import 'package:comunic/utils/ui_utils.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -16,6 +21,8 @@ class NotificationsScreen extends StatefulWidget {
class _NotificationsScreenState extends State<NotificationsScreen> { class _NotificationsScreenState extends State<NotificationsScreen> {
NotificationsList _list; NotificationsList _list;
UsersList _users;
GroupsList _groups;
_Status _status = _Status.LOADING; _Status _status = _Status.LOADING;
void setStatus(_Status s) => setState(() => _status = s); void setStatus(_Status s) => setState(() => _status = s);
@ -23,6 +30,31 @@ class _NotificationsScreenState extends State<NotificationsScreen> {
Future<void> _loadList() async { Future<void> _loadList() async {
setStatus(_Status.LOADING); setStatus(_Status.LOADING);
try {
final list = await NotificationsHelper().getUnread();
final users = await UsersHelper().getListWithThrow(list.usersIds);
final groups = await GroupsHelper().getListOrThrow(list.groupsIds);
setState(() {
_list = list;
_users = users;
_groups = groups;
});
} on Exception catch (e) {
print("Exception while getting the list of notifications!");
print(e);
} on Error catch (e) {
print("Error while getting the list of notifications!");
print(e.stackTrace);
}
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
_loadList();
} }
@override @override