@@ -349,31 +349,26 @@ impl WebPushClient {
349349 // Change the min urgency
350350 self . flags . min_urgency = new_min;
351351
352- let status = if let Some ( mut user) = self . app_state . db . get_user ( & self . uaid ) . await ? {
352+ if let Some ( mut user) = self . app_state . db . get_user ( & self . uaid ) . await ? {
353353 // If the user hasn't set a minimum urgency yet, they receive all messages,
354354 // which is equivalent to setting very-low as a minimum
355355 let current_urgency = user. urgency . unwrap_or ( Urgency :: VeryLow ) ;
356+
356357 // We update the user
357358 user. urgency = Some ( new_min) ;
358359 user. connected_at = ms_since_epoch ( ) ;
360+ self . app_state . db . update_user ( & mut user) . await ?;
359361
362+ let mut res = vec ! [ ServerMessage :: Urgency { status: 200 } ] ;
360363 // if new urgency < previous: fetch pending messages
361- if self . app_state . db . update_user ( & mut user) . await . is_ok ( ) {
362- if new_min < current_urgency {
363- self . ack_state . unacked_stored_highest = None ;
364- self . current_timestamp = None ;
365- let mut res = vec ! [ ServerMessage :: Urgency { status: 200 } ] ;
366- res. append ( & mut self . check_storage ( ) . await ?) ;
367- // We return the Urgency Ack + pending messages
368- return Ok ( res) ;
369- }
370- 200
371- } else {
372- 500
364+ if new_min < current_urgency {
365+ self . ack_state . unacked_stored_highest = None ;
366+ self . current_timestamp = None ;
367+ res. append ( & mut self . check_storage ( ) . await ?) ;
373368 }
369+ Ok ( res)
374370 } else {
375- 404
376- } ;
377- Ok ( vec ! [ ServerMessage :: Urgency { status } ] )
371+ Ok ( vec ! [ ServerMessage :: Urgency { status: 404 } ] )
372+ }
378373 }
379374}
0 commit comments