Skip to content

Commit

Permalink
Merge pull request #2482 from nextcloud/feat/notifications_push_repos…
Browse files Browse the repository at this point in the history
…itory
  • Loading branch information
provokateurin authored Sep 29, 2024
2 parents 7670075 + 29f6a4b commit 8b905a0
Show file tree
Hide file tree
Showing 27 changed files with 3,105 additions and 1 deletion.
1 change: 1 addition & 0 deletions commitlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ rules:
- nextcloud_test_presets
- notes_app
- notifications_app
- notifications_push_repository
- release
- sort_box
- talk_app
Expand Down
6 changes: 6 additions & 0 deletions packages/neon_framework/lib/src/storage/persistence.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ abstract interface class Persistence<T extends Object> {
/// Whether a value exists at the given [key].
FutureOr<bool> containsKey(String key);

/// Returns all keys in the persistent storage.
FutureOr<List<String>> keys();

/// Clears all values from persistent storage.
FutureOr<bool> clear();

Expand Down Expand Up @@ -53,6 +56,9 @@ abstract class CachedPersistence<T extends Object> implements Persistence<T> {
/// when the app is restarted.
void setCache(String key, T value) => cache[key] = value;

@override
List<String> keys() => cache.keys.toList();

@override
bool containsKey(String key) => cache.containsKey(key);

Expand Down
6 changes: 6 additions & 0 deletions packages/neon_framework/lib/src/storage/settings_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ abstract interface class SettingsStore {

/// Removes an entry from persistent storage.
Future<bool> remove(String key);

/// Returns all keys in the persistent storage.
List<String> keys();
}

/// Default implementation of the [SettingsStore] backed by the given [persistence].
Expand Down Expand Up @@ -62,4 +65,7 @@ final class DefaultSettingsStore implements SettingsStore {

@override
Future<bool> setBool(String key, bool value) => persistence.setValue(key, value);

@override
List<String> keys() => persistence.keys();
}
1 change: 0 additions & 1 deletion packages/neon_framework/lib/src/testing/mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import 'package:neon_framework/src/blocs/accounts.dart';
import 'package:neon_framework/src/models/account_cache.dart';
import 'package:neon_framework/src/models/disposable.dart';
import 'package:neon_framework/src/settings/models/exportable.dart';
import 'package:neon_framework/src/storage/persistence.dart';
import 'package:neon_framework/src/utils/account_options.dart';
import 'package:neon_framework/storage.dart';
import 'package:neon_framework/testing.dart';
Expand Down
1 change: 1 addition & 0 deletions packages/neon_framework/lib/storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
library;

export 'package:neon_framework/src/storage/keys.dart' show Storable;
export 'package:neon_framework/src/storage/persistence.dart';
export 'package:neon_framework/src/storage/request_cache.dart' show RequestCache;
export 'package:neon_framework/src/storage/settings_store.dart' show SettingsStore;
export 'package:neon_framework/src/storage/single_value_store.dart' show SingleValueStore;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include: package:neon_lints/dart.yaml

custom_lint:
rules:
- avoid_exports: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export 'src/models/models.dart' show PushNotification;
export 'src/notifications_push_repository.dart';
export 'src/utils/encryption.dart' show parseEncryptedPushNotifications;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export 'push_notification.dart';
export 'push_subscription.dart';
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
import 'package:built_value/standard_json_plugin.dart';
import 'package:crypton/crypton.dart';
import 'package:nextcloud/notifications.dart' as notifications;

part 'push_notification.g.dart';

/// Data for a push notification.
abstract class PushNotification implements Built<PushNotification, PushNotificationBuilder> {
/// Creates a new [PushNotification].
factory PushNotification([void Function(PushNotificationBuilder)? updates]) = _$PushNotification;

const PushNotification._();

/// Creates a new PushNotification object from the given [json] data containing an encrypted [subject].
///
/// Use [PushNotification.fromJson] when the [subject] is not encrypted.
factory PushNotification.fromEncrypted(
Map<String, dynamic> json,
String accountID,
RSAPrivateKey privateKey,
) {
final subject = notifications.DecryptedSubject.fromEncrypted(privateKey, json['subject'] as String);

return PushNotification(
(b) => b
..accountID = accountID
..priority = json['priority'] as String
..type = json['type'] as String
..subject.replace(subject),
);
}

/// Creates a new PushNotification object from the given [json] data.
///
/// Use [PushNotification.fromEncrypted] when you the [subject] is still encrypted.
factory PushNotification.fromJson(Map<String, dynamic> json) => _serializers.deserializeWith(serializer, json)!;

/// Parses this object into a json like map.
Map<String, dynamic> toJson() => _serializers.serializeWith(serializer, this)! as Map<String, dynamic>;

/// The serializer for [PushNotification].
static Serializer<PushNotification> get serializer => _$pushNotificationSerializer;

/// The account associated with this notification.
String get accountID;

/// The priority of the notification.
String get priority;

/// The type of the notification.
String get type;

/// The subject of this notification.
notifications.DecryptedSubject get subject;
}

final Serializers _serializers = (Serializers().toBuilder()
..add(PushNotification.serializer)
..add(notifications.DecryptedSubject.serializer)
..addPlugin(StandardJsonPlugin()))
.build();

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
import 'package:built_value/standard_json_plugin.dart';
import 'package:meta/meta.dart';
import 'package:nextcloud/notifications.dart' as notifications;

part 'push_subscription.g.dart';

@internal
abstract class PushSubscription implements Built<PushSubscription, PushSubscriptionBuilder> {
factory PushSubscription([void Function(PushSubscriptionBuilder)? updates]) = _$PushSubscription;

const PushSubscription._();

factory PushSubscription.fromJson(Map<String, dynamic> json) => _serializers.deserializeWith(serializer, json)!;

Map<String, dynamic> toJson() => _serializers.serializeWith(serializer, this)! as Map<String, dynamic>;

static Serializer<PushSubscription> get serializer => _$pushSubscriptionSerializer;

String? get endpoint;

notifications.PushDevice? get pushDevice;
}

final Serializers _serializers = (Serializers().toBuilder()
..add(PushSubscription.serializer)
..add(notifications.PushDevice.serializer)
..addPlugin(StandardJsonPlugin()))
.build();
Loading

0 comments on commit 8b905a0

Please sign in to comment.