annotate plugins/im.js @ 108:5cb4733c5189

many api changes
author Sonny Piers <sonny@fastmail.net>
date Fri, 13 Jul 2012 15:26:18 +0200
parents c06ec02217ee
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1 'use strict';
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
2
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
3 /**
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
4 Copyright (c) 2011, Sonny Piers <sonny at fastmail dot net>
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
5
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
6 Permission to use, copy, modify, and/or distribute this software for any
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
7 purpose with or without fee is hereby granted, provided that the above
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
8 copyright notice and this permission notice appear in all copies.
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
9
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
17 */
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
18
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
19 //////
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
20 //IM//
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
21 //////
106
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 46
diff changeset
22 Lightstring.plugins['im'] = {
46
f23e4741a7c5 Fix im plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 30
diff changeset
23 stanzas: {
106
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 46
diff changeset
24 normal: function(aTo, aSubject, aText) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 46
diff changeset
25 return(
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 46
diff changeset
26 "<message type='normal' to='" + aTo + "'>" +
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 46
diff changeset
27 "<subject>" + aSubject + "</subject>" +
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 46
diff changeset
28 "<body>" + aText + "</body>" +
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 46
diff changeset
29 "</message>"
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 46
diff changeset
30 );
46
f23e4741a7c5 Fix im plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 30
diff changeset
31 },
106
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 46
diff changeset
32 chat: function(aTo, aText, aReceipt) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 46
diff changeset
33 var message = Lightstring.parse(
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 46
diff changeset
34 "<message type='chat' to='" + aTo + "'>" +
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 46
diff changeset
35 "<body>" + aText + "</body>" +
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 46
diff changeset
36 "</message>"
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 46
diff changeset
37 );
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 46
diff changeset
38
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 46
diff changeset
39 if (aReceipt) {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 46
diff changeset
40 var receipt = document.createElement('request');
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 46
diff changeset
41 receipt.setAttribute('xmlns', 'urn:xmpp:receipts');
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 46
diff changeset
42 message.appendChild(receipt);
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 46
diff changeset
43 message.setAttribute('id', Lightstring.newId());
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 46
diff changeset
44 }
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 46
diff changeset
45
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 46
diff changeset
46 return message;
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 46
diff changeset
47 },
30
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
48 }
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
49 };
108
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
50 Object.defineProperties(Lightstring.Stanza.prototype, {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
51 'body': {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
52 get : function(){
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
53 var bodyEl = this.el.querySelector('body');
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
54 if (!bodyEl)
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
55 return null;
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
56
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
57 return bodyEl.textContent;
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
58 },
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
59 // set : function(newValue){ bValue = newValue; },
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
60 enumerable : true,
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
61 configurable : true
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
62 },
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
63 'subject': {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
64 get : function(){
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
65 var subjectEl = this.el.querySelector('subject');
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
66 if (!subjectEl)
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
67 return null;
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
68
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
69 return subjectEl.textContent;
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
70 },
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
71 // set : function(newValue){ bValue = newValue; },
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
72 enumerable : true,
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
73 configurable : true
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
74 }
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
75 });