Files
tm_app/lib/data/services/notification_check_service.dart

33 lines
1.1 KiB
Dart

import 'package:tm_app/core/utils/result.dart';
import 'package:tm_app/data/repositories/home_repository.dart';
import 'package:tm_app/data/services/notification_state_service.dart';
/// Service to check for unread notifications and update state
class NotificationCheckService {
final HomeRepository _homeRepository;
final NotificationStateService _notificationStateService;
NotificationCheckService({
required HomeRepository homeRepository,
required NotificationStateService notificationStateService,
}) : _homeRepository = homeRepository,
_notificationStateService = notificationStateService;
Future<void> checkUnreadNotifications() async {
final result = await _homeRepository.checkUnreadNotifications();
switch (result) {
case Ok<Map<String, dynamic>>():
final response = result.value;
final data = response['data'];
_notificationStateService.setHasUnreadNotification(
data is List && data.isNotEmpty,
);
break;
case Error<Map<String, dynamic>>():
_notificationStateService.setHasUnreadNotification(false);
break;
}
}
}