Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

Commit

Permalink
Changes to enhance readability
Browse files Browse the repository at this point in the history
  • Loading branch information
Raghav Katyal committed Jul 8, 2015
1 parent beba29a commit c269647
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions src/windows8/PushPluginProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,48 @@ var pushNotifications = Windows.Networking.PushNotifications;

var createNotificationJSON = function (e) {
var result = {};
result.message = ''; //Added to identify callback as notification type in the API in case where notification has no message

This comment has been minimized.

Copy link
@macdonst

macdonst Jul 9, 2015

Member

You can do:

var result = { message: '' };

which is ever so slightly faster.

This comment has been minimized.

Copy link
@rakatyal

rakatyal Jul 10, 2015

Collaborator

Thanks. Updated.

var notificationPayload;

switch (e.notificationType) {
case pushNotifications.PushNotificationType.toast:
notificationPayload = e.toastNotification.content;
break;

case pushNotifications.PushNotificationType.tile:
notificationPayload = e.tileNotification.content;
if (e.notificationType === pushNotifications.PushNotificationType.toast) {
notificationPayload = e.toastNotification.content;
}
else {
notificationPayload = e.tileNotification.content;
}
var texts = notificationPayload.getElementsByTagName("text");
if (texts.length > 1) {
result.title = texts[0].innerText;
result.message = texts[1].innerText;
}
else if(texts.length === 1) {
result.message = texts[0].innerText;
}
var images = notificationPayload.getElementsByTagName("image");
if (images.length > 0) {
result.image = images[0].getAttribute("src");
}
var soundFile = notificationPayload.getElementsByTagName("audio");
if (soundFile.length > 0) {
result.sound = soundFile[0].getAttribute("src");
}
break;

case pushNotifications.PushNotificationType.badge:
notificationPayload = e.badgeNotification.content;
result.message = '';
result.count = notificationPayload.getElementsByTagName("badge")[0].getAttribute("value");
break;

case pushNotifications.PushNotificationType.raw:
result.message = e.rawNotification.content;
break;
}

if (e.notificationType === pushNotifications.PushNotificationType.toast || e.notificationType === pushNotifications.PushNotificationType.tile) {
var texts = notificationPayload.getElementsByTagName("text");
if (texts.length > 1) {
result.title = texts[0].innerText;
result.message = texts[1].innerText;
}
else {
result.message = texts[0].innerText;
}
var images = notificationPayload.getElementsByTagName("image");
if (images.length > 0) {
result.image = images[0].getAttribute("src");
}
var soundFile = notificationPayload.getElementsByTagName("audio");
if (soundFile.length > 0) {
result.sound = soundFile[0].getAttribute("src");
}
}

result.additionalData = {};
result.additionalData.objectReference = e;
result.additionalData.pushNotificationReceivedEventArgs = e;
return result;
}

Expand Down

0 comments on commit c269647

Please sign in to comment.