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)
Wed, Sep 25, 7:04 PM
Unknown Object (File)
Wed, Sep 25, 7:04 PM
Unknown Object (File)
Wed, Sep 25, 7:04 PM
Unknown Object (File)
Wed, Sep 25, 7:03 PM
Unknown Object (File)
Wed, Sep 25, 7:02 PM
Unknown Object (File)
Sun, Sep 22, 11:16 AM
Unknown Object (File)
Aug 28 2024, 2:43 PM
Unknown Object (File)
Aug 27 2024, 9:17 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
No Lint Coverage
Unit
No Test Coverage

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

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

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

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

much cleaner, thanks

77

fair point