Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/services/incoming_bus_reminder_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:convert';

import 'package:bluebus/constants.dart';
import 'package:bluebus/services/notification_service.dart';
import 'package:flutter/material.dart';
import 'package:flutter/semantics.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:http/http.dart' as http;
Expand Down Expand Up @@ -84,6 +85,21 @@ class IncomingBusReminderService {
final token = _serverToken();
if (token == null) throw Exception("missing token");
await _modifyReminders(token: token, modifications: modifications);

// List for checking if every reminder modification has been set
List<bool> added = List.generate(modifications.length, (i) => modifications[i] is RemoveReminder);

for (final reminder in await _activeReminders(token: token)) {
for (int i = 0; i < modifications.length; ++i) {
if (reminder.stpid == modifications[i].encode()["stpid"] && reminder.rtid == modifications[i].encode()["rtid"]) {
if (added[i] is RemoveReminder) throw Exception("backend not updated");
added[i] = modifications[i] is AddReminder;
break;
}
}
}

if (added.contains(false)) throw Exception("backend not updated");
}

static Future<bool> isActiveReminder(String stpid, String rtid) async {
Expand Down
4 changes: 2 additions & 2 deletions lib/widgets/stop_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1094,11 +1094,11 @@ class _ReminderFormState extends State<ReminderForm> {
await IncomingBusReminderService.modifyReminders(modifications);
if (!context.mounted) return;
Navigator.pop(context);
} on Exception catch (e) {
} on Exception {
showDialog(
context: context,
builder: (context) => SimpleDialog(
title: Text("Failed!\n${e.toString()}")),
title: Text("Notification request\n couldn't be sent\n", textAlign: TextAlign.center,)),
);
}
setState(() => _isProcessing = false);
Expand Down