@@ -122,13 +122,13 @@ export const persistNotificationFn = inngest.createFunction(
122122 id : "persist-notification" ,
123123 triggers : [ { event : "app/notification.requested" } ] ,
124124 } ,
125- async ( { event } : { event : { data : NotificationEventData } } ) => {
125+ async ( { event, step } ) => {
126126 const parsed = notificationEventSchema . safeParse ( event . data ) ;
127127 if ( ! parsed . success ) {
128128 return { skipped : true , reason : "invalid-notification-payload" } ;
129129 }
130130
131- let data = parsed . data ;
131+ let data : NotificationEventData = parsed . data ;
132132
133133 if ( data . reaction_request && data . actor_id ) {
134134 const built = await buildPersistableNotification ( {
@@ -182,23 +182,46 @@ export const persistNotificationFn = inngest.createFunction(
182182 return { skipped : true , reason : "self-notification" } ;
183183 }
184184
185- await persistenceRepository . notification . insert ( [
186- {
187- recipient_id : data . recipient_id ,
188- actor_id : data . actor_id ?? null ,
189- type : data . type as NotificationType ,
190- payload : ( data . payload ?? null ) as NotificationPayload | null ,
191- created_at : new Date ( ) ,
192- } ,
193- ] ) ;
185+ const row = {
186+ recipient_id : data . recipient_id ,
187+ actor_id : data . actor_id ?? null ,
188+ type : data . type as NotificationType ,
189+ payload : ( data . payload ?? null ) as NotificationPayload | null ,
190+ created_at : new Date ( ) ,
191+ } ;
194192
195- // Broadcast a lightweight signal so the recipient's browser can invalidate
196- // its TanStack Query caches without polling.
197- await publishMessage (
198- `private-user.${ data . recipient_id } ` ,
199- REALTIME_PUSHER_EVENTS . NOTIFICATION_NEW ,
200- { scope : "notifications" } ,
201- ) ;
193+ await step . run ( "insert-notification-row" , async ( ) => {
194+ try {
195+ const result = await persistenceRepository . notification . insert ( [ row ] ) ;
196+ return {
197+ insertedRow : result ?. rows ?. [ 0 ] ,
198+ } ;
199+ } catch ( err ) {
200+ return {
201+ insertedRow : null ,
202+ message : "Failed to insert notification row" ,
203+ } ;
204+ }
205+ } ) ;
206+
207+ await step . run ( "publish-notification-realtime" , async ( ) => {
208+ try {
209+ await publishMessage (
210+ `private-user.${ data . recipient_id } ` ,
211+ REALTIME_PUSHER_EVENTS . NOTIFICATION_NEW ,
212+ { scope : "notifications" } ,
213+ ) ;
214+ return {
215+ published : true ,
216+ message : "Notification published successfully" ,
217+ } ;
218+ } catch ( err ) {
219+ return {
220+ published : false ,
221+ message : "Failed to publish notification" ,
222+ } ;
223+ }
224+ } ) ;
202225
203226 return { success : true } ;
204227 } ,
0 commit comments