2026-06-02 10:24:37 -04:00
|
|
|
part of '../oott_api.dart';
|
|
|
|
|
|
|
|
|
|
/// Notification endpoints: listing and read/new state transitions.
|
|
|
|
|
extension NotificationApi on BackendAPI {
|
|
|
|
|
Future<void> markNotificationAsRead(int id) async {
|
|
|
|
|
await _dio.get('/notifications/$id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> markNotificationAsNew(int id) async {
|
|
|
|
|
await _dio.post('/notifications/$id/mark_as_new');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> markAllNotificationsAsRead() async {
|
|
|
|
|
await _dio.post('/notifications/mark_all_as_old');
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-09 12:42:20 -04:00
|
|
|
/// Asks the backend to deliver a one-off test push to every registered device,
|
2026-06-09 14:06:56 -04:00
|
|
|
/// used from Settings to verify end-to-end push delivery. Returns the number of
|
|
|
|
|
/// devices the relay confirmed delivery to (0 when none are registered).
|
|
|
|
|
Future<int> sendTestNotification() async {
|
|
|
|
|
final response = await _dio.post('/notifications/test');
|
|
|
|
|
return (response.data as Map<String, dynamic>)['delivered'] as int;
|
2026-06-09 12:42:20 -04:00
|
|
|
}
|
|
|
|
|
|
2026-06-05 21:09:25 -04:00
|
|
|
Future<({List<Notification> items, int totalCount})> listNotifications(
|
2026-06-02 10:24:37 -04:00
|
|
|
bool? isNew, {
|
|
|
|
|
int page = 0,
|
|
|
|
|
int perPage = 5,
|
|
|
|
|
CancelToken? cancelToken,
|
|
|
|
|
}) async {
|
|
|
|
|
final response = await _dio.get(
|
|
|
|
|
'/notifications',
|
|
|
|
|
queryParameters: {
|
|
|
|
|
'is_new': isNew ?? '',
|
|
|
|
|
'page_offset': page * perPage,
|
2026-06-05 21:09:25 -04:00
|
|
|
'page_limit': perPage,
|
2026-06-02 10:24:37 -04:00
|
|
|
},
|
|
|
|
|
cancelToken: cancelToken,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return _paginate(
|
2026-06-05 21:09:25 -04:00
|
|
|
response.data as Map<String, dynamic>,
|
2026-06-02 10:24:37 -04:00
|
|
|
(item) => Notification.fromJson(item),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|