Skip to content

Commit 43d5d29

Browse files
committed
Use refactored GCM code
1 parent f0932e9 commit 43d5d29

File tree

1 file changed

+1
-62
lines changed

1 file changed

+1
-62
lines changed

src/Adapters/Push/SNSPushAdapter.js

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -78,70 +78,9 @@ export class SNSPushAdapter extends PushAdapter {
7878
};
7979
}
8080

81-
// FIXME - pull out of GCM as static
82-
generateGCMPayload(coreData, pushId, timeStamp, expirationTime) {
83-
84-
const GCMTimeToLiveMax = 4 * 7 * 24 * 60 * 60; // GCM allows a max of 4 weeks
85-
86-
let payloadData = {
87-
'time': new Date(timeStamp).toISOString(),
88-
'push_id': pushId,
89-
'data': JSON.stringify(coreData)
90-
}
91-
let payload = {
92-
priority: 'normal',
93-
data: payloadData
94-
};
95-
if (expirationTime) {
96-
// The timeStamp and expiration is in milliseconds but gcm requires second
97-
let timeToLive = Math.floor((expirationTime - timeStamp) / 1000);
98-
if (timeToLive < 0) {
99-
timeToLive = 0;
100-
}
101-
if (timeToLive >= GCMTimeToLiveMax) {
102-
timeToLive = GCMTimeToLiveMax;
103-
}
104-
payload.timeToLive = timeToLive;
105-
}
106-
return payload;
107-
}
108-
10981
// Generate proper json for GCM message
11082
generateAndroidPayload(data) {
111-
let pushId = cryptoUtils.newObjectId();
112-
let timeStamp = Date.now();
113-
let expirationTime;
114-
// We handle the expiration_time convertion in push.js, so expiration_time is a valid date
115-
// in Unix epoch time in milliseconds here
116-
if (data['expiration_time']) {
117-
expirationTime = data['expiration_time'];
118-
}
119-
120-
// var payload = this.generateGCMPayload(data.data, pushId, timestamp, expirationTime);
121-
122-
const GCMTimeToLiveMax = 4 * 7 * 24 * 60 * 60; // GCM allows a max of 4 weeks
123-
124-
let payloadData = {
125-
'time': new Date(timeStamp).toISOString(),
126-
'push_id': pushId,
127-
'data': JSON.stringify(data.data)
128-
}
129-
let payload = {
130-
priority: 'normal',
131-
data: payloadData
132-
};
133-
134-
if (expirationTime) {
135-
// The timeStamp and expiration is in milliseconds but gcm requires second
136-
let timeToLive = Math.floor((expirationTime - timeStamp) / 1000);
137-
if (timeToLive < 0) {
138-
timeToLive = 0;
139-
}
140-
if (timeToLive >= GCMTimeToLiveMax) {
141-
timeToLive = GCMTimeToLiveMax;
142-
}
143-
payload.timeToLive = timeToLive;
144-
}
83+
var payload = GCM.generateGCMPayload(data);
14584

14685
// SNS is verify sensitive to the body being JSON stringified but not GCM key.
14786
return {

0 commit comments

Comments
 (0)