You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: functions/src/notifications/README.md
+37-16Lines changed: 37 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -6,45 +6,59 @@ The notification feature is responsible for sending notifications to users based
6
6
7
7
## Features
8
8
9
-
-**Topic-Based Notifications**: Users receive notifications based on topics they are interested in.
10
-
-**Scheduled Triggers**: Functions are triggered based on a publication schedule.
11
-
-**Multi-Environment Support**: Both HTTP callable and pubSub versions of functions are available for testing and production, respectively.
9
+
-**Topic-Based Notifications**: Users receive notifications based on topics they are subscribed to.
10
+
- Each user has a list of topics created when subscribing to a Bill, User, or Organization.
11
+
- Topics can be categorized as either Bill Topics or Organization Topics:
12
+
-`bill-[courtId]-[billId]`: Triggers when a subscribed Bill has a history update or when testimony is posted on the Bill.
13
+
-`testimony-[userId]`: Triggers when a subscribed User or Organization posts testimony.
14
+
-**Notification Events**
15
+
- A BillHistoryNotificationEvent is created when a subscribed Bill has an updated history
16
+
- A TestimonySubmissionNotificationEvent is created when a subscribed Bill has testimony published and when a Organization/User publishes testimony
17
+
-**Event Triggers**: Functions are triggered based on changes in the `notificationEvents` collection
12
18
13
19
## Architecture
14
20
15
-
### Events
21
+
### Notification Events
16
22
17
23
A user could be subscribed to a given topic, and receive a notification of a bill or profile (such as an organization) that fall under that topic have an event.
The following cloud functions are involved in the notification process:
31
34
32
-
1.**publishNotifications**:
35
+
1.**populateBillHistoryNotifictionEvents** and **populateTestimonySubmissionNotificationEvents**:
36
+
37
+
- Creates/Updates a notificationEvent document when:
38
+
- A Bill is created or updated, if the history is updated, it will update the notificationEvent history and not create a new one.
39
+
- Testimony is published or updated, if the testimony content is updated, it will update the notificationEvent testimony content an not create a new one.
33
40
34
-
- Creates a notification document from an event.
41
+
2.**publishNotifications**:
42
+
43
+
- Creates a notification document from an notification event.
35
44
- Populates the user's `userNotificationFeed` collection with a notification document.
36
45
- Populates the newsfeed.
37
46
38
47
For example, here is a notification document in a given user's feed:
- There are two key fields to differentiate whether a notification came from following a bill or following a user/organization:
52
+
-`isBillMatch` and `isUserMatch` indicate the source of the notification.
53
+
- For example, if a user follows both a bill and an organization, and the organization posts testimony to that same bill, both `isBillMatch` and `isUserMatch` will be true.
54
+
- If a user follows only the bill and not the organization, `isBillMatch` will be true and `isUserMatch` will be false, and vice versa.
41
55
42
-
1.**deliverNotifications**:
56
+
3.**deliverNotifications**:
43
57
44
58
- Sends notifications to users who have a `notificationFrequency` of 'daily' and whose `nextDigestAt` is less than or equal to the current time.
45
59
- Populates the `emails` collection with a notification document.
46
60
47
-
2.**cleanUpNotifications**:
61
+
4.**cleanUpNotifications**:
48
62
- Removes notifications from the users' userNotificationFeed collection that are older than 60 days.
49
63
- Removes notifications from the notificationEvents collection that are older than 60 days.
50
64
- Removes notifications from the emails collection that are older than 60 days.
@@ -54,6 +68,7 @@ The following cloud functions are involved in the notification process:
54
68
-`activeTopicSubscriptions`: Stores the active topic subscriptions for users.
55
69
-`emails`: Stores the notification mails sent to users.
56
70
-`notificationEvents`: Stores the events that trigger notifications.
71
+
-`userNotificationFeed`: Stores the notifications for each user
57
72
58
73
### Query Logic
59
74
@@ -67,6 +82,12 @@ To test these functions in a container environment, use the following command:
67
82
yarn firebase-admin -e local run-script <name-of-script>
68
83
```
69
84
85
+
or to test the notifications as a whole
86
+
87
+
```bash
88
+
yarn test:integration notifications.test.ts
89
+
```
90
+
70
91
## Future Considerations
71
92
72
93
-`publishNotifications` currently listens to the `notificationEvents` collection but could be extended to include other collections.
0 commit comments