Permalink
Browse files

Fixing #5

  • Loading branch information...
yavorg committed Feb 10, 2013
1 parent 423de23 commit 160ff0aad1ab04081168f78b12f7209a208a1da2
Showing with 15 additions and 7 deletions.
  1. +2 −1 README.md
  2. +13 −6 lib/mpns.js
View
@@ -49,7 +49,7 @@ For toasts, the properties and ordering for them:
### Sending a live tile update
To send a tile update, call the `sendTile` method on mpns.
-It is recommended that you use the options syntax for this call as it is possible for the live tile update to include just one component in the update, say the tile count, and not update other properties.
+It is recommended that you use the options syntax for this call as it is possible for the live tile update to include just one component in the update, say the tile count, and not update other properties. To clear the value of a property, simply pass `null` as the value.
The option names or ordering for parameters is:
@@ -125,6 +125,7 @@ NPM module written and maintained by [Jeff Wilcox] with contributions from:
- Jeff Wilcox : https://github.com/jeffwilcox
- Shawn Burke : https://github.com/shawnburke
- Jeremie Pelletier : https://github.com/ddude
+- Yavor Georgiev: https://github.com/yavorg
## License
View
@@ -58,7 +58,8 @@ function PushMessage(pushType, quickNotificationClass, targetName, options) {
this.targetName = targetName;
if (options) {
- copyOfInterest(options, this, propertiesOfInterest);
+ copyOfInterest(options, this, propertiesOfInterest,
+ this.pushType === 'tile');
}
}
@@ -104,7 +105,8 @@ PushMessage.prototype.send = function(pushUri, callback) {
}
// Store the fields that were sent to make it easy to log.
- copyOfInterest(me, result, propertiesOfInterest);
+ copyOfInterest(me, result, propertiesOfInterest,
+ this.pushType === 'tile');
switch (res.statusCode) {
// The device is in an inactive state.
@@ -156,11 +158,11 @@ PushMessage.prototype.send = function(pushUri, callback) {
req.end();
};
-function copyOfInterest(source, destination, fieldsOfInterest) {
+function copyOfInterest(source, destination, fieldsOfInterest, allowNull) {
if (source && destination && fieldsOfInterest && fieldsOfInterest.length) {
for (var i = 0; i < fieldsOfInterest.length; i++) {
var key = fieldsOfInterest[i];
- if (source[key]) {
+ if (source[key] || (source[key] === null && allowNull)) {
destination[key] = source[key];
}
}
@@ -230,7 +232,12 @@ function endTag(tag) {
}
function wrapValue(object, key, name) {
- return object[key] ? startTag(name) + escapeXml(object[key]) + endTag(name) : '';
+ // We want to clear the value
+ if(object[key] === null){
+ return startTag(name, [['Action', 'Clear']]) + endTag(name);
+ } else {
+ return object[key] ? startTag(name) + escapeXml(object[key]) + endTag(name) : '';
+ }
}
function toastToXml(options) {
@@ -294,7 +301,7 @@ function send(type, typeProperties, objectType, args) {
var params = {};
if (typeof args[0] === 'object') {
var payload = Array.prototype.shift.apply(args);
- copyOfInterest(payload, params, typeProperties);
+ copyOfInterest(payload, params, typeProperties, type === 'tile');
}
else {
// assume parameters are provided as atomic, string arguments of the function call

0 comments on commit 160ff0a

Please sign in to comment.