1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-10-23 06:53:23 +00:00

Can delete notifications from notifications screen

This commit is contained in:
Pierre HUBERT 2019-11-02 12:14:17 +01:00
parent 559516efbd
commit 5250eb59b4
2 changed files with 44 additions and 0 deletions

View File

@ -75,4 +75,14 @@ class NotificationsHelper {
f["from_container_type"]]))
.toList());
}
/// Mark a notification as seen
Future<bool> markSeen(Notification n) async => (await APIRequest(
uri: "notifications/mark_seen",
needLogin: true,
args: {
"notifID": n.id.toString(),
},
).exec())
.isOK;
}

View File

@ -17,6 +17,8 @@ import 'package:flutter/material.dart';
enum _Status { LOADING, ERROR, NONE }
enum _PopupMenuActions { DELETE }
class NotificationsScreen extends StatefulWidget {
@override
_NotificationsScreenState createState() => _NotificationsScreenState();
@ -93,6 +95,7 @@ class _NotificationsScreenState extends State<NotificationsScreen> {
notification: f,
usersList: _users,
groupsList: _groups,
onDelete: _deleteNotification,
))
.toList(),
);
@ -118,19 +121,33 @@ class _NotificationsScreenState extends State<NotificationsScreen> {
),
);
}
/// Delete a notification
void _deleteNotification(n.Notification notif) async {
setState(() {
_list.remove(notif);
});
NotificationsHelper().markSeen(notif);
}
}
class _NotificationTile extends StatelessWidget {
final n.Notification notification;
final UsersList usersList;
final GroupsList groupsList;
final void Function(n.Notification) onDelete;
const _NotificationTile({
Key key,
@required this.notification,
@required this.usersList,
@required this.groupsList,
@required this.onDelete,
}) : assert(notification != null),
assert(usersList != null),
assert(groupsList != null),
assert(onDelete != null),
super(key: key);
@override
@ -227,6 +244,23 @@ class _NotificationTile extends StatelessWidget {
),
title: Text(message),
subtitle: Text(diffTimeFromNowToStr(notification.timeCreate)),
trailing: PopupMenuButton<_PopupMenuActions>(
onSelected: _popupMenuAction,
itemBuilder: (c) => [
PopupMenuItem(
child: Text(tr("Delete")),
value: _PopupMenuActions.DELETE,
),
],
),
);
}
void _popupMenuAction(_PopupMenuActions value) {
switch (value) {
case _PopupMenuActions.DELETE:
onDelete(notification);
break;
}
}
}