Skip to content

Commit f21341d

Browse files
committed
Step 17.19: Update facebook.ts to set name and picture from Facebook
1 parent aead5f7 commit f21341d

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/pages/login/facebook.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { Component } from "@angular/core";
22
import { Alert, AlertController, NavController } from "ionic-angular";
33
import { PhoneService } from "../../services/phone";
44
import { ProfilePage } from "../profile/profile";
5+
import { MeteorObservable } from "meteor-rxjs";
6+
import { FbProfile } from "api/services/facebook";
7+
import { Profile } from "api/models";
58

69
@Component({
710
selector: 'facebook',
@@ -39,8 +42,29 @@ export class FacebookPage {
3942
linkFacebook(): void {
4043
this.phoneService.linkFacebook()
4144
.then(() => {
42-
this.navCtrl.setRoot(ProfilePage, {}, {
43-
animate: true
45+
MeteorObservable.call('getFbProfile').subscribe({
46+
next: (fbProfile: FbProfile) => {
47+
const pathname = (new URL(fbProfile.pictureUrl)).pathname;
48+
const filename = pathname.substring(pathname.lastIndexOf('/') + 1);
49+
const description = {name: filename};
50+
let profile: Profile = {name: fbProfile.name, pictureId: ""};
51+
MeteorObservable.call('ufsImportURL', fbProfile.pictureUrl, description, 'pictures')
52+
.map((value) => profile.pictureId = (<any>value)._id)
53+
.switchMapTo(MeteorObservable.call('updateProfile', profile))
54+
.subscribe({
55+
next: () => {
56+
this.navCtrl.setRoot(ProfilePage, {}, {
57+
animate: true
58+
});
59+
},
60+
error: (e: Error) => {
61+
this.handleError(e);
62+
}
63+
});
64+
},
65+
error: (e: Error) => {
66+
this.handleError(e);
67+
}
4468
});
4569
})
4670
.catch((e) => {

0 commit comments

Comments
 (0)