Page MenuHomePhabricator

[Tunnelbroker] implement sending FCM message
ClosedPublic

Authored by kamil on Jul 16 2024, 1:24 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Nov 2, 2:15 AM
Unknown Object (File)
Fri, Nov 1, 10:18 AM
Unknown Object (File)
Fri, Nov 1, 10:18 AM
Unknown Object (File)
Fri, Nov 1, 10:18 AM
Unknown Object (File)
Fri, Nov 1, 10:18 AM
Unknown Object (File)
Fri, Nov 1, 10:18 AM
Unknown Object (File)
Oct 18 2024, 3:18 AM
Unknown Object (File)
Sep 25 2024, 7:04 PM
Subscribers

Details

Summary

Sending Firebase Message according to docs.

Depends on D12768

Test Plan

Run this method with different params and check both error statuses and if notif is delivered to physical Android device.

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

kamil held this revision as a draft.
kamil published this revision for review.Jul 16 2024, 2:43 AM
kamil edited the summary of this revision. (Show Details)
kamil added inline comments.
services/tunnelbroker/src/notifs/fcm/mod.rs
71–134 ↗(On Diff #42326)

This looks strange but I wanted to map reqwest status codes to FCM errors

Proposed an optional alternative to error handling

services/tunnelbroker/src/notifs/fcm/mod.rs
71–134 ↗(On Diff #42326)

Maybe sth like this? (StatusCode implements Display trait so you can use it in the error!:

impl FCMError {
  fn from_status(status: &StatusCode, body: typeof Body) -> Self {
    match status {
      StatusCode::BAD_REQUEST => FCMError(Unavailable),
      StatusCode::NOT_FOUND => FCMError(Unregistered),
      // ...
      _ => FCMError(UnspecifiedError)
    }
  }
}

Then the above code can be

match response.status() {
    StatusCode::OK => {
      debug!("Successfully sent FCM notif to {}", token);
      Ok(())
    }
    error_status => {
      let body = response.text().await.unwrap();
      error!(
        "Failed sending FCM notification to: {}. Status: {}. Body: {}",
        token, error_status, body
      );
      let fcm_error = FCMError::from_status(error_status, body);
      Err(fcm_error)
    }
77 ↗(On Diff #42326)

Can we do sth like unwrap_or_default()? It's better to avoid crashes when just trying to display error body

This revision is now accepted and ready to land.Jul 17 2024, 9:18 AM
services/tunnelbroker/src/notifs/fcm/mod.rs
71–134 ↗(On Diff #42326)

much cleaner, thanks

77 ↗(On Diff #42326)

fair point