migrated custom timetable events to Marianum-Connect and refactored push notification handling
This commit is contained in:
@@ -13,22 +13,29 @@ import '../../marianumconnect_api.dart';
|
||||
import '../../marianumconnect_endpoint.dart';
|
||||
import 'telemetry_device_id.dart';
|
||||
|
||||
/// Sends a telemetry heartbeat to MarianumConnect (`POST me/telemetry`) — one
|
||||
/// upsert per app start carrying the stable install id, platform, app version
|
||||
/// and device info. Bearer-authenticated via the shared dio interceptor.
|
||||
/// Replaces the legacy mhsl.eu `server/userIndex/update` call.
|
||||
/// Sends a telemetry heartbeat to MarianumConnect (`POST me/telemetry`) —
|
||||
/// upserts the stable install id, platform, app version and device info. Sent
|
||||
/// once on app start and again once push registration completes that session
|
||||
/// (so a fresh registration isn't under-reported until the next launch).
|
||||
/// Bearer-authenticated via the shared dio interceptor. Replaces the legacy
|
||||
/// mhsl.eu `server/userIndex/update` call.
|
||||
class TelemetryHeartbeat {
|
||||
final Dio _dio;
|
||||
|
||||
TelemetryHeartbeat({Dio? dio}) : _dio = dio ?? MarianumConnectApi.dio();
|
||||
|
||||
/// Fire-and-forget: schedules a heartbeat and swallows any error, so a failed
|
||||
/// send never disrupts app start. Used from the app shell's initState.
|
||||
static void report() {
|
||||
unawaited(TelemetryHeartbeat().send().catchError((Object _) {}));
|
||||
/// send never disrupts app start. Used from the app shell's initState and
|
||||
/// re-emitted once push registration completes (see `_MainState._syncPush`).
|
||||
static void report({required bool notificationsEnabled}) {
|
||||
unawaited(
|
||||
TelemetryHeartbeat()
|
||||
.send(notificationsEnabled: notificationsEnabled)
|
||||
.catchError((Object _) {}),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> send() async {
|
||||
Future<void> send({required bool notificationsEnabled}) async {
|
||||
try {
|
||||
final info = DeviceInfoPlugin();
|
||||
final package = await PackageInfo.fromPlatform();
|
||||
@@ -58,7 +65,12 @@ class TelemetryHeartbeat {
|
||||
MarianumConnectEndpoint.resolve('me/telemetry'),
|
||||
data: {
|
||||
'deviceIdentifier': deviceIdentifier,
|
||||
// `pushDeviceIdentifier` reflects a *completed* registration and is
|
||||
// absent until it lands; `pushEnabled` carries the user's intent
|
||||
// (the notification toggle) so the backend can tell "user wants push"
|
||||
// apart from "registration not finished yet".
|
||||
'pushDeviceIdentifier': ?pushDeviceIdentifier,
|
||||
'pushEnabled': notificationsEnabled,
|
||||
'platform': platform,
|
||||
'appVersion': package.version,
|
||||
'appBuild': int.tryParse(package.buildNumber),
|
||||
|
||||
Reference in New Issue
Block a user