@@ -40,15 +40,18 @@ export const addComment = mutation({
4040 . withIndex ( "by_user" , ( q ) => q . eq ( "userId" , userId ) )
4141 . first ( ) ;
4242
43- await ctx . runMutation ( internal . notifications . mutation . createNotification , {
44- userId : post . authorId ,
45- type : "COMMENT_ON_POST" ,
46- title : "New Comment" ,
47- message : `${ commenterProfile ?. displayName || commenterProfile ?. githubUsername || "Someone" } commented on your post "${ post . title } "` ,
48- postId : args . postId ,
49- commentId,
50- triggeredById : userId ,
51- } ) ;
43+ await ctx . runMutation (
44+ internal . notifications . mutation . createNotification ,
45+ {
46+ userId : post . authorId ,
47+ type : "COMMENT_ON_POST" ,
48+ title : "New Comment" ,
49+ message : `${ commenterProfile ?. displayName || commenterProfile ?. githubUsername || "Someone" } commented on your post "${ post . title } "` ,
50+ postId : args . postId ,
51+ commentId,
52+ triggeredById : userId ,
53+ }
54+ ) ;
5255 }
5356
5457 // If this is a reply, notify the parent comment author
@@ -60,20 +63,27 @@ export const addComment = mutation({
6063 . withIndex ( "by_user" , ( q ) => q . eq ( "userId" , userId ) )
6164 . first ( ) ;
6265
63- await ctx . runMutation ( internal . notifications . mutation . createNotification , {
64- userId : parentComment . authorId ,
65- type : "COMMENT_ON_POST" ,
66- title : "New Reply" ,
67- message : `${ commenterProfile ?. displayName || commenterProfile ?. githubUsername || "Someone" } replied to your comment` ,
68- postId : args . postId ,
69- commentId,
70- triggeredById : userId ,
71- } ) ;
66+ await ctx . runMutation (
67+ internal . notifications . mutation . createNotification ,
68+ {
69+ userId : parentComment . authorId ,
70+ type : "COMMENT_ON_POST" ,
71+ title : "New Reply" ,
72+ message : `${ commenterProfile ?. displayName || commenterProfile ?. githubUsername || "Someone" } replied to your comment` ,
73+ postId : args . postId ,
74+ commentId,
75+ triggeredById : userId ,
76+ }
77+ ) ;
7278 }
7379 }
7480
7581 // Send notifications to mentioned users
76- const mentionedUserIds = await getMentionedUserIds ( ctx . db , args . content , userId ) ;
82+ const mentionedUserIds = await getMentionedUserIds (
83+ ctx . db ,
84+ args . content ,
85+ userId
86+ ) ;
7787 // Filter out users who already received notifications (post author, parent comment author)
7888 const alreadyNotified = new Set ( [ post . authorId ] ) ;
7989 if ( args . parentId ) {
@@ -85,19 +95,25 @@ export const addComment = mutation({
8595 . query ( "userProfiles" )
8696 . withIndex ( "by_user" , ( q ) => q . eq ( "userId" , userId ) )
8797 . first ( ) ;
88- const commenterName = commenterProfile ?. displayName || commenterProfile ?. githubUsername || "Someone" ;
98+ const commenterName =
99+ commenterProfile ?. displayName ||
100+ commenterProfile ?. githubUsername ||
101+ "Someone" ;
89102
90103 for ( const mentionedUserId of mentionedUserIds ) {
91104 if ( ! alreadyNotified . has ( mentionedUserId ) ) {
92- await ctx . runMutation ( internal . notifications . mutation . createNotification , {
93- userId : mentionedUserId ,
94- type : "MENTIONED" ,
95- title : "You were mentioned" ,
96- message : `${ commenterName } mentioned you in a comment on "${ post . title } "` ,
97- postId : args . postId ,
98- commentId,
99- triggeredById : userId ,
100- } ) ;
105+ await ctx . runMutation (
106+ internal . notifications . mutation . createNotification ,
107+ {
108+ userId : mentionedUserId ,
109+ type : "MENTIONED" ,
110+ title : "You were mentioned" ,
111+ message : `${ commenterName } mentioned you in a comment on "${ post . title } "` ,
112+ postId : args . postId ,
113+ commentId,
114+ triggeredById : userId ,
115+ }
116+ ) ;
101117 }
102118 }
103119
@@ -162,7 +178,10 @@ export const deleteComment = mutation({
162178 // Update post comment count
163179 if ( post ) {
164180 await ctx . db . patch ( post . _id , {
165- commentsCount : Math . max ( 0 , post . commentsCount - 1 - childReplies . length ) ,
181+ commentsCount : Math . max (
182+ 0 ,
183+ post . commentsCount - 1 - childReplies . length
184+ ) ,
166185 } ) ;
167186 }
168187
@@ -183,7 +202,10 @@ export const toggleCommentLike = mutation({
183202 const existingLike = await ctx . db
184203 . query ( "likes" )
185204 . withIndex ( "by_target_user" , ( q ) =>
186- q . eq ( "targetType" , "comment" ) . eq ( "targetId" , args . commentId ) . eq ( "userId" , userId )
205+ q
206+ . eq ( "targetType" , "comment" )
207+ . eq ( "targetId" , args . commentId )
208+ . eq ( "userId" , userId )
187209 )
188210 . first ( ) ;
189211
@@ -213,15 +235,18 @@ export const toggleCommentLike = mutation({
213235 . withIndex ( "by_user" , ( q ) => q . eq ( "userId" , userId ) )
214236 . first ( ) ;
215237
216- await ctx . runMutation ( internal . notifications . mutation . createNotification , {
217- userId : comment . authorId ,
218- type : "LIKE_ON_COMMENT" ,
219- title : "New Like" ,
220- message : `${ likerProfile ?. displayName || likerProfile ?. githubUsername || "Someone" } liked your comment` ,
221- postId : comment . postId ,
222- commentId : args . commentId ,
223- triggeredById : userId ,
224- } ) ;
238+ await ctx . runMutation (
239+ internal . notifications . mutation . createNotification ,
240+ {
241+ userId : comment . authorId ,
242+ type : "LIKE_ON_COMMENT" ,
243+ title : "New Like" ,
244+ message : `${ likerProfile ?. displayName || likerProfile ?. githubUsername || "Someone" } liked your comment` ,
245+ postId : comment . postId ,
246+ commentId : args . commentId ,
247+ triggeredById : userId ,
248+ }
249+ ) ;
225250 }
226251
227252 return { liked : true } ;
0 commit comments