Fix issue with users signing up and not subscribing to push notifications.

This commit is contained in:
Georgi Prodanov 2017-05-22 17:38:36 +03:00
Родитель daef8d24bf
Коммит e4b0012433
3 изменённых файлов: 19 добавлений и 14 удалений

Просмотреть файл

@ -3,7 +3,7 @@ import { NavigationEnd, NavigationStart } from '@angular/router';
import { RouterExtensions } from 'nativescript-angular/router'; import { RouterExtensions } from 'nativescript-angular/router';
import { Page } from 'ui/page'; import { Page } from 'ui/page';
import { utilities } from './shared'; import { utilities } from './shared';
import { FilesService } from './services'; import { FilesService, UsersService, PushNotificationsService } from './services';
@Component({ @Component({
moduleId: module.id, moduleId: module.id,
@ -16,6 +16,8 @@ export class AppComponent implements OnInit {
constructor( constructor(
private _page: Page, private _page: Page,
private _filesService: FilesService, private _filesService: FilesService,
private _usersService: UsersService,
private _push: PushNotificationsService,
private _routerExtensions: RouterExtensions private _routerExtensions: RouterExtensions
) {} ) {}
@ -30,5 +32,10 @@ export class AppComponent implements OnInit {
}); });
this._filesService.emptyAppTempFolder(); this._filesService.emptyAppTempFolder();
// .catch(err => console.log('err while emptying: ' + JSON.stringify(err))); // .catch(err => console.log('err while emptying: ' + JSON.stringify(err)));
this._usersService.currentUser().then(user => {
if (user) {
this._push.subscribe().catch(err => err); // ignore errors
}
});
} }
} }

Просмотреть файл

@ -24,7 +24,7 @@ export class PushNotificationsService {
// this._alertsService.showSuccess('got push' + JSON.stringify(args)); // this._alertsService.showSuccess('got push' + JSON.stringify(args));
} }
subscribe(userId: string) { subscribe() {
let pushRegSettings = { let pushRegSettings = {
iOS: { badge: true, sound: true, alert: true }, iOS: { badge: true, sound: true, alert: true },
android: { senderID: constants.androidProjNumber }, android: { senderID: constants.androidProjNumber },

Просмотреть файл

@ -46,11 +46,7 @@ export class LoginComponent implements OnInit {
} }
login() { login() {
this._usersService.login(this.user.Username, this.user.Password) this._logInUser(this.user.Username, this.user.Password)
.then((loginResult) => {
this._push.subscribe(loginResult.result.principal_id).catch(err => err);
this._goToEvents();
})
.catch((e) => { .catch((e) => {
this._alertsService.showError(e && e.message); this._alertsService.showError(e && e.message);
}); });
@ -65,17 +61,11 @@ export class LoginComponent implements OnInit {
if (errMsg) { if (errMsg) {
return this._alertsService.showError(errMsg); return this._alertsService.showError(errMsg);
} }
let registeredUserId: string;
this._usersService.register(this.user.Username, this.user.Password, this.user.DisplayName) this._usersService.register(this.user.Username, this.user.Password, this.user.DisplayName)
.then((res) => { .then((res) => {
this._alertsService.showSuccess('Welcome to TeamUP!'); this._alertsService.showSuccess('Welcome to TeamUP!');
registeredUserId = res.result.Id; return this._logInUser(this.user.Username, this.user.Password);
return this._usersService.login(this.user.Username, this.user.Password);
})
.then(() => {
this._push.subscribe(registeredUserId).catch(err => err);
this._goToEvents();
}) })
.catch((err) => { .catch((err) => {
if (err) { if (err) {
@ -106,4 +96,12 @@ export class LoginComponent implements OnInit {
let transition = utilities.getPageTransition(); let transition = utilities.getPageTransition();
this._routerExtensions.navigate(['events'], { clearHistory: true, transition }); this._routerExtensions.navigate(['events'], { clearHistory: true, transition });
} }
private _logInUser(username: string, password: string) {
return this._usersService.login(this.user.Username, this.user.Password)
.then(() => {
this._push.subscribe().catch(e => e); // ignore errors
this._goToEvents();
});
}
} }