Skip to content

Commit

Permalink
feat(notifications_push_repository): Init
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin committed Sep 29, 2024
1 parent 43d4983 commit 80071e4
Show file tree
Hide file tree
Showing 23 changed files with 3,092 additions and 0 deletions.
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
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 80071e4

Please sign in to comment.