1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-25 22:39:22 +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;
}
/// 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
Future<GroupsList> getList(Set<int> groups, {bool force = false}) async {
final list = GroupsList();

View File

@ -8,21 +8,19 @@ import 'package:comunic/models/notification.dart';
class NotificationsList extends AbstractList<Notification> {
/// Get the ID of all the users related to the notifications
/// included in the list
List<int> get usersIds {
final list = List<int>();
Set<int> get usersIds {
final list = Set<int>();
forEach((n) {
if (!list.contains(n.fromUser)) list.add(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);
}
n.onElemType == NotificationElementType.USER_PAGE)
list.add(n.onElemId);
if (n.fromContainerType == NotificationElementType.FRIENDSHIP_REQUEST ||
n.fromContainerType == NotificationElementType.USER_PAGE) {
if (!list.contains(n.fromContainerId)) list.add(n.fromContainerId);
}
n.fromContainerType == NotificationElementType.USER_PAGE)
list.add(n.fromContainerId);
});
return list;
@ -30,18 +28,18 @@ class NotificationsList extends AbstractList<Notification> {
/// Get the ID of all the groups related to the notifications
/// included in the list
List<int> get groupsIds {
final list = List<int>();
Set<int> get groupsIds {
final list = Set<int>();
forEach((n) {
if (n.onElemType == NotificationElementType.GROUP_PAGE &&
!list.contains(n.onElemId)) list.add(n.onElemId);
if (n.onElemType == NotificationElementType.GROUP_PAGE)
list.add(n.onElemId);
if (n.fromContainerType == NotificationElementType.GROUP_PAGE &&
!list.contains(n.fromContainerId)) list.add(n.fromContainerId);
if (n.fromContainerType == NotificationElementType.GROUP_PAGE)
list.add(n.fromContainerId);
if (n.onElemType == NotificationElementType.GROUP_MEMBERSHIP &&
!list.contains(n.onElemId)) list.add(n.onElemId);
if (n.onElemType == NotificationElementType.GROUP_MEMBERSHIP)
list.add(n.onElemId);
});
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/users_list.dart';
import 'package:comunic/utils/intl_utils.dart';
import 'package:comunic/utils/ui_utils.dart';
import 'package:flutter/material.dart';
@ -16,6 +21,8 @@ class NotificationsScreen extends StatefulWidget {
class _NotificationsScreenState extends State<NotificationsScreen> {
NotificationsList _list;
UsersList _users;
GroupsList _groups;
_Status _status = _Status.LOADING;
void setStatus(_Status s) => setState(() => _status = s);
@ -23,6 +30,31 @@ class _NotificationsScreenState extends State<NotificationsScreen> {
Future<void> _loadList() async {
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