Skip to content

Commit

Permalink
syncFirebaseToken endpoint on sdkService, submit token on new token o…
Browse files Browse the repository at this point in the history
…r token change
  • Loading branch information
lacksfish committed Mar 19, 2018
1 parent fddae65 commit 4535374
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
"use strict";

angular.module("blocktrail.core")
.factory("pushNotificationService", function($rootScope, $window, modalService, $q) {
return new PushNotificationService($rootScope, $window, modalService, $q);
.factory("pushNotificationService", function($rootScope, $window, modalService, $q, sdkService) {
return new PushNotificationService($rootScope, $window, modalService, $q, sdkService);
});

function PushNotificationService($rootScope, $window, modalService, $q) {
function PushNotificationService($rootScope, $window, modalService, $q, sdkService) {
var self = this;

self._rootScope = $rootScope;
self._window = $window;
self._modalService = modalService;
self._q = $q;
self._sdkService = sdkService;
}

/**
Expand Down Expand Up @@ -86,6 +87,14 @@

self._window.FirebasePlugin.getToken(function(token) {
console.debug('Push notification token: ' + token);
// Submit token
self._sdkService.syncFirebaseToken({
device_id: device.uuid,
label: navigator.userAgent,
platform: device.platform,
firebase_token: token
});

}, function(error) {
console.error(error);
});
Expand All @@ -99,7 +108,14 @@

// Register for token changes
self._window.FirebasePlugin.onTokenRefresh(function(token) {
console.debug('token: ' + token);
console.debug('New notification token: ' + token);
// Submit token
self._sdkService.syncFirebaseToken({
device_id: device.uuid,
label: navigator.userAgent,
platform: device.platform,
firebase_token: token
});
}, function(error) {
console.error(error);
});
Expand Down
6 changes: 6 additions & 0 deletions src/js/modules/core/services/sdk/sdk.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,4 +357,10 @@

return self.client.post("/mywallet/feedback", null, data);
};

GenericBlocktrailSDK.prototype.syncFirebaseToken = function (data) {
var self = this;

return self.client.post("/mywallet/notifications/token", null, data);
};
})();

2 comments on commit 4535374

@patinya1908
Copy link

Choose a reason for hiding this comment

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

@patinya1908
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.