-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from Iconica-Development/5.0.0
refactor: new component structure
- Loading branch information
Showing
51 changed files
with
741 additions
and
916 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../CHANGELOG.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../LICENSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,4 @@ analyzer: | |
exclude: | ||
|
||
linter: | ||
rules: | ||
rules: |
1 change: 1 addition & 0 deletions
1
.../firebase_notification_center_repository/lib/firebase_notification_center_repository.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export "src/firebase_notification_repository.dart"; |
151 changes: 151 additions & 0 deletions
151
...ges/firebase_notification_center_repository/lib/src/firebase_notification_repository.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
import "package:cloud_firestore/cloud_firestore.dart"; | ||
import "package:firebase_core/firebase_core.dart"; | ||
import "package:notification_center_repository_interface/notification_center_repository_interface.dart"; | ||
|
||
class FirebaseNotificationRepository | ||
implements NotificationRepositoryInterface { | ||
FirebaseNotificationRepository({ | ||
FirebaseApp? firebaseApp, | ||
this.activeNotificationsCollection = "active_notifications", | ||
this.plannedNotificationsCollection = "planned_notifications", | ||
}) : firebaseApp = firebaseApp ?? Firebase.app(); | ||
|
||
final FirebaseApp firebaseApp; | ||
final String activeNotificationsCollection; | ||
final String plannedNotificationsCollection; | ||
|
||
@override | ||
Future<NotificationModel> addNotification( | ||
String userId, | ||
NotificationModel notification, | ||
List<String> recipientIds, | ||
) async { | ||
var newNotification = notification; | ||
|
||
for (var recipientId in recipientIds) { | ||
DocumentReference notifications; | ||
if (notification.scheduledFor != null && | ||
notification.scheduledFor!.isAfter(DateTime.now())) { | ||
notifications = FirebaseFirestore.instanceFor(app: firebaseApp) | ||
.collection(plannedNotificationsCollection) | ||
.doc(recipientId) | ||
.collection(plannedNotificationsCollection) | ||
.doc(notification.id); | ||
} else { | ||
newNotification = notification.copyWith( | ||
id: "${notification.id}-${DateTime.now().millisecondsSinceEpoch}", | ||
); | ||
|
||
notifications = FirebaseFirestore.instanceFor(app: firebaseApp) | ||
.collection(activeNotificationsCollection) | ||
.doc(recipientId) | ||
.collection(activeNotificationsCollection) | ||
.doc(newNotification.id); | ||
} | ||
|
||
var currentDateTime = DateTime.now(); | ||
newNotification.dateTimePushed = currentDateTime; | ||
var notificationMap = newNotification.toMap(); | ||
await notifications.set(notificationMap); | ||
} | ||
|
||
return newNotification; | ||
} | ||
|
||
@override | ||
Future<void> deleteNotification( | ||
String userId, | ||
String id, | ||
bool planned, | ||
) async { | ||
try { | ||
if (planned) { | ||
await FirebaseFirestore.instanceFor(app: firebaseApp) | ||
.collection(plannedNotificationsCollection) | ||
.doc(userId) | ||
.collection(plannedNotificationsCollection) | ||
.doc(id) | ||
.delete(); | ||
} else { | ||
await FirebaseFirestore.instanceFor(app: firebaseApp) | ||
.collection(activeNotificationsCollection) | ||
.doc(userId) | ||
.collection(activeNotificationsCollection) | ||
.doc(id) | ||
.delete(); | ||
} | ||
} catch (e) { | ||
throw Exception("Failed to delete notification: $e"); | ||
} | ||
} | ||
|
||
@override | ||
Stream<NotificationModel?> getNotification(String userId, String id) { | ||
var notificationStream = FirebaseFirestore.instanceFor(app: firebaseApp) | ||
.collection(activeNotificationsCollection) | ||
.doc(userId) | ||
.collection(activeNotificationsCollection) | ||
.doc(id) | ||
.snapshots() | ||
.map((snapshot) { | ||
if (snapshot.exists) { | ||
if (snapshot.data() == null) { | ||
return null; | ||
} | ||
|
||
return NotificationModel.fromJson(snapshot.data()!); | ||
} else { | ||
return null; | ||
} | ||
}); | ||
|
||
return notificationStream; | ||
} | ||
|
||
@override | ||
Stream<List<NotificationModel>> getNotifications(String userId) { | ||
var notificationsStream = FirebaseFirestore.instanceFor(app: firebaseApp) | ||
.collection(activeNotificationsCollection) | ||
.doc(userId) | ||
.collection(activeNotificationsCollection) | ||
.snapshots() | ||
.map( | ||
(snapshot) => snapshot.docs | ||
.map((doc) => NotificationModel.fromJson(doc.data())) | ||
.toList(), | ||
); | ||
|
||
return notificationsStream; | ||
} | ||
|
||
@override | ||
Future<NotificationModel> updateNotification( | ||
String userId, | ||
NotificationModel notification, | ||
) async { | ||
await FirebaseFirestore.instanceFor(app: firebaseApp) | ||
.collection(activeNotificationsCollection) | ||
.doc(userId) | ||
.collection(activeNotificationsCollection) | ||
.doc(notification.id) | ||
.update(notification.toMap()); | ||
|
||
return notification; | ||
} | ||
|
||
@override | ||
Stream<List<NotificationModel>> getPlannedNotifications(String userId) { | ||
var notificationsStream = FirebaseFirestore.instanceFor(app: firebaseApp) | ||
.collection(plannedNotificationsCollection) | ||
.doc(userId) | ||
.collection(plannedNotificationsCollection) | ||
.snapshots() | ||
.map( | ||
(snapshot) => snapshot.docs | ||
.map((doc) => NotificationModel.fromJson(doc.data())) | ||
.toList(), | ||
); | ||
|
||
return notificationsStream; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
packages/firebase_notification_center_repository/pubspec.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: firebase_notification_center_repository | ||
description: "A new Flutter package project." | ||
version: 5.0.0 | ||
homepage: | ||
publish_to: 'none' | ||
|
||
environment: | ||
sdk: ^3.5.3 | ||
flutter: ">=1.17.0" | ||
|
||
dependencies: | ||
flutter: | ||
sdk: flutter | ||
|
||
# Firebase | ||
cloud_firestore: ^5.4.2 | ||
firebase_core: ^3.5.0 | ||
|
||
notification_center_repository_interface: | ||
git: | ||
url: https://github.com/Iconica-Development/flutter_notification_center.git | ||
path: packages/notification_center_repository_interface | ||
ref: 5.0.0 | ||
|
||
dev_dependencies: | ||
flutter_iconica_analysis: | ||
git: | ||
url: https://github.com/Iconica-Development/flutter_iconica_analysis | ||
ref: 7.0.0 | ||
|
||
flutter: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../CHANGELOG.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../LICENSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,4 @@ analyzer: | |
exclude: | ||
|
||
linter: | ||
rules: | ||
rules: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"flutter":{"platforms":{"dart":{"lib/firebase_options.dart":{"projectId":"appshell-demo","configurations":{"web":"1:431820621472:web:f4b27eea24be24fd1babc5"}}}}}} |
Oops, something went wrong.