Skip to content

Category parameter #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ lib-cov
*.out
*.pid
*.gz
.idea

pids
logs
Expand Down
1 change: 1 addition & 0 deletions lib/apnagent/agent/live.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ Agent.prototype.connect = function (cb) {
});

// handle a disconnection
//gateway._parent
gateway.on('close', function () {
self.cache.pause();
self.queue.pause();
Expand Down
20 changes: 20 additions & 0 deletions lib/apnagent/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
*
Expand Down
30 changes: 22 additions & 8 deletions lib/apnagent/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down