annotate plugins/receipts.js @ 109:cd1f57661439 default tip

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