From f21341d35c22a0d5f34745441cb5815a60456a5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Belli?= Date: Mon, 12 Jun 2017 01:07:06 +0200 Subject: [PATCH] Step 17.19: Update facebook.ts to set name and picture from Facebook --- src/pages/login/facebook.ts | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/pages/login/facebook.ts b/src/pages/login/facebook.ts index f1840ae3f..3d0375836 100644 --- a/src/pages/login/facebook.ts +++ b/src/pages/login/facebook.ts @@ -2,6 +2,9 @@ import { Component } from "@angular/core"; import { Alert, AlertController, NavController } from "ionic-angular"; import { PhoneService } from "../../services/phone"; import { ProfilePage } from "../profile/profile"; +import { MeteorObservable } from "meteor-rxjs"; +import { FbProfile } from "api/services/facebook"; +import { Profile } from "api/models"; @Component({ selector: 'facebook', @@ -39,8 +42,29 @@ export class FacebookPage { linkFacebook(): void { this.phoneService.linkFacebook() .then(() => { - this.navCtrl.setRoot(ProfilePage, {}, { - animate: true + MeteorObservable.call('getFbProfile').subscribe({ + next: (fbProfile: FbProfile) => { + const pathname = (new URL(fbProfile.pictureUrl)).pathname; + const filename = pathname.substring(pathname.lastIndexOf('/') + 1); + const description = {name: filename}; + let profile: Profile = {name: fbProfile.name, pictureId: ""}; + MeteorObservable.call('ufsImportURL', fbProfile.pictureUrl, description, 'pictures') + .map((value) => profile.pictureId = (value)._id) + .switchMapTo(MeteorObservable.call('updateProfile', profile)) + .subscribe({ + next: () => { + this.navCtrl.setRoot(ProfilePage, {}, { + animate: true + }); + }, + error: (e: Error) => { + this.handleError(e); + } + }); + }, + error: (e: Error) => { + this.handleError(e); + } }); }) .catch((e) => {