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 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(); diff --git a/lib/apnagent/message.js b/lib/apnagent/message.js index 8545062..73ee54b 100644 --- a/lib/apnagent/message.js +++ b/lib/apnagent/message.js @@ -349,6 +349,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 () * diff --git a/lib/apnagent/util.js b/lib/apnagent/util.js index d0f8cdf..03d9c66 100644 --- a/lib/apnagent/util.js +++ b/lib/apnagent/util.js @@ -32,15 +32,29 @@ var APNS_PORT = 2195 */ exports.trim = function (str, len) { - var origLen = Buffer.byteLength(str) - , expLen = len - 3 - , 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; + } } - return res + '...'; + + if(x > 1) + buf = buf.slice(0, x); + + return buf.toString() + '...'; }; exports.gatewayOptions = function (agent) {