File tree Expand file tree Collapse file tree 1 file changed +17
-5
lines changed
backend/api/src/junk-drawer Expand file tree Collapse file tree 1 file changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -180,9 +180,20 @@ const notifyOtherUserInChannelIfInactive = async (
180180 } )
181181 console . log ( 'Sending notification to:' , subscription . endpoint , payload ) ;
182182 await webPush . sendNotification ( subscription , payload ) ;
183- } catch ( err ) {
184- console . error ( 'Failed to send notification' , err ) ;
185- // optionally remove invalid subscription from DB
183+ } catch ( err : any ) {
184+ console . log ( 'Failed to send notification' , err ) ;
185+ if ( err . statusCode === 410 || err . statusCode === 404 ) {
186+ console . warn ( 'Removing expired subscription' , subscription . endpoint ) ;
187+ await pg . none (
188+ `DELETE
189+ FROM push_subscriptions
190+ WHERE endpoint = $1
191+ AND user_id = $2` ,
192+ [ subscription . endpoint , otherUser . id ]
193+ ) ;
194+ } else {
195+ console . error ( 'Push failed' , err ) ;
196+ }
186197 }
187198 }
188199
@@ -223,8 +234,9 @@ export async function getSubscriptionsFromDB(
223234) {
224235 try {
225236 const subscriptions = await pg . manyOrNone ( `
226- select endpoint, keys from push_subscriptions
227- where user_id = $1
237+ select endpoint, keys
238+ from push_subscriptions
239+ where user_id = $1
228240 ` , [ userId ]
229241 ) ;
230242
You can’t perform that action at this time.
0 commit comments