Skip to content

Conversation

davideast
Copy link
Collaborator

AngularFireMessaging

This is a WIP, but here is the current API surface.

class AngularFireMessaging {
  messaging: FirebaseMessaging;
  requestPermission: Observable<void>;
  getToken: Observable<string>;
  tokenChanges: Observable<string>;
  messages: Observable<{}>;
  requestToken: Observable<string>;
  deleteToken: (token: string) => Observable<any>;
}


this.requestPermission = requestPermission(this.messaging);

this.getToken = from(this.messaging.getToken());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make this a single IMO

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Err, that's a Promise hance a single... nevermind.


this.getToken = from(this.messaging.getToken());

this.tokenChanges = new Observable(subscriber => {
Copy link
Member

@jamesdaniels jamesdaniels Aug 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So now that I'm playing with this I'm not sure I like this API. I think I'd prefer:

this.tokenChanges => from(this.messaging.onTokenRefresh);

this.token => this.getToken.pipe(concat(this.tokenChanges))

Thoughts?


}

deleteToken(token: string) {
Copy link
Member

@jamesdaniels jamesdaniels Aug 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm... not sure about this API either, how about

this.deleteToken = this.getToken.pipe(
  mergeMap(t => t ? this.messaging.deleteToken(t) : empty() )
)

constructor(public app: FirebaseApp) {
this.messaging = app.messaging();

this.requestPermission = requestPermission(this.messaging);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not inline?

this.messaging.onMessage(subscriber);
});

this.requestToken = this.requestPermission.pipe(
Copy link
Member

@jamesdaniels jamesdaniels Aug 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should catch the requestPermission exception and complete with null

@davideast davideast merged commit 26f7613 into angular:master Aug 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants