From 32c3492fabd0e9c48d789d48e871957cbbe04403 Mon Sep 17 00:00:00 2001 From: phgrey Date: Mon, 22 Sep 2014 12:38:23 +0300 Subject: [PATCH 1/5] category for messages fix - copy of https://github.com/amilloy/apnagent/commit/618745a593c56a18ce369ff1003a3d6472667149 --- lib/apnagent/message.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/apnagent/message.js b/lib/apnagent/message.js index 2e74e35..e35e50b 100644 --- a/lib/apnagent/message.js +++ b/lib/apnagent/message.js @@ -347,6 +347,26 @@ Message.prototype.contentAvailable = function (contentAvailable) { }; +/** + * ### .category (identifier) + * + * Set the category for custom actions to be added to this notification + * + * ```js + * msg.category('actionButtons'); + * ``` + * + * @param {String} String identifier for category + * @returns {this} for chaining + * @api public + * @name category + */ + +Message.prototype.category = function (category) { + this.settings.category = category; + return this; +}; + /*! * .serialize () * From abf92c6156ba7e761cd8675f93edcfba8cf97a83 Mon Sep 17 00:00:00 2001 From: phgrey Date: Wed, 20 May 2015 13:39:39 +0300 Subject: [PATCH 2/5] cutting non-spaced push body --- lib/apnagent/util.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/apnagent/util.js b/lib/apnagent/util.js index d0f8cdf..5a5395d 100644 --- a/lib/apnagent/util.js +++ b/lib/apnagent/util.js @@ -33,13 +33,18 @@ var APNS_PORT = 2195 exports.trim = function (str, len) { var origLen = Buffer.byteLength(str) - , expLen = len - 3 - , words = str.split(' ') - , res = words.shift(); + , expLen = len - 3, + first_space = str.indexOf(' '); + if((first_space < expLen) && (first_space >= 0)){ + var words = str.split(' ') + , res = words.shift(); + while (Buffer.byteLength(res + words[0]) < expLen - 2) { + res += ' ' + words.shift(); + } + }else + res = str.slice(0, expLen - 1) + - while (Buffer.byteLength(res + words[0]) < expLen - 2) { - res += ' ' + words.shift(); - } return res + '...'; }; From 02ad4c51806cc4b828bffb863c6657c7875529c1 Mon Sep 17 00:00:00 2001 From: phgrey Date: Mon, 25 May 2015 19:28:37 +0300 Subject: [PATCH 3/5] ibo nadoelo --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 6aae22d..dea8d7b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ lib-cov *.out *.pid *.gz +.idea pids logs From 605c08bd695f074f8096a692ce9502c8b207e3d6 Mon Sep 17 00:00:00 2001 From: phgrey Date: Thu, 19 Nov 2015 13:12:04 +0200 Subject: [PATCH 4/5] some info comment --- lib/apnagent/agent/live.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/apnagent/agent/live.js b/lib/apnagent/agent/live.js index 924a499..be25e92 100644 --- a/lib/apnagent/agent/live.js +++ b/lib/apnagent/agent/live.js @@ -137,6 +137,7 @@ Agent.prototype.connect = function (cb) { }); // handle a disconnection + //gateway._parent gateway.on('close', function () { self.cache.pause(); self.queue.pause(); From 7b038f551643f17dfc6732c9ddbdb872c5b11930 Mon Sep 17 00:00:00 2001 From: phgrey Date: Thu, 24 Dec 2015 17:13:20 +0200 Subject: [PATCH 5/5] multibyte-unicode body trim --- lib/apnagent/util.js | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/lib/apnagent/util.js b/lib/apnagent/util.js index 5a5395d..03d9c66 100644 --- a/lib/apnagent/util.js +++ b/lib/apnagent/util.js @@ -32,20 +32,29 @@ var APNS_PORT = 2195 */ exports.trim = function (str, len) { - var origLen = Buffer.byteLength(str) - , expLen = len - 3, - first_space = str.indexOf(' '); - if((first_space < expLen) && (first_space >= 0)){ - var words = str.split(' ') - , res = words.shift(); - while (Buffer.byteLength(res + words[0]) < expLen - 2) { - res += ' ' + words.shift(); + var buf = new Buffer(str).slice(0, len-3), + //well, let's try to see if the cut was good enough + //meaning utf8 multibyte symbols + //and space for normal encodings + is_ascii = buf[buf.length - 1] < 128; + + + + for(var x = buf.length - 1; x >= 0; x--){ + var chr = buf[x]; + //we've found a space + if(is_ascii && chr == 32){ + break; + //bytes with mask 11xx xxxx are starts of the symbol - https://ru.wikipedia.org/wiki/UTF-8 + }else if(!is_ascii && (chr >= 128 + 64)){ + break; } - }else - res = str.slice(0, expLen - 1) + } + if(x > 1) + buf = buf.slice(0, x); - return res + '...'; + return buf.toString() + '...'; }; exports.gatewayOptions = function (agent) {