forked from firka/student-legacy
add logic to avoid notification spam
This commit is contained in:
parent
b73cc62c16
commit
0f97dddcd8
@ -1,4 +1,8 @@
|
|||||||
|
import 'package:refilc/api/providers/database_provider.dart';
|
||||||
|
import 'package:refilc/api/providers/user_provider.dart';
|
||||||
|
import 'package:refilc/helpers/notification_helper.dart';
|
||||||
import 'package:refilc/models/settings.dart';
|
import 'package:refilc/models/settings.dart';
|
||||||
|
import 'package:refilc/models/user.dart';
|
||||||
import 'package:refilc/theme/colors/colors.dart';
|
import 'package:refilc/theme/colors/colors.dart';
|
||||||
import 'package:refilc_mobile_ui/common/beta_chip.dart';
|
import 'package:refilc_mobile_ui/common/beta_chip.dart';
|
||||||
import 'package:refilc_mobile_ui/common/panel/panel.dart';
|
import 'package:refilc_mobile_ui/common/panel/panel.dart';
|
||||||
@ -53,6 +57,17 @@ class MenuNotifications extends StatelessWidget {
|
|||||||
class NotificationsScreen extends StatelessWidget {
|
class NotificationsScreen extends StatelessWidget {
|
||||||
const NotificationsScreen({super.key});
|
const NotificationsScreen({super.key});
|
||||||
|
|
||||||
|
void setAllAsSeen(BuildContext context) {
|
||||||
|
// Set all notification categories as seen to avoid spamming the user with notifications when they turn on notifications
|
||||||
|
DatabaseProvider database = Provider.of<DatabaseProvider>(context);
|
||||||
|
User? user = Provider.of<UserProvider>(context).user;
|
||||||
|
if(user != null) {
|
||||||
|
for(LastSeenCategory category in LastSeenCategory.values) {
|
||||||
|
database.userStore.storeLastSeen(DateTime.now(), userId: user.id, category: category);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
SettingsProvider settings = Provider.of<SettingsProvider>(context);
|
SettingsProvider settings = Provider.of<SettingsProvider>(context);
|
||||||
@ -78,8 +93,10 @@ class NotificationsScreen extends StatelessWidget {
|
|||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(12.0)),
|
borderRadius: BorderRadius.circular(12.0)),
|
||||||
value: settings.notificationsGradesEnabled,
|
value: settings.notificationsGradesEnabled,
|
||||||
onChanged: (v) =>
|
onChanged: (v) {
|
||||||
settings.update(notificationsGradesEnabled: v),
|
settings.update(notificationsGradesEnabled: v);
|
||||||
|
setAllAsSeen(context);
|
||||||
|
},
|
||||||
title: Row(
|
title: Row(
|
||||||
children: [
|
children: [
|
||||||
Icon(
|
Icon(
|
||||||
@ -113,8 +130,10 @@ class NotificationsScreen extends StatelessWidget {
|
|||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(12.0)),
|
borderRadius: BorderRadius.circular(12.0)),
|
||||||
value: settings.notificationsAbsencesEnabled,
|
value: settings.notificationsAbsencesEnabled,
|
||||||
onChanged: (v) =>
|
onChanged: (v) {
|
||||||
settings.update(notificationsAbsencesEnabled: v),
|
settings.update(notificationsAbsencesEnabled: v);
|
||||||
|
setAllAsSeen(context);
|
||||||
|
},
|
||||||
title: Row(
|
title: Row(
|
||||||
children: [
|
children: [
|
||||||
Icon(
|
Icon(
|
||||||
@ -148,8 +167,10 @@ class NotificationsScreen extends StatelessWidget {
|
|||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(12.0)),
|
borderRadius: BorderRadius.circular(12.0)),
|
||||||
value: settings.notificationsMessagesEnabled,
|
value: settings.notificationsMessagesEnabled,
|
||||||
onChanged: (v) =>
|
onChanged: (v) {
|
||||||
settings.update(notificationsMessagesEnabled: v),
|
settings.update(notificationsMessagesEnabled: v);
|
||||||
|
setAllAsSeen(context);
|
||||||
|
},
|
||||||
title: Row(
|
title: Row(
|
||||||
children: [
|
children: [
|
||||||
Icon(
|
Icon(
|
||||||
@ -183,8 +204,10 @@ class NotificationsScreen extends StatelessWidget {
|
|||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(12.0)),
|
borderRadius: BorderRadius.circular(12.0)),
|
||||||
value: settings.notificationsLessonsEnabled,
|
value: settings.notificationsLessonsEnabled,
|
||||||
onChanged: (v) =>
|
onChanged: (v) {
|
||||||
settings.update(notificationsLessonsEnabled: v),
|
settings.update(notificationsLessonsEnabled: v);
|
||||||
|
setAllAsSeen(context);
|
||||||
|
},
|
||||||
title: Row(
|
title: Row(
|
||||||
children: [
|
children: [
|
||||||
Icon(
|
Icon(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user