Skip to content

Commit f2d3ed9

Browse files
Fixed #6
Added support for custom xml element in push and pushHtml methods
1 parent 24c49f4 commit f2d3ed9

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

lib/reactnative-xmpp.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ Client = function (conf) {
169169
self.emit('presence.'+ element.getAttribute('type'), element);
170170
}
171171

172-
self.emit('presence.receive', attrs.from, attrs.to, attrs.status, attrs.priority, attrs.type, element);
172+
self.emit('presence.receive', element);
173173
}
174174

175175
stream_events_manager.on('end|presence|' + NS_CLIENT, presenceReceived);
@@ -455,16 +455,17 @@ Client.prototype.getVCard = function (to, cb) {
455455
* - to (String): receiver jid (ex: "john.doe@domain.com") to send message
456456
* - str (String): the message
457457
* - type (String): message type, default "chat", could be "groupchat" for MUC
458+
* - data (String): xml element to be added to the message
458459
*
459460
* Send instant message.
460461
**/
461-
Client.prototype.push = function (to, str, type) {
462+
Client.prototype.push = function (to, str, type, data = undefined) {
462463
if (type === "groupchat") {
463464
to = this.getBareJid(to);
464465
}
465466
var raw = '<message from="' + this.jid + '" '
466467
+ (typeof type === "string" ? ' type="' + type + '"' : ' type="chat"')
467-
+ ' to="' + to + '"><body><![CDATA[' + str + ']]></body></message>';
468+
+ ' to="' + to + '">' + (data ? data : "") + '<body><![CDATA[' + str + ']]></body></message>';
468469
this.write(raw);
469470
this.emit('message.sent', to, str);
470471
return this;
@@ -478,14 +479,14 @@ Client.prototype.push = function (to, str, type) {
478479
*
479480
* Send HTML instant message.
480481
**/
481-
Client.prototype.pushHtml = function (to, str, type) {
482+
Client.prototype.pushHtml = function (to, str, type, data = undefined) {
482483
if (type === "groupchat") {
483484
to = this.getBareJid(to);
484485
}
485486
var raw = '<message from="' + this.jid + '" '
486487
+ 'to="' + to +'" '
487488
+ (typeof type === "string" ? ' type="' + type + '"' : ' type="chat"')
488-
+ '><body>' + str.replace(/(\<[^\>]+\>|\<\/[^\>]+\>|\<[^\>]+\/\>)/g, '') + '</body>'
489+
+ '>' + (data ? data : "") + '<body>' + str.replace(/(\<[^\>]+\>|\<\/[^\>]+\>|\<[^\>]+\/\>)/g, '') + '</body>'
489490
+ '<html xmlns="' + NS_XHTML_IM + '">'
490491
+ '<body xmlns="' + NS_XHTML + '">' + str + '</body></html></message>';
491492
this.write(raw);

0 commit comments

Comments
 (0)