Skip to content

Commit 1f5fe25

Browse files
Copilotshoaibsharif
andcommitted
fix: address code review - actor guard, article author username in payload, correct deep links
Agent-Logs-Url: https://github.com/techdiary-dev/techdiary.dev/sessions/a4d2f56f-8ea0-484d-883e-4aa0cce5a9cc Co-authored-by: shoaibsharif <29075110+shoaibsharif@users.noreply.github.com>
1 parent d70acd2 commit 1f5fe25

5 files changed

Lines changed: 30 additions & 4 deletions

File tree

src/app/dashboard/notifications/page.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ function notificationLink(
7070
(type === "COMMENT_ON_ARTICLE" || type === "REACTION_ON_ARTICLE") &&
7171
payload.article_handle
7272
) {
73-
return `/article/${payload.article_handle}`;
73+
const base = payload.article_author_username
74+
? `/@${payload.article_author_username}/${payload.article_handle}`
75+
: `/@${payload.article_handle}`;
76+
return base;
7477
}
7578
if (type === "COMMENT_ON_GIST" && payload.gist_id) {
7679
return `/gists/${payload.gist_id}`;
@@ -79,7 +82,10 @@ function notificationLink(
7982
(type === "REPLY_TO_COMMENT" || type === "REACTION_ON_COMMENT") &&
8083
payload.article_handle
8184
) {
82-
return `/article/${payload.article_handle}`;
85+
const base = payload.article_author_username
86+
? `/@${payload.article_author_username}/${payload.article_handle}`
87+
: `/@${payload.article_handle}`;
88+
return base;
8389
}
8490
return "#";
8591
}

src/backend/models/domain-models.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ export interface NotificationPayload {
275275
article_id?: string;
276276
article_handle?: string;
277277
article_title?: string;
278+
article_author_username?: string;
278279
comment_id?: string;
279280
gist_id?: string;
280281
reaction_type?: string;

src/backend/services/comment.action.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,18 @@ export const createMyComment = async (
5353
});
5454
if (!article) throw new ActionException("Resource not found");
5555
notificationRecipientId = article.author_id;
56+
const [articleAuthor] = await persistenceRepository.user.find({
57+
where: eq("id", article.author_id),
58+
limit: 1,
59+
columns: ["id", "username"],
60+
});
5661
notificationPayload = {
5762
article_id: article.id,
5863
article_handle: article.handle,
5964
article_title: article.title,
65+
...(articleAuthor?.username
66+
? { article_author_username: articleAuthor.username }
67+
: {}),
6068
};
6169
break;
6270
}

src/backend/services/reaction.actions.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ async function sendReactionNotification({
122122
columns: ["id", "name", "username"],
123123
});
124124

125+
if (!actor) return;
126+
125127
if (resourceType === "ARTICLE") {
126128
const [article] = await persistenceRepository.article.find({
127129
where: eq("id", resourceId),
@@ -133,6 +135,14 @@ async function sendReactionNotification({
133135
payload.article_id = article.id;
134136
payload.article_handle = article.handle;
135137
payload.article_title = article.title;
138+
const [articleAuthor] = await persistenceRepository.user.find({
139+
where: eq("id", article.author_id),
140+
limit: 1,
141+
columns: ["id", "username"],
142+
});
143+
if (articleAuthor?.username) {
144+
payload.article_author_username = articleAuthor.username;
145+
}
136146
}
137147
} else if (resourceType === "COMMENT") {
138148
const [comment] = await persistenceRepository.comment.find({
@@ -159,8 +169,8 @@ async function sendReactionNotification({
159169
: "REACTION_ON_COMMENT",
160170
payload: {
161171
...payload,
162-
actor_name: actor?.name,
163-
actor_username: actor?.username,
172+
actor_name: actor.name,
173+
actor_username: actor.username,
164174
},
165175
},
166176
});

src/lib/inngest.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const notificationEventSchema = z.object({
1818
article_id: z.string().optional(),
1919
article_handle: z.string().optional(),
2020
article_title: z.string().optional(),
21+
article_author_username: z.string().optional(),
2122
comment_id: z.string().optional(),
2223
gist_id: z.string().optional(),
2324
reaction_type: z.string().optional(),

0 commit comments

Comments
 (0)