Skip to content

feat(messaging): AngularFireMessaing - #1749

Merged
davideast merged 5 commits into
angular:masterfrom
davideast:master
Aug 11, 2018
Merged

davideast merged 5 commits into
angular:masterfrom
davideast:master

Conversation

@davideast

Copy link
Copy Markdown
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>;
}

Comment thread src/messaging/messaging.ts Outdated

this.requestPermission = requestPermission(this.messaging);

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

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

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.

Comment thread src/messaging/messaging.ts Outdated

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

this.tokenChanges = new Observable(subscriber => {

@jamesdaniels jamesdaniels Aug 7, 2018 •

Copy link
Copy Markdown
Contributor

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?

Comment thread src/messaging/messaging.ts Outdated

}

deleteToken(token: string) {

@jamesdaniels jamesdaniels Aug 7, 2018 •

Copy link
Copy Markdown
Contributor

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() )
)

Comment thread src/messaging/messaging.ts Outdated
constructor(public app: FirebaseApp) {
this.messaging = app.messaging();

this.requestPermission = requestPermission(this.messaging);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not inline?

Comment thread src/messaging/messaging.ts Outdated
this.messaging.onMessage(subscriber);
});

this.requestToken = this.requestPermission.pipe(

@jamesdaniels jamesdaniels Aug 7, 2018 •

Copy link
Copy Markdown
Contributor

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