Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #12 from yavorg/master

Adding support for clearing a value
  • Loading branch information...
commit 83c0fff6463f4e6fa899606c02eaee7d773577a1 2 parents 423de23 + ac365ff
@jeffwilcox authored
Showing with 20 additions and 8 deletions.
  1. +6 −1 README.md
  2. +13 −6 lib/mpns.js
  3. +1 −1  package.json
View
7 README.md
@@ -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
@@ -147,6 +148,10 @@ limitations under the License.
## Changelog
+1.2.2:
+
+* Allows clearing a property value for tiles
+
1.2.1:
* Renames `sendRawNotification` to `sendRaw`
View
19 lib/mpns.js
@@ -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
View
2  package.json
@@ -1,7 +1,7 @@
{
"name": "mpns",
"description": "A Node.js interface to the Microsoft Push Notification Service (MPNS) for Windows Phone.",
- "version": "1.2.1",
+ "version": "1.2.2",
"author": "Jeff Wilcox <jeffwilcox+github@gmail.com>",
"contributors": [
{ "name": "Jeff Wilcox", "email": "jeffwilcox+github@gmail.com" },
Please sign in to comment.
Something went wrong with that request. Please try again.