mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 12:59:21 +00:00
Automatically refresh the list of notifications when required
This commit is contained in:
parent
1b13a90615
commit
0700014b3a
@ -1,3 +1,4 @@
|
|||||||
|
import 'package:comunic/helpers/events_helper.dart';
|
||||||
import 'package:comunic/helpers/groups_helper.dart';
|
import 'package:comunic/helpers/groups_helper.dart';
|
||||||
import 'package:comunic/helpers/notifications_helper.dart';
|
import 'package:comunic/helpers/notifications_helper.dart';
|
||||||
import 'package:comunic/helpers/users_helper.dart';
|
import 'package:comunic/helpers/users_helper.dart';
|
||||||
@ -7,6 +8,7 @@ import 'package:comunic/lists/users_list.dart';
|
|||||||
import 'package:comunic/models/notification.dart' as n;
|
import 'package:comunic/models/notification.dart' as n;
|
||||||
import 'package:comunic/ui/routes/main_route.dart';
|
import 'package:comunic/ui/routes/main_route.dart';
|
||||||
import 'package:comunic/ui/widgets/account_image_widget.dart';
|
import 'package:comunic/ui/widgets/account_image_widget.dart';
|
||||||
|
import 'package:comunic/ui/widgets/safe_state.dart';
|
||||||
import 'package:comunic/utils/date_utils.dart';
|
import 'package:comunic/utils/date_utils.dart';
|
||||||
import 'package:comunic/utils/intl_utils.dart';
|
import 'package:comunic/utils/intl_utils.dart';
|
||||||
import 'package:comunic/utils/navigation_utils.dart';
|
import 'package:comunic/utils/navigation_utils.dart';
|
||||||
@ -26,7 +28,7 @@ class NotificationsScreen extends StatefulWidget {
|
|||||||
_NotificationsScreenState createState() => _NotificationsScreenState();
|
_NotificationsScreenState createState() => _NotificationsScreenState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _NotificationsScreenState extends State<NotificationsScreen> {
|
class _NotificationsScreenState extends SafeState<NotificationsScreen> {
|
||||||
NotificationsList _list;
|
NotificationsList _list;
|
||||||
UsersList _users;
|
UsersList _users;
|
||||||
GroupsList _groups;
|
GroupsList _groups;
|
||||||
@ -62,6 +64,14 @@ class _NotificationsScreenState extends State<NotificationsScreen> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
this.listenChangeState<NewNumberNotifsEvent>(
|
||||||
|
(d) => _refreshKey.currentState.show());
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didChangeDependencies() {
|
void didChangeDependencies() {
|
||||||
super.didChangeDependencies();
|
super.didChangeDependencies();
|
||||||
@ -111,11 +121,11 @@ class _NotificationsScreenState extends State<NotificationsScreen> {
|
|||||||
return ListView(
|
return ListView(
|
||||||
children: _list
|
children: _list
|
||||||
.map((f) => _NotificationTile(
|
.map((f) => _NotificationTile(
|
||||||
notification: f,
|
notification: f,
|
||||||
usersList: _users,
|
usersList: _users,
|
||||||
groupsList: _groups,
|
groupsList: _groups,
|
||||||
onDelete: _deleteNotification,
|
onDelete: _deleteNotification,
|
||||||
))
|
))
|
||||||
.toList(),
|
.toList(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -193,12 +203,12 @@ class _NotificationTile extends StatelessWidget {
|
|||||||
String message = "${srcUser.fullName} ";
|
String message = "${srcUser.fullName} ";
|
||||||
|
|
||||||
switch (notification.type) {
|
switch (notification.type) {
|
||||||
// Comment
|
// Comment
|
||||||
case n.NotificationType.COMMENT_CREATED:
|
case n.NotificationType.COMMENT_CREATED:
|
||||||
message += tr("posted a comment");
|
message += tr("posted a comment");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Friendship requests
|
// Friendship requests
|
||||||
case n.NotificationType.SENT_FRIEND_REQUEST:
|
case n.NotificationType.SENT_FRIEND_REQUEST:
|
||||||
message += tr("sent you a friendship request.");
|
message += tr("sent you a friendship request.");
|
||||||
break;
|
break;
|
||||||
@ -211,7 +221,7 @@ class _NotificationTile extends StatelessWidget {
|
|||||||
message += tr("rejected your friendship request.");
|
message += tr("rejected your friendship request.");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Groups membership
|
// Groups membership
|
||||||
case n.NotificationType.SENT_GROUP_MEMBERSHIP_INVITATION:
|
case n.NotificationType.SENT_GROUP_MEMBERSHIP_INVITATION:
|
||||||
message += tr("invited you to join the group");
|
message += tr("invited you to join the group");
|
||||||
break;
|
break;
|
||||||
@ -236,14 +246,14 @@ class _NotificationTile extends StatelessWidget {
|
|||||||
message += tr("rejected your request to join the group");
|
message += tr("rejected your request to join the group");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Generic element creation
|
// Generic element creation
|
||||||
case n.NotificationType.ELEM_CREATED:
|
case n.NotificationType.ELEM_CREATED:
|
||||||
if (notification.onElemType == n.NotificationElementType.POST)
|
if (notification.onElemType == n.NotificationElementType.POST)
|
||||||
message += tr("created a new post");
|
message += tr("created a new post");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case n.NotificationType.ELEM_UPDATED:
|
case n.NotificationType.ELEM_UPDATED:
|
||||||
// Operation not implemented
|
// Operation not implemented
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user