Fix notifications?
This commit is contained in:
parent
4ec79e09e0
commit
5fde56b5c9
|
@ -147,8 +147,10 @@ class APIRequestBuilder {
|
|||
throw Exception('API Key or API URL not set');
|
||||
}
|
||||
|
||||
final response =
|
||||
await _httpClient.post(generateUrl(), body: {'api_key': api.apiKey});
|
||||
var url = generateUrl();
|
||||
print('Fetching $url');
|
||||
|
||||
final response = await _httpClient.post(url, body: {'api_key': api.apiKey});
|
||||
final data = jsonDecode((response).body);
|
||||
if (data['auth'] == 0) throw UnauthenticatedException(data['auth']);
|
||||
return data;
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:feet/api/api.dart';
|
||||
|
@ -38,16 +37,26 @@ void callbackDispatcher() {
|
|||
return true;
|
||||
}
|
||||
|
||||
if (latest == null || latest == 0) {
|
||||
print("newestKnownPost is not set; cancelling task");
|
||||
return true;
|
||||
}
|
||||
|
||||
var api = FeverAPI(
|
||||
apiKey: apiKey,
|
||||
apiUrl: apiUrl,
|
||||
sharedPrefs: sharedPreferences,
|
||||
);
|
||||
|
||||
await api.request().withItems().sinceId(latest ?? 0).execute();
|
||||
var response =
|
||||
await api.request().withItems().sinceId(latest).execute();
|
||||
var items =
|
||||
api.cache.items.getAll().values.where((post) => !post.isRead);
|
||||
|
||||
print("Found ${items.length} new unread posts (out of "
|
||||
"${api.cache.items.size} total)");
|
||||
print(response);
|
||||
|
||||
// Only fetch feeds and favicons if necessary to avoid wasting bandwidth
|
||||
if (items.isNotEmpty) {
|
||||
print("New posts found, fetching feeds and favicons");
|
||||
|
@ -100,7 +109,7 @@ void callbackDispatcher() {
|
|||
|
||||
void setupBackgroundTasks() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
Workmanager().initialize(
|
||||
await Workmanager().initialize(
|
||||
callbackDispatcher,
|
||||
isInDebugMode: kDebugMode,
|
||||
);
|
||||
|
@ -108,9 +117,10 @@ void setupBackgroundTasks() async {
|
|||
await Permission.notification.request();
|
||||
|
||||
// Runs every 15 minutes
|
||||
Workmanager().registerPeriodicTask(
|
||||
'fetch-notifications',
|
||||
await Workmanager().registerPeriodicTask(
|
||||
'fetch_notifications',
|
||||
'fetchNotifications',
|
||||
initialDelay: const Duration(seconds: 30),
|
||||
constraints: Constraints(networkType: NetworkType.connected),
|
||||
initialDelay: const Duration(seconds: 60),
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue