@@ -2,6 +2,9 @@ import { Component } from "@angular/core";
22import { Alert , AlertController , NavController } from "ionic-angular" ;
33import { PhoneService } from "../../services/phone" ;
44import { 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