mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 12:59:21 +00:00
Can delete notifications from notifications screen
This commit is contained in:
parent
559516efbd
commit
5250eb59b4
@ -75,4 +75,14 @@ class NotificationsHelper {
|
|||||||
f["from_container_type"]]))
|
f["from_container_type"]]))
|
||||||
.toList());
|
.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;
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,8 @@ import 'package:flutter/material.dart';
|
|||||||
|
|
||||||
enum _Status { LOADING, ERROR, NONE }
|
enum _Status { LOADING, ERROR, NONE }
|
||||||
|
|
||||||
|
enum _PopupMenuActions { DELETE }
|
||||||
|
|
||||||
class NotificationsScreen extends StatefulWidget {
|
class NotificationsScreen extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
_NotificationsScreenState createState() => _NotificationsScreenState();
|
_NotificationsScreenState createState() => _NotificationsScreenState();
|
||||||
@ -93,6 +95,7 @@ class _NotificationsScreenState extends State<NotificationsScreen> {
|
|||||||
notification: f,
|
notification: f,
|
||||||
usersList: _users,
|
usersList: _users,
|
||||||
groupsList: _groups,
|
groupsList: _groups,
|
||||||
|
onDelete: _deleteNotification,
|
||||||
))
|
))
|
||||||
.toList(),
|
.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 {
|
class _NotificationTile extends StatelessWidget {
|
||||||
final n.Notification notification;
|
final n.Notification notification;
|
||||||
final UsersList usersList;
|
final UsersList usersList;
|
||||||
final GroupsList groupsList;
|
final GroupsList groupsList;
|
||||||
|
final void Function(n.Notification) onDelete;
|
||||||
|
|
||||||
const _NotificationTile({
|
const _NotificationTile({
|
||||||
Key key,
|
Key key,
|
||||||
@required this.notification,
|
@required this.notification,
|
||||||
@required this.usersList,
|
@required this.usersList,
|
||||||
@required this.groupsList,
|
@required this.groupsList,
|
||||||
|
@required this.onDelete,
|
||||||
}) : assert(notification != null),
|
}) : assert(notification != null),
|
||||||
|
assert(usersList != null),
|
||||||
|
assert(groupsList != null),
|
||||||
|
assert(onDelete != null),
|
||||||
super(key: key);
|
super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -227,6 +244,23 @@ class _NotificationTile extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
title: Text(message),
|
title: Text(message),
|
||||||
subtitle: Text(diffTimeFromNowToStr(notification.timeCreate)),
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user