Skip to content

Commit 3df0779

Browse files
authored
Merge pull request #93 from unisoncomputing/cp/omit-self-notifications
Filter self notifications
2 parents f472f43 + df5bb1b commit 3df0779

File tree

7 files changed

+25
-89
lines changed

7 files changed

+25
-89
lines changed

sql/2025-06-11_skip-self-notifications.sql

Whitespace-only changes.

src/Share/Notifications/Queries.hs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ listNotificationHubEntryPayloads notificationUserId mayLimit mayCursor statusFil
7878
JOIN notification_events event ON hub.event_id = event.id
7979
WHERE hub.user_id = #{notificationUserId}
8080
AND (#{statusFilterList} IS NULL OR hub.status = ANY(#{statusFilterList}::notification_status[]))
81+
-- By default omit notifications that are from the user themself.
82+
AND event.actor_user_id <> #{notificationUserId}
8183
^{cursorFilter}
8284
ORDER BY hub.created_at DESC
8385
LIMIT #{limit}
@@ -86,14 +88,16 @@ listNotificationHubEntryPayloads notificationUserId mayLimit mayCursor statusFil
8688
hydratedPayloads & DisplayInfoQ.unifiedDisplayInfoForUserOf (traversed . hubEntryUserInfo_)
8789

8890
hasUnreadNotifications :: UserId -> Transaction e Bool
89-
hasUnreadNotifications userId = do
91+
hasUnreadNotifications notificationUserId = do
9092
queryExpect1Col
9193
[sql|
9294
SELECT EXISTS(
9395
SELECT
9496
FROM notification_hub_entries hub
95-
WHERE hub.user_id = #{userId}
97+
JOIN notification_events event ON hub.event_id = event.id
98+
WHERE hub.user_id = #{notificationUserId}
9699
AND hub.status = #{Unread}::notification_status
100+
AND event.actor_user_id <> #{notificationUserId}
97101
)
98102
|]
99103

transcripts/share-apis/notifications/list-notifications-test.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,9 @@
201201
"event": {
202202
"actor": {
203203
"info": {
204-
"avatarUrl": null,
205-
"handle": "test",
206-
"name": null,
204+
"avatarUrl": "https://www.gravatar.com/avatar/205e460b479e2e5b48aec07710c08d50?f=y&d=retro",
205+
"handle": "transcripts",
206+
"name": "Transcript User",
207207
"userId": "U-<UUID>"
208208
},
209209
"kind": "user"
@@ -214,9 +214,9 @@
214214
"payload": {
215215
"contribution": {
216216
"author": {
217-
"avatarUrl": null,
218-
"handle": "test",
219-
"name": null,
217+
"avatarUrl": "https://www.gravatar.com/avatar/205e460b479e2e5b48aec07710c08d50?f=y&d=retro",
218+
"handle": "transcripts",
219+
"name": "Transcript User",
220220
"userId": "U-<UUID>"
221221
},
222222
"contributionId": "C-<UUID>",

transcripts/share-apis/notifications/list-notifications-transcripts.json

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -48,75 +48,6 @@
4848
},
4949
"id": "NOT-<UUID>",
5050
"status": "unread"
51-
},
52-
{
53-
"createdAt": "<TIMESTAMP>",
54-
"event": {
55-
"actor": {
56-
"info": {
57-
"avatarUrl": null,
58-
"handle": "test",
59-
"name": null,
60-
"userId": "U-<UUID>"
61-
},
62-
"kind": "user"
63-
},
64-
"data": {
65-
"kind": "project:contribution:created",
66-
"link": "http://<HOST>:1234/@test/publictestproject/contributions/3",
67-
"payload": {
68-
"contribution": {
69-
"author": {
70-
"avatarUrl": null,
71-
"handle": "test",
72-
"name": null,
73-
"userId": "U-<UUID>"
74-
},
75-
"contributionId": "C-<UUID>",
76-
"description": "My description",
77-
"number": 3,
78-
"sourceBranch": {
79-
"branchContributorHandle": null,
80-
"branchContributorUserId": null,
81-
"branchId": "B-<UUID>",
82-
"branchName": "main",
83-
"branchShortHand": "main",
84-
"projectBranchShortHand": "@test/publictestproject/main"
85-
},
86-
"status": "draft",
87-
"targetBranch": {
88-
"branchContributorHandle": null,
89-
"branchContributorUserId": null,
90-
"branchId": "B-<UUID>",
91-
"branchName": "feature",
92-
"branchShortHand": "feature",
93-
"projectBranchShortHand": "@test/publictestproject/feature"
94-
},
95-
"title": "My contribution"
96-
},
97-
"project": {
98-
"projectId": "P-<UUID>",
99-
"projectOwnerHandle": "test",
100-
"projectOwnerUserId": "U-<UUID>",
101-
"projectShortHand": "@test/publictestproject",
102-
"projectSlug": "publictestproject"
103-
}
104-
}
105-
},
106-
"id": "EVENT-<UUID>",
107-
"occurredAt": "<TIMESTAMP>",
108-
"scope": {
109-
"info": {
110-
"avatarUrl": null,
111-
"handle": "test",
112-
"name": null,
113-
"userId": "U-<UUID>"
114-
},
115-
"kind": "user"
116-
}
117-
},
118-
"id": "NOT-<UUID>",
119-
"status": "unread"
12051
}
12152
],
12253
"nextCursor": "<CURSOR>",

transcripts/share-apis/notifications/list-notifications-unread-test.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@
138138
"event": {
139139
"actor": {
140140
"info": {
141-
"avatarUrl": null,
142-
"handle": "test",
143-
"name": null,
141+
"avatarUrl": "https://www.gravatar.com/avatar/205e460b479e2e5b48aec07710c08d50?f=y&d=retro",
142+
"handle": "transcripts",
143+
"name": "Transcript User",
144144
"userId": "U-<UUID>"
145145
},
146146
"kind": "user"
@@ -151,9 +151,9 @@
151151
"payload": {
152152
"contribution": {
153153
"author": {
154-
"avatarUrl": null,
155-
"handle": "test",
156-
"name": null,
154+
"avatarUrl": "https://www.gravatar.com/avatar/205e460b479e2e5b48aec07710c08d50?f=y&d=retro",
155+
"handle": "transcripts",
156+
"name": "Transcript User",
157157
"userId": "U-<UUID>"
158158
},
159159
"contributionId": "C-<UUID>",

transcripts/share-apis/notifications/public-contribution-create.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"body": {
33
"author": {
4-
"avatarUrl": null,
5-
"handle": "test",
6-
"name": null,
4+
"avatarUrl": "https://www.gravatar.com/avatar/205e460b479e2e5b48aec07710c08d50?f=y&d=retro",
5+
"handle": "transcripts",
6+
"name": "Transcript User",
77
"userId": "U-<UUID>"
88
},
99
"createdAt": "<TIMESTAMP>",

transcripts/share-apis/notifications/run.zsh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ fetch "$test_user" POST create-email-delivery '/users/test/notifications/deliver
4141

4242
fetch "$test_user" GET check-delivery-methods '/users/test/notifications/delivery-methods'
4343

44-
# Create a contribution in a public project, which should trigger a notification for both users
45-
fetch "$test_user" POST public-contribution-create '/users/test/projects/publictestproject/contributions' '{
44+
# Create a contribution in a public project, which should trigger a notification for both users, but will be omitted
45+
# from 'transcripts' notification list since it's a self-notification.
46+
fetch "$transcripts_user" POST public-contribution-create '/users/test/projects/publictestproject/contributions' '{
4647
"title": "My contribution",
4748
"description": "My description",
4849
"status": "draft",
@@ -80,7 +81,7 @@ fetch "$test_user" POST private-contribution-create '/users/test/projects/privat
8081
"targetBranchRef": "main"
8182
}'
8283

83-
# Create a new branch in the watched project, which should trigger a branch updated notification
84+
# Create a new branch in the watched project, which should trigger a branch updated notification
8485
fetch "$test_user" POST branch-create '/ucm/v1/projects/create-project-branch' "{
8586
\"project-id\": \"${publictestproject_id}\",
8687
\"branch-name\": \"newbranch\",

0 commit comments

Comments
 (0)