108
|
1 'use strict';
|
|
2
|
|
3 /**
|
|
4 Copyright (c) 2011, Sonny Piers <sonny at fastmail dot net>
|
|
5 Copyright (c) 2012, Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
|
|
6
|
|
7 Permission to use, copy, modify, and/or distribute this software for any
|
|
8 purpose with or without fee is hereby granted, provided that the above
|
|
9 copyright notice and this permission notice appear in all copies.
|
|
10
|
|
11 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
12 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
13 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
14 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
15 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
16 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
17 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
18 */
|
|
19
|
|
20 /////////////////////////////////////////////////////////////////////////////////
|
|
21 //XEP-0184: Message Delivery Receipts http://xmpp.org/extensions/xep-0184.html //
|
|
22 /////////////////////////////////////////////////////////////////////////////////
|
|
23 (function () {
|
|
24
|
|
25 var ns = 'urn:xmpp:receipts';
|
|
26 Lightstring.plugins['receipts'] = {
|
|
27 namespaces: {
|
|
28 receipts: ns
|
|
29 },
|
|
30 // features: [ns],
|
|
31 // methods: {
|
|
32 // 'received': function(aOnSuccess, aOnError) {
|
|
33 // }
|
|
34 // }
|
|
35 };
|
|
36 Object.defineProperties(Lightstring.Stanza.prototype, {
|
|
37 'receipt': {
|
|
38 get : function() {
|
|
39 var receiptEl;
|
|
40 for (var i = 0, length = this.el.childNodes.length; i < length; i++) {
|
|
41 if (this.el.childNodes[i].namespaceURI === ns) {
|
|
42 receiptEl = this.el.childNodes[i];
|
|
43 break;
|
|
44 }
|
|
45 }
|
|
46 if (!receiptEl)
|
|
47 return null;
|
|
48
|
|
49 var receipt = {name: receiptEl.localName};
|
|
50
|
|
51 var id = receiptEl.getAttribute('id');
|
|
52 if (id)
|
|
53 receipt.id = id;
|
|
54
|
|
55 return receipt;
|
|
56 },
|
|
57 set: function(aProps) {
|
|
58 var receipt = Lightstring.doc.createElementNS(ns, aProps.name);
|
|
59 if (aProps.id)
|
|
60 receipt.setAttribute('id', aProps.id);
|
|
61
|
|
62 var receiptEl;
|
|
63 for (var i = 0, length = this.el.childNodes.length; i < length; i++) {
|
|
64 if (this.el.childNodes[i].namespaceURI === ns) {
|
|
65 receiptEl = this.el.childNodes[i];
|
|
66 break;
|
|
67 }
|
|
68 }
|
|
69 if (receiptEl)
|
|
70 this.el.removeChild(receiptEl);
|
|
71
|
|
72 this.el.appendChild(receipt);
|
|
73 },
|
|
74 enumerable : true,
|
|
75 configurable : true
|
|
76 },
|
|
77 'request': {
|
|
78 get : function() {
|
|
79 var receipt = this.receipt;
|
|
80 if (!receipt || (receipt.name !== 'request'))
|
|
81 return null;
|
|
82
|
|
83 return receipt;
|
|
84 },
|
|
85 set: function(aBool) {
|
|
86 this.receipt = {name: 'request'}
|
|
87 if (!this.id)
|
|
88 this.id = Lightstring.id();
|
|
89 },
|
|
90 enumerable : true,
|
|
91 configurable : true
|
|
92 },
|
|
93 'received': {
|
|
94 get : function() {
|
|
95 var receipt = this.receipt;
|
|
96 if (!receipt || (receipt.name !== 'received'))
|
|
97 return null;
|
|
98
|
|
99 return receipt;
|
|
100 },
|
|
101 set: function(aId) {
|
|
102 this.receipt = {name: 'received', id: aId}
|
|
103 },
|
|
104 enumerable : true,
|
|
105 configurable : true
|
|
106 },
|
|
107 });
|
|
108 Lightstring.Stanza.prototype.replyWithReceived = function(aProps) {
|
|
109 var reply = this.reply(aProps);
|
|
110 reply.received = this.id;
|
|
111
|
|
112 return reply;
|
|
113 };
|
|
114
|
|
115 })(); |