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

Can delete all the notifications

This commit is contained in:
Pierre HUBERT 2020-04-17 13:50:47 +02:00
parent 8b6e464644
commit 2c1ae783e3
2 changed files with 39 additions and 1 deletions

View File

@ -102,4 +102,10 @@ class NotificationsHelper {
}, },
).exec()) ).exec())
.isOK; .isOK;
/// Delete all unread notifications
Future<bool> deleteAllNotifications() async =>
(await APIRequest(uri: "notifications/delete_all", needLogin: true)
.exec())
.isOK;
} }

View File

@ -32,6 +32,8 @@ class _NotificationsScreenState extends State<NotificationsScreen> {
GroupsList _groups; GroupsList _groups;
_Status _status = _Status.LOADING; _Status _status = _Status.LOADING;
final _refreshKey = GlobalKey<RefreshIndicatorState>();
void setStatus(_Status s) => setState(() => _status = s); void setStatus(_Status s) => setState(() => _status = s);
Future<void> _loadList() async { Future<void> _loadList() async {
@ -77,7 +79,22 @@ class _NotificationsScreenState extends State<NotificationsScreen> {
return Column( return Column(
children: [ children: [
Expanded( Expanded(
child: RefreshIndicator(child: _buildBody(), onRefresh: _loadList), child: Stack(children: [
RefreshIndicator(
key: _refreshKey,
child: _buildBody(),
onRefresh: _loadList,
),
// Add conversation button
Positioned(
right: 20.0,
bottom: 20.0,
child: FloatingActionButton(
onPressed: () => _deleteAllNotifications(),
child: Icon(Icons.delete),
),
),
]),
) )
], ],
); );
@ -134,6 +151,21 @@ class _NotificationsScreenState extends State<NotificationsScreen> {
NotificationsHelper().markSeen(notif); NotificationsHelper().markSeen(notif);
} }
/// Delete all the notifications
void _deleteAllNotifications() async {
if (!await showConfirmDialog(
context: context,
message: tr("Do you really want to delete all your notifications?")))
return;
if (!await NotificationsHelper().deleteAllNotifications()) {
showSimpleSnack(context, tr("Could not delete all your notifications!"));
return;
}
_refreshKey.currentState.show();
}
} }
class _NotificationTile extends StatelessWidget { class _NotificationTile extends StatelessWidget {