Mercurial > snowl
annotate modules/twitter.js @ 382:8460f746207e default tip
remove extraneous log statement
author | Myk Melez <myk@mozilla.org> |
---|---|
date | Sat, 08 Nov 2008 10:38:57 -0800 |
parents | 6916b17a0536 2116e44e4c17 |
children |
rev | line source |
---|---|
229
b324ba5e93f0
add license header blocks to all CSS & JS files
Myk Melez <myk@mozilla.org>
parents:
225
diff
changeset
|
1 /* ***** BEGIN LICENSE BLOCK ***** |
b324ba5e93f0
add license header blocks to all CSS & JS files
Myk Melez <myk@mozilla.org>
parents:
225
diff
changeset
|
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
b324ba5e93f0
add license header blocks to all CSS & JS files
Myk Melez <myk@mozilla.org>
parents:
225
diff
changeset
|
3 * |
b324ba5e93f0
add license header blocks to all CSS & JS files
Myk Melez <myk@mozilla.org>
parents:
225
diff
changeset
|
4 * The contents of this file are subject to the Mozilla Public License Version |
b324ba5e93f0
add license header blocks to all CSS & JS files
Myk Melez <myk@mozilla.org>
parents:
225
diff
changeset
|
5 * 1.1 (the "License"); you may not use this file except in compliance with |
b324ba5e93f0
add license header blocks to all CSS & JS files
Myk Melez <myk@mozilla.org>
parents:
225
diff
changeset
|
6 * the License. You may obtain a copy of the License at |
b324ba5e93f0
add license header blocks to all CSS & JS files
Myk Melez <myk@mozilla.org>
parents:
225
diff
changeset
|
7 * http://www.mozilla.org/MPL/ |
b324ba5e93f0
add license header blocks to all CSS & JS files
Myk Melez <myk@mozilla.org>
parents:
225
diff
changeset
|
8 * |
b324ba5e93f0
add license header blocks to all CSS & JS files
Myk Melez <myk@mozilla.org>
parents:
225
diff
changeset
|
9 * Software distributed under the License is distributed on an "AS IS" basis, |
b324ba5e93f0
add license header blocks to all CSS & JS files
Myk Melez <myk@mozilla.org>
parents:
225
diff
changeset
|
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
b324ba5e93f0
add license header blocks to all CSS & JS files
Myk Melez <myk@mozilla.org>
parents:
225
diff
changeset
|
11 * for the specific language governing rights and limitations under the |
b324ba5e93f0
add license header blocks to all CSS & JS files
Myk Melez <myk@mozilla.org>
parents:
225
diff
changeset
|
12 * License. |
b324ba5e93f0
add license header blocks to all CSS & JS files
Myk Melez <myk@mozilla.org>
parents:
225
diff
changeset
|
13 * |
b324ba5e93f0
add license header blocks to all CSS & JS files
Myk Melez <myk@mozilla.org>
parents:
225
diff
changeset
|
14 * The Original Code is Snowl. |
b324ba5e93f0
add license header blocks to all CSS & JS files
Myk Melez <myk@mozilla.org>
parents:
225
diff
changeset
|
15 * |
b324ba5e93f0
add license header blocks to all CSS & JS files
Myk Melez <myk@mozilla.org>
parents:
225
diff
changeset
|
16 * The Initial Developer of the Original Code is Mozilla. |
b324ba5e93f0
add license header blocks to all CSS & JS files
Myk Melez <myk@mozilla.org>
parents:
225
diff
changeset
|
17 * Portions created by the Initial Developer are Copyright (C) 2008 |
b324ba5e93f0
add license header blocks to all CSS & JS files
Myk Melez <myk@mozilla.org>
parents:
225
diff
changeset
|
18 * the Initial Developer. All Rights Reserved. |
b324ba5e93f0
add license header blocks to all CSS & JS files
Myk Melez <myk@mozilla.org>
parents:
225
diff
changeset
|
19 * |
b324ba5e93f0
add license header blocks to all CSS & JS files
Myk Melez <myk@mozilla.org>
parents:
225
diff
changeset
|
20 * Contributor(s): |
b324ba5e93f0
add license header blocks to all CSS & JS files
Myk Melez <myk@mozilla.org>
parents:
225
diff
changeset
|
21 * Myk Melez <myk@mozilla.org> |
b324ba5e93f0
add license header blocks to all CSS & JS files
Myk Melez <myk@mozilla.org>
parents:
225
diff
changeset
|
22 * |
b324ba5e93f0
add license header blocks to all CSS & JS files
Myk Melez <myk@mozilla.org>
parents:
225
diff
changeset
|
23 * Alternatively, the contents of this file may be used under the terms of |
b324ba5e93f0
add license header blocks to all CSS & JS files
Myk Melez <myk@mozilla.org>
parents:
225
diff
changeset
|
24 * either the GNU General Public License Version 2 or later (the "GPL"), or |
b324ba5e93f0
add license header blocks to all CSS & JS files
Myk Melez <myk@mozilla.org>
parents:
225
diff
changeset
|
25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), |
b324ba5e93f0
add license header blocks to all CSS & JS files
Myk Melez <myk@mozilla.org>
parents:
225
diff
changeset
|
26 * in which case the provisions of the GPL or the LGPL are applicable instead |
b324ba5e93f0
add license header blocks to all CSS & JS files
Myk Melez <myk@mozilla.org>
parents:
225
diff
changeset
|
27 * of those above. If you wish to allow use of your version of this file only |
b324ba5e93f0
add license header blocks to all CSS & JS files
Myk Melez <myk@mozilla.org>
parents:
225
diff
changeset
|
28 * under the terms of either the GPL or the LGPL, and not to allow others to |
b324ba5e93f0
add license header blocks to all CSS & JS files
Myk Melez <myk@mozilla.org>
parents:
225
diff
changeset
|
29 * use your version of this file under the terms of the MPL, indicate your |
b324ba5e93f0
add license header blocks to all CSS & JS files
Myk Melez <myk@mozilla.org>
parents:
225
diff
changeset
|
30 * decision by deleting the provisions above and replace them with the notice |
b324ba5e93f0
add license header blocks to all CSS & JS files
Myk Melez <myk@mozilla.org>
parents:
225
diff
changeset
|
31 * and other provisions required by the GPL or the LGPL. If you do not delete |
b324ba5e93f0
add license header blocks to all CSS & JS files
Myk Melez <myk@mozilla.org>
parents:
225
diff
changeset
|
32 * the provisions above, a recipient may use your version of this file under |
b324ba5e93f0
add license header blocks to all CSS & JS files
Myk Melez <myk@mozilla.org>
parents:
225
diff
changeset
|
33 * the terms of any one of the MPL, the GPL or the LGPL. |
b324ba5e93f0
add license header blocks to all CSS & JS files
Myk Melez <myk@mozilla.org>
parents:
225
diff
changeset
|
34 * |
b324ba5e93f0
add license header blocks to all CSS & JS files
Myk Melez <myk@mozilla.org>
parents:
225
diff
changeset
|
35 * ***** END LICENSE BLOCK ***** */ |
b324ba5e93f0
add license header blocks to all CSS & JS files
Myk Melez <myk@mozilla.org>
parents:
225
diff
changeset
|
36 |
205 | 37 let EXPORTED_SYMBOLS = ["SnowlTwitter"]; |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
38 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
39 const Cc = Components.classes; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
40 const Ci = Components.interfaces; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
41 const Cr = Components.results; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
42 const Cu = Components.utils; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
43 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
44 // modules that come with Firefox |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
45 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
46 Cu.import("resource://gre/modules/ISO8601DateUtils.jsm"); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
47 |
308
553ceeb3507b
factor out PART_TYPE_* constants
Myk Melez <myk@mozilla.org>
parents:
287
diff
changeset
|
48 // modules that are generic |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
49 Cu.import("resource://snowl/modules/log4moz.js"); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
50 Cu.import("resource://snowl/modules/Observers.js"); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
51 Cu.import("resource://snowl/modules/URI.js"); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
52 |
287
113312a23f53
use julian dates for the lastRefreshed values, push date conversion up the stack (away from the core database access routines), and make the datastore code migrate from a version 4 to a version 5 schema (storing julian instead of JS dates)
Myk Melez <myk@mozilla.org>
parents:
283
diff
changeset
|
53 // modules that are Snowl-specific |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
54 Cu.import("resource://snowl/modules/datastore.js"); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
55 Cu.import("resource://snowl/modules/source.js"); |
357
1db123f46ed7
add some glue to let sources be queried to see if they are also targets
Myk Melez <myk@mozilla.org>
parents:
355
diff
changeset
|
56 Cu.import("resource://snowl/modules/target.js"); |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
57 Cu.import("resource://snowl/modules/identity.js"); |
282
76ee747a1dba
add messages progressively to the stream view rather than rebuilding the view each time
Myk Melez <myk@mozilla.org>
parents:
260
diff
changeset
|
58 Cu.import("resource://snowl/modules/message.js"); |
287
113312a23f53
use julian dates for the lastRefreshed values, push date conversion up the stack (away from the core database access routines), and make the datastore code migrate from a version 4 to a version 5 schema (storing julian instead of JS dates)
Myk Melez <myk@mozilla.org>
parents:
283
diff
changeset
|
59 Cu.import("resource://snowl/modules/utils.js"); |
239
2116e44e4c17
Added a simple, tentative source type registration API to SnowlService. Rather than coupling SnowlService to specific source types by importing their JS modules in service.js, we now have the source types register with SnowlService upon import by calling a new method, SnowlService.addSourceType(). This makes it easy for third parties to add new source types without having to modify Snowl's source code.
Atul Varma <varmaa@toolness.com>
parents:
229
diff
changeset
|
60 Cu.import("resource://snowl/modules/service.js"); |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
61 |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
62 const NAME = "Twitter"; |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
63 const MACHINE_URI = URI.get("https://twitter.com"); |
211
9c5fdc76cb35
store the list of collections in the database
Myk Melez <myk@mozilla.org>
parents:
208
diff
changeset
|
64 // XXX Should this be simply http://twitter.com ? |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
65 const HUMAN_URI = URI.get("http://twitter.com/home"); |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
66 |
283
ae23e6f323db
refresh twitter every three minutes
Myk Melez <myk@mozilla.org>
parents:
282
diff
changeset
|
67 function SnowlTwitter(aID, aName, aMachineURI, aHumanURI, aLastRefreshed, aImportance) { |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
68 // XXX Should we append the username to the NAME const to enable users |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
69 // to subscribe to multiple Twitter accounts? |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
70 |
357
1db123f46ed7
add some glue to let sources be queried to see if they are also targets
Myk Melez <myk@mozilla.org>
parents:
355
diff
changeset
|
71 // Call the superclasses' constructors to initialize the new instance. |
1db123f46ed7
add some glue to let sources be queried to see if they are also targets
Myk Melez <myk@mozilla.org>
parents:
355
diff
changeset
|
72 // FIXME: use composition to inherit functionality from the superclasses. |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
73 SnowlSource.call(this, aID, NAME, MACHINE_URI, HUMAN_URI, aLastRefreshed, aImportance); |
357
1db123f46ed7
add some glue to let sources be queried to see if they are also targets
Myk Melez <myk@mozilla.org>
parents:
355
diff
changeset
|
74 SnowlTarget.call(this); |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
75 } |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
76 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
77 SnowlTwitter.prototype = { |
283
ae23e6f323db
refresh twitter every three minutes
Myk Melez <myk@mozilla.org>
parents:
282
diff
changeset
|
78 // How often to refresh sources, in milliseconds. |
ae23e6f323db
refresh twitter every three minutes
Myk Melez <myk@mozilla.org>
parents:
282
diff
changeset
|
79 refreshInterval: 1000 * 60 * 3, // 30 minutes |
ae23e6f323db
refresh twitter every three minutes
Myk Melez <myk@mozilla.org>
parents:
282
diff
changeset
|
80 |
357
1db123f46ed7
add some glue to let sources be queried to see if they are also targets
Myk Melez <myk@mozilla.org>
parents:
355
diff
changeset
|
81 // The constructor property is defined automatically, but we destroy it |
1db123f46ed7
add some glue to let sources be queried to see if they are also targets
Myk Melez <myk@mozilla.org>
parents:
355
diff
changeset
|
82 // when we redefine the prototype, so we redefine it here in case we ever |
1db123f46ed7
add some glue to let sources be queried to see if they are also targets
Myk Melez <myk@mozilla.org>
parents:
355
diff
changeset
|
83 // need to check it to find out what kind of object an instance is. |
205 | 84 constructor: SnowlTwitter, |
85 | |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
86 __proto__: SnowlSource.prototype, |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
87 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
88 _log: Log4Moz.Service.getLogger("Snowl.Twitter"), |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
89 |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
90 |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
91 //**************************************************************************// |
357
1db123f46ed7
add some glue to let sources be queried to see if they are also targets
Myk Melez <myk@mozilla.org>
parents:
355
diff
changeset
|
92 // Class Composition Goo |
1db123f46ed7
add some glue to let sources be queried to see if they are also targets
Myk Melez <myk@mozilla.org>
parents:
355
diff
changeset
|
93 |
1db123f46ed7
add some glue to let sources be queried to see if they are also targets
Myk Melez <myk@mozilla.org>
parents:
355
diff
changeset
|
94 _classes: [SnowlSource, SnowlTarget], |
1db123f46ed7
add some glue to let sources be queried to see if they are also targets
Myk Melez <myk@mozilla.org>
parents:
355
diff
changeset
|
95 |
1db123f46ed7
add some glue to let sources be queried to see if they are also targets
Myk Melez <myk@mozilla.org>
parents:
355
diff
changeset
|
96 implements: function(cls) { |
1db123f46ed7
add some glue to let sources be queried to see if they are also targets
Myk Melez <myk@mozilla.org>
parents:
355
diff
changeset
|
97 return (this._classes.indexOf(cls) != -1); |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
98 }, |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
99 |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
100 |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
101 //**************************************************************************// |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
102 // Notification Callbacks for Authentication |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
103 |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
104 // FIXME: factor this out with the equivalent code in feed.js. |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
105 |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
106 // If we prompt the user to authenticate, and the user asks us to remember |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
107 // their password, we store the nsIAuthInformation in this property until |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
108 // the request succeeds, at which point we store it with the login manager. |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
109 _authInfo: null, |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
110 |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
111 // Logins from the login manager that we try in turn until we run out of them |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
112 // or one of them works. |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
113 // XXX Should we only try the username the user entered when they originally |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
114 // subscribed to the source? After all, different usernames could result in |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
115 // different content, and it might not be what the user expects. |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
116 _logins: null, |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
117 _loginIndex: 0, |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
118 |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
119 // nsISupports |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
120 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
121 QueryInterface: XPCOMUtils.generateQI([Ci.nsIAuthPrompt2]), |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
122 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
123 // nsIInterfaceRequestor |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
124 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
125 getInterface: function(iid) { |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
126 return this.QueryInterface(iid); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
127 }, |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
128 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
129 // nsIAuthPrompt2 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
130 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
131 promptAuth: function(channel, level, authInfo) { |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
132 // Check saved logins before prompting the user. We get them |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
133 // from the login manager and try each in turn until one of them works |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
134 // or we run out of them. |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
135 if (!this._logins) { |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
136 let lm = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
137 // XXX Should we be using channel.URI.prePath in case the old URI |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
138 // redirects us to a new one at a different hostname? |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
139 this._logins = lm.findLogins({}, this.machineURI.prePath, null, authInfo.realm); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
140 } |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
141 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
142 let login = this._logins[this._loginIndex]; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
143 if (login) { |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
144 authInfo.username = login.username; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
145 authInfo.password = login.password; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
146 ++this._loginIndex; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
147 return true; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
148 } |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
149 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
150 // If we've made it this far, none of the saved logins worked, so we prompt |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
151 // the user to provide one. |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
152 let args = Cc["@mozilla.org/supports-array;1"].createInstance(Ci.nsISupportsArray); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
153 args.AppendElement({ wrappedJSObject: this }); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
154 args.AppendElement(authInfo); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
155 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
156 // |result| is how the dialog passes information back to us. It sets two |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
157 // properties on the object: |proceed|, which we return from this function, |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
158 // and which determines whether or not authentication can proceed using |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
159 // the values entered by the user; and |remember|, which determines whether |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
160 // or not we save the user's login with the login manager once the request |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
161 // succeeds. |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
162 let result = {}; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
163 args.AppendElement({ wrappedJSObject: result }); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
164 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
165 let ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].getService(Ci.nsIWindowWatcher); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
166 ww.openWindow(null, |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
167 "chrome://snowl/content/login.xul", |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
168 null, |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
169 "chrome,centerscreen,dialog,modal", |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
170 args); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
171 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
172 if (result.remember) |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
173 this._authInfo = authInfo; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
174 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
175 return result.proceed; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
176 }, |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
177 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
178 asyncPromptAuth: function() { |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
179 throw Cr.NS_ERROR_NOT_IMPLEMENTED; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
180 }, |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
181 |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
182 |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
183 //**************************************************************************// |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
184 // Subscription |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
185 |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
186 subscribe: function(credentials) { |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
187 Observers.notify(this, "snowl:subscribe:connect:start", null); |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
188 |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
189 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
190 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
191 request.QueryInterface(Ci.nsIDOMEventTarget); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
192 let t = this; |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
193 request.addEventListener("load", function(e) { t.onSubscribeLoad(e) }, false); |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
194 request.addEventListener("error", function(e) { t.onSubscribeError(e) }, false); |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
195 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
196 request.QueryInterface(Ci.nsIXMLHttpRequest); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
197 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
198 request.open("GET", this.machineURI.spec + "/account/verify_credentials.json", true); |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
199 |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
200 // We could just set the Authorization request header here, but then |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
201 // we wouldn't get an nsIAuthInformation object through our notification |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
202 // callbacks, so we'd have to parse the WWW-Authenticate header ourselves |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
203 // to extract the realm to use when saving the credentials to the login |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
204 // manager, and WWW-Authenticate header parsing is said to be tricky. |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
205 |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
206 // So instead we define notification callbacks that fill in (and persist) |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
207 // an nsIAuthInformation object the first time they are called (subsequent |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
208 // attempts fail, though, to avoid an infinite loop with a server that keeps |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
209 // rejecting our credentials along with a Mozilla that keeps prompting |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
210 // for them). |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
211 request.channel.notificationCallbacks = { |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
212 QueryInterface: XPCOMUtils.generateQI([Ci.nsIAuthPrompt2]), |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
213 getInterface: function(iid) { return this.QueryInterface(iid) }, |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
214 _firstAttempt: true, |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
215 promptAuth: function(channel, level, authInfo) { |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
216 if (!this._firstAttempt) { |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
217 if (credentials.remember) |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
218 this._authInfo = null; |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
219 return false; |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
220 } |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
221 authInfo.username = credentials.username; |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
222 authInfo.password = credentials.password; |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
223 if (credentials.remember) |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
224 this._authInfo = authInfo; |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
225 this._firstAttempt = false; |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
226 return true; |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
227 }, |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
228 asyncPromptAuth: function() { throw Cr.NS_ERROR_NOT_IMPLEMENTED } |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
229 }; |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
230 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
231 request.send(null); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
232 }, |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
233 |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
234 onSubscribeLoad: function(event) { |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
235 let request = event.target; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
236 |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
237 // request.responseText should be: {"authorized":true} |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
238 this._log.info("onSubscribeLoad: " + request.responseText); |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
239 |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
240 // If the request failed, let the error handler handle it. |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
241 // XXX Do we need this? Don't such failures call the error handler directly? |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
242 if (request.status < 200 || request.status > 299) { |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
243 this.onSubscribeError(event); |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
244 return; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
245 } |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
246 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
247 // XXX What's the right way to handle this? |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
248 if (request.responseText.length == 0) { |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
249 this.onSubscribeError(event); |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
250 return; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
251 } |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
252 |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
253 Observers.notify(this, "snowl:subscribe:connect:end", request.status); |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
254 |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
255 // _authInfo only gets set if we prompted the user to authenticate |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
256 // and the user checked the "remember password" box. Since we're here, |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
257 // it means the request succeeded, so we save the login. |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
258 if (this._authInfo) |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
259 this._saveLogin(); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
260 |
205 | 261 // Save the source to the database. |
262 this.persist(); | |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
263 |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
264 // Let observers know about the new source. |
358
c00b3db58dcf
add 'snowl' to all observer topics to avoid conflicts with other extensions/core code; use the Observers component everywhere
Myk Melez <myk@mozilla.org>
parents:
357
diff
changeset
|
265 Observers.notify(null, "snowl:sources:changed", null); |
205 | 266 |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
267 this.refresh(); |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
268 }, |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
269 |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
270 onSubscribeError: function(event) { |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
271 let request = event.target; |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
272 |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
273 // request.responseText should be: Could not authenticate you. |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
274 this._log.info("onSubscribeError: " + request.responseText); |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
275 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
276 // Sometimes an attempt to retrieve status text throws NS_ERROR_NOT_AVAILABLE. |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
277 let statusText = ""; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
278 try { |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
279 statusText = request.statusText; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
280 } |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
281 catch(ex) {} |
239
2116e44e4c17
Added a simple, tentative source type registration API to SnowlService. Rather than coupling SnowlService to specific source types by importing their JS modules in service.js, we now have the source types register with SnowlService upon import by calling a new method, SnowlService.addSourceType(). This makes it easy for third parties to add new source types without having to modify Snowl's source code.
Atul Varma <varmaa@toolness.com>
parents:
229
diff
changeset
|
282 |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
283 this._log.error("onSubscribeError: " + request.status + " (" + statusText + ")"); |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
284 |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
285 Observers.notify(this, "snowl:subscribe:connect:end", request.status); |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
286 }, |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
287 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
288 |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
289 //**************************************************************************// |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
290 // Refreshment |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
291 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
292 refresh: function() { |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
293 Observers.notify(this, "snowl:subscribe:get:start", null); |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
294 |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
295 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
296 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
297 request.QueryInterface(Ci.nsIDOMEventTarget); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
298 let t = this; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
299 request.addEventListener("load", function(e) { t.onRefreshLoad(e) }, false); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
300 request.addEventListener("error", function(e) { t.onRefreshError(e) }, false); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
301 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
302 request.QueryInterface(Ci.nsIXMLHttpRequest); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
303 |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
304 // FIXME: use the count parameter to retrieve more messages at once. |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
305 // FIXME: use the since or since_id parameter to retrieve only new messages. |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
306 // http://groups.google.com/group/twitter-development-talk/web/api-documentation |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
307 request.open("GET", this.machineURI.spec + "/statuses/friends_timeline.json", true); |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
308 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
309 // Register a listener for notification callbacks so we handle authentication. |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
310 request.channel.notificationCallbacks = this; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
311 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
312 request.send(null); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
313 }, |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
314 |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
315 onRefreshLoad: function(event) { |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
316 let request = event.target; |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
317 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
318 // If the request failed, let the error handler handle it. |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
319 // XXX Do we need this? Don't such failures call the error handler directly? |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
320 if (request.status < 200 || request.status > 299) { |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
321 this.onRefreshError(event); |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
322 return; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
323 } |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
324 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
325 // XXX What's the right way to handle this? |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
326 if (request.responseText.length == 0) { |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
327 this.onRefreshError(event); |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
328 return; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
329 } |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
330 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
331 // _authInfo only gets set if we prompted the user to authenticate |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
332 // and the user checked the "remember password" box. Since we're here, |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
333 // it means the request succeeded, so we save the login. |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
334 if (this._authInfo) |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
335 this._saveLogin(); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
336 |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
337 this._processRefresh(request.responseText); |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
338 }, |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
339 |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
340 onRefreshError: function(event) { |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
341 let request = event.target; |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
342 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
343 // Sometimes an attempt to retrieve status text throws NS_ERROR_NOT_AVAILABLE |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
344 let statusText = ""; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
345 try { |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
346 statusText = request.statusText; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
347 } |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
348 catch(ex) {} |
239
2116e44e4c17
Added a simple, tentative source type registration API to SnowlService. Rather than coupling SnowlService to specific source types by importing their JS modules in service.js, we now have the source types register with SnowlService upon import by calling a new method, SnowlService.addSourceType(). This makes it easy for third parties to add new source types without having to modify Snowl's source code.
Atul Varma <varmaa@toolness.com>
parents:
229
diff
changeset
|
349 |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
350 this._log.error("onRefreshError: " + request.status + " (" + statusText + ")"); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
351 }, |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
352 |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
353 _processRefresh: function(responseText) { |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
354 // Now that we know we successfully downloaded the source and obtained |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
355 // a result from it, update the "last refreshed" timestamp. |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
356 this.lastRefreshed = new Date(); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
357 |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
358 var JSON = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON); |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
359 let messages = JSON.decode(responseText); |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
360 |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
361 let currentMessages = []; |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
362 let messagesChanged = false; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
363 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
364 SnowlDatastore.dbConnection.beginTransaction(); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
365 try { |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
366 for each (let message in messages) { |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
367 let externalID = message.id; |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
368 let internalID = this._getInternalIDForExternalID(externalID); |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
369 if (internalID) { |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
370 currentMessages.push(internalID); |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
371 continue; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
372 } |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
373 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
374 messagesChanged = true; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
375 this._log.info(this.name + " adding message " + externalID); |
260
f88055405aee
make all messages received in the same refresh have the same received datetime, and support multiple sort properties when sorting a collection
Myk Melez <myk@mozilla.org>
parents:
256
diff
changeset
|
376 internalID = this._addMessage(message, this.lastRefreshed); |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
377 currentMessages.push(internalID); |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
378 } |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
379 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
380 // Update the current flag. |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
381 // XXX Should this affect whether or not messages have changed? |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
382 SnowlDatastore.dbConnection.executeSimpleSQL("UPDATE messages SET current = 0 WHERE sourceID = " + this.id); |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
383 SnowlDatastore.dbConnection.executeSimpleSQL("UPDATE messages SET current = 1 WHERE id IN (" + currentMessages.join(", ") + ")"); |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
384 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
385 SnowlDatastore.dbConnection.commitTransaction(); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
386 } |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
387 catch(ex) { |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
388 SnowlDatastore.dbConnection.rollbackTransaction(); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
389 throw ex; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
390 } |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
391 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
392 if (messagesChanged) |
358
c00b3db58dcf
add 'snowl' to all observer topics to avoid conflicts with other extensions/core code; use the Observers component everywhere
Myk Melez <myk@mozilla.org>
parents:
357
diff
changeset
|
393 Observers.notify(null, "snowl:messages:changed", null); |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
394 |
205 | 395 // FIXME: if we added people, refresh the collections view too. |
396 | |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
397 Observers.notify(this, "snowl:subscribe:get:end", null); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
398 }, |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
399 |
260
f88055405aee
make all messages received in the same refresh have the same received datetime, and support multiple sort properties when sorting a collection
Myk Melez <myk@mozilla.org>
parents:
256
diff
changeset
|
400 _addMessage: function(message, aReceived) { |
208
d507cc4374c7
store twitter message content as the subject of the message so it shows up in the list view
Myk Melez <myk@mozilla.org>
parents:
205
diff
changeset
|
401 // We store the message text as both the subject and the content so that |
d507cc4374c7
store twitter message content as the subject of the message so it shows up in the list view
Myk Melez <myk@mozilla.org>
parents:
205
diff
changeset
|
402 // the content shows up in the Subject column of the list view. |
d507cc4374c7
store twitter message content as the subject of the message so it shows up in the list view
Myk Melez <myk@mozilla.org>
parents:
205
diff
changeset
|
403 // FIXME: make the list view automatically display some of the content |
d507cc4374c7
store twitter message content as the subject of the message so it shows up in the list view
Myk Melez <myk@mozilla.org>
parents:
205
diff
changeset
|
404 // if the subject is missing so we don't have to duplicate storage here. |
d507cc4374c7
store twitter message content as the subject of the message so it shows up in the list view
Myk Melez <myk@mozilla.org>
parents:
205
diff
changeset
|
405 let subject = message.text; |
d507cc4374c7
store twitter message content as the subject of the message so it shows up in the list view
Myk Melez <myk@mozilla.org>
parents:
205
diff
changeset
|
406 |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
407 // Get an existing identity or create a new one. Creating an identity |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
408 // automatically creates a person record with the provided name. |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
409 let identity = SnowlIdentity.get(this.id, message.user.id) || |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
410 SnowlIdentity.create(this.id, |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
411 message.user.id, |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
412 message.user.screen_name, |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
413 message.user.url, |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
414 message.user.profile_image_url); |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
415 // FIXME: update the identity record with the latest info about the person. |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
416 //identity.updateProperties(this.machineURI, message.user); |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
417 let authorID = identity.personID; |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
418 |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
419 let timestamp = new Date(message.created_at); |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
420 |
208
d507cc4374c7
store twitter message content as the subject of the message so it shows up in the list view
Myk Melez <myk@mozilla.org>
parents:
205
diff
changeset
|
421 // Add the message. |
260
f88055405aee
make all messages received in the same refresh have the same received datetime, and support multiple sort properties when sorting a collection
Myk Melez <myk@mozilla.org>
parents:
256
diff
changeset
|
422 let messageID = this.addSimpleMessage(this.id, message.id, subject, authorID, timestamp, aReceived, null); |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
423 |
208
d507cc4374c7
store twitter message content as the subject of the message so it shows up in the list view
Myk Melez <myk@mozilla.org>
parents:
205
diff
changeset
|
424 // Add the message's content. |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
425 this.addPart(messageID, PART_TYPE_CONTENT, message.text, null, null, "text/plain"); |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
426 |
208
d507cc4374c7
store twitter message content as the subject of the message so it shows up in the list view
Myk Melez <myk@mozilla.org>
parents:
205
diff
changeset
|
427 // Add the message's metadata. |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
428 for (let [name, value] in Iterator(message)) { |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
429 // Ignore properties we have already handled specially. |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
430 // XXX Should we add them anyway, which is redundant info but lets others |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
431 // (who don't know about our special treatment) access them? |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
432 if (["user", "created_at", "text"].indexOf(name) != -1) |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
433 continue; |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
434 |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
435 // FIXME: populate a "recipient" field with in_reply_to_user_id. |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
436 |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
437 this._addMetadatum(messageID, name, value); |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
438 } |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
439 |
282
76ee747a1dba
add messages progressively to the stream view rather than rebuilding the view each time
Myk Melez <myk@mozilla.org>
parents:
260
diff
changeset
|
440 Observers.notify(SnowlMessage.get(messageID), "snowl:message:added", null); |
76ee747a1dba
add messages progressively to the stream view rather than rebuilding the view each time
Myk Melez <myk@mozilla.org>
parents:
260
diff
changeset
|
441 |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
442 return messageID; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
443 }, |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
444 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
445 // FIXME: Make the rest of this stuff be part of a superclass from which |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
446 // this class is derived. |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
447 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
448 /** |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
449 * Get the internal ID of the message with the given external ID. |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
450 * |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
451 * @param aExternalID {string} |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
452 * the external ID of the message |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
453 * |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
454 * @returns {number} |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
455 * the internal ID of the message, or undefined if the message |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
456 * doesn't exist |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
457 */ |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
458 _getInternalIDForExternalID: function(aExternalID) { |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
459 // FIXME: external IDs may be source-specific, as some sources |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
460 // (like Twitter) don't use globally-unique IDs (unlike feeds, which |
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
461 // generally do), so handle non-globally unique IDs correctly. |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
462 return SnowlDatastore.selectInternalIDForExternalID(aExternalID); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
463 }, |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
464 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
465 /** |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
466 * Add a message with a single part to the datastore. |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
467 * |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
468 * @param aSourceID {integer} the record ID of the message source |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
469 * @param aExternalID {string} the external ID of the message |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
470 * @param aSubject {string} the title of the message |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
471 * @param aAuthorID {string} the author of the message |
260
f88055405aee
make all messages received in the same refresh have the same received datetime, and support multiple sort properties when sorting a collection
Myk Melez <myk@mozilla.org>
parents:
256
diff
changeset
|
472 * @param aTimestamp {Date} the date/time when the message was sent |
f88055405aee
make all messages received in the same refresh have the same received datetime, and support multiple sort properties when sorting a collection
Myk Melez <myk@mozilla.org>
parents:
256
diff
changeset
|
473 * @param aReceived {Date} the date/time when the message was received |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
474 * @param aLink {nsIURI} a link to the content of the message, |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
475 * if the content is hosted on a server |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
476 * |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
477 * @returns {integer} the internal ID of the newly-created message |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
478 */ |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
479 addSimpleMessage: function(aSourceID, aExternalID, aSubject, aAuthorID, |
260
f88055405aee
make all messages received in the same refresh have the same received datetime, and support multiple sort properties when sorting a collection
Myk Melez <myk@mozilla.org>
parents:
256
diff
changeset
|
480 aTimestamp, aReceived, aLink) { |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
481 let messageID = |
287
113312a23f53
use julian dates for the lastRefreshed values, push date conversion up the stack (away from the core database access routines), and make the datastore code migrate from a version 4 to a version 5 schema (storing julian instead of JS dates)
Myk Melez <myk@mozilla.org>
parents:
283
diff
changeset
|
482 SnowlDatastore.insertMessage(aSourceID, |
113312a23f53
use julian dates for the lastRefreshed values, push date conversion up the stack (away from the core database access routines), and make the datastore code migrate from a version 4 to a version 5 schema (storing julian instead of JS dates)
Myk Melez <myk@mozilla.org>
parents:
283
diff
changeset
|
483 aExternalID, |
113312a23f53
use julian dates for the lastRefreshed values, push date conversion up the stack (away from the core database access routines), and make the datastore code migrate from a version 4 to a version 5 schema (storing julian instead of JS dates)
Myk Melez <myk@mozilla.org>
parents:
283
diff
changeset
|
484 aSubject, |
113312a23f53
use julian dates for the lastRefreshed values, push date conversion up the stack (away from the core database access routines), and make the datastore code migrate from a version 4 to a version 5 schema (storing julian instead of JS dates)
Myk Melez <myk@mozilla.org>
parents:
283
diff
changeset
|
485 aAuthorID, |
355
e9d7087abad1
implement tree (list and collection) contextmenu foundation, change XXX Utils to DateUtils, some click handling fixes.
alta88
parents:
330
diff
changeset
|
486 SnowlDateUtils.jsToJulianDate(aTimestamp), |
e9d7087abad1
implement tree (list and collection) contextmenu foundation, change XXX Utils to DateUtils, some click handling fixes.
alta88
parents:
330
diff
changeset
|
487 SnowlDateUtils.jsToJulianDate(aReceived), |
287
113312a23f53
use julian dates for the lastRefreshed values, push date conversion up the stack (away from the core database access routines), and make the datastore code migrate from a version 4 to a version 5 schema (storing julian instead of JS dates)
Myk Melez <myk@mozilla.org>
parents:
283
diff
changeset
|
488 aLink ? aLink.spec : null); |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
489 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
490 return messageID; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
491 }, |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
492 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
493 get _addPartStatement() { |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
494 let statement = SnowlDatastore.createStatement( |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
495 "INSERT INTO parts(messageID, partType, content, baseURI, languageCode, mediaType) \ |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
496 VALUES (:messageID, :partType, :content, :baseURI, :languageCode, :mediaType)" |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
497 ); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
498 this.__defineGetter__("_addPartStatement", function() { return statement }); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
499 return this._addPartStatement; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
500 }, |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
501 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
502 addPart: function(aMessageID, aPartType, aContent, aBaseURI, aLanguageCode, |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
503 aMediaType) { |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
504 this._addPartStatement.params.messageID = aMessageID; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
505 this._addPartStatement.params.partType = aPartType; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
506 this._addPartStatement.params.content = aContent; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
507 this._addPartStatement.params.baseURI = aBaseURI; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
508 this._addPartStatement.params.languageCode = aLanguageCode; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
509 this._addPartStatement.params.mediaType = aMediaType; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
510 this._addPartStatement.execute(); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
511 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
512 return SnowlDatastore.dbConnection.lastInsertRowID; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
513 }, |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
514 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
515 _addMetadatum: function(aMessageID, aAttributeName, aValue) { |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
516 // FIXME: speed this up by caching the list of known attributes. |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
517 let attributeID = SnowlDatastore.selectAttributeID(aAttributeName) |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
518 || SnowlDatastore.insertAttribute(aAttributeName); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
519 SnowlDatastore.insertMetadatum(aMessageID, attributeID, aValue); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
520 }, |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
521 |
193
b5033574560f
basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents:
190
diff
changeset
|
522 // FIXME: factor this out with the identical function in feed.js. |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
523 _saveLogin: function() { |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
524 let lm = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
525 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
526 // Create a new login with the auth information we obtained from the user. |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
527 let LoginInfo = new Components.Constructor("@mozilla.org/login-manager/loginInfo;1", |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
528 Ci.nsILoginInfo, |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
529 "init"); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
530 // XXX Should we be using channel.URI.prePath in case the old URI |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
531 // redirects us to a new one at a different hostname? |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
532 let newLogin = new LoginInfo(this.machineURI.prePath, |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
533 null, |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
534 this._authInfo.realm, |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
535 this._authInfo.username, |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
536 this._authInfo.password, |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
537 "", |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
538 ""); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
539 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
540 // Get existing logins that have the same hostname and realm. |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
541 let logins = lm.findLogins({}, this.machineURI.prePath, null, this._authInfo.realm); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
542 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
543 // Try to figure out if we should replace one of the existing logins. |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
544 // If there's only one existing login, we replace it. Otherwise, if |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
545 // there's a login with the same username, we replace that. Otherwise, |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
546 // we add the new login instead of replacing an existing one. |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
547 let oldLogin; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
548 if (logins.length == 1) |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
549 oldLogin = logins[0]; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
550 else if (logins.length > 1) |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
551 oldLogin = logins.filter(function(v) v.username == this._authInfo.username)[0]; |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
552 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
553 if (oldLogin) |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
554 lm.modifyLogin(oldLogin, newLogin); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
555 else |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
556 lm.addLogin(newLogin); |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
557 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
558 // Now that we've saved the login, we don't need the auth info anymore. |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
559 this._authInfo = null; |
359
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
560 }, |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
561 |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
562 |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
563 //**************************************************************************// |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
564 // Sending |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
565 |
364
48d21192fe85
add a message length counter so users know when they've typed too much for targets that don't allow more than a certain number of characters to be sent to them
Myk Melez <myk@mozilla.org>
parents:
362
diff
changeset
|
566 maxMessageLength: 140, |
48d21192fe85
add a message length counter so users know when they've typed too much for targets that don't allow more than a certain number of characters to be sent to them
Myk Melez <myk@mozilla.org>
parents:
362
diff
changeset
|
567 |
362
fffaeb8f1950
give the user feedback about the send while it is occurring
Myk Melez <myk@mozilla.org>
parents:
361
diff
changeset
|
568 _sendCallback: null, |
fffaeb8f1950
give the user feedback about the send while it is occurring
Myk Melez <myk@mozilla.org>
parents:
361
diff
changeset
|
569 |
fffaeb8f1950
give the user feedback about the send while it is occurring
Myk Melez <myk@mozilla.org>
parents:
361
diff
changeset
|
570 send: function(content, callback) { |
359
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
571 Observers.notify(this, "snowl:send:start", null); |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
572 |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
573 let data = "status=" + encodeURIComponent(content); |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
574 // + "&in_reply_to_status_id=" + encodeURIComponent(inReplyToID); |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
575 |
362
fffaeb8f1950
give the user feedback about the send while it is occurring
Myk Melez <myk@mozilla.org>
parents:
361
diff
changeset
|
576 this._sendCallback = callback; |
fffaeb8f1950
give the user feedback about the send while it is occurring
Myk Melez <myk@mozilla.org>
parents:
361
diff
changeset
|
577 |
359
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
578 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(); |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
579 |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
580 request.QueryInterface(Ci.nsIDOMEventTarget); |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
581 let (t = this) { |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
582 request.addEventListener("load", function(e) { t.onSendLoad(e) }, false); |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
583 request.addEventListener("error", function(e) { t.onSendError(e) }, false); |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
584 } |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
585 |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
586 request.QueryInterface(Ci.nsIXMLHttpRequest); |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
587 request.open("POST", this.machineURI.spec + "/statuses/update.json", true); |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
588 request.channel.notificationCallbacks = this; |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
589 request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
590 request.send(data); |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
591 }, |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
592 |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
593 onSendLoad: function(event) { |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
594 let request = event.target; |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
595 |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
596 // FIXME: the next three chunks of code are the same for multiple |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
597 // load handlers; find some way to factor them out. |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
598 |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
599 // If the request failed, let the error handler handle it. |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
600 // XXX Do we need this? Don't such failures call the error handler directly? |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
601 if (request.status < 200 || request.status > 299) { |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
602 this.onSendError(event); |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
603 return; |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
604 } |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
605 |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
606 // If the response is empty, assume failure. |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
607 // XXX What's the right way to handle this? |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
608 if (request.responseText.length == 0) { |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
609 this.onSendError(event); |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
610 return; |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
611 } |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
612 |
362
fffaeb8f1950
give the user feedback about the send while it is occurring
Myk Melez <myk@mozilla.org>
parents:
361
diff
changeset
|
613 if (this._sendCallback) { |
fffaeb8f1950
give the user feedback about the send while it is occurring
Myk Melez <myk@mozilla.org>
parents:
361
diff
changeset
|
614 this._sendCallback(); |
fffaeb8f1950
give the user feedback about the send while it is occurring
Myk Melez <myk@mozilla.org>
parents:
361
diff
changeset
|
615 this._sendCallback = null; |
fffaeb8f1950
give the user feedback about the send while it is occurring
Myk Melez <myk@mozilla.org>
parents:
361
diff
changeset
|
616 } |
fffaeb8f1950
give the user feedback about the send while it is occurring
Myk Melez <myk@mozilla.org>
parents:
361
diff
changeset
|
617 |
fffaeb8f1950
give the user feedback about the send while it is occurring
Myk Melez <myk@mozilla.org>
parents:
361
diff
changeset
|
618 this._log.info("onSendLoad: " + request.responseText); |
fffaeb8f1950
give the user feedback about the send while it is occurring
Myk Melez <myk@mozilla.org>
parents:
361
diff
changeset
|
619 |
359
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
620 // _authInfo only gets set if we prompted the user to authenticate |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
621 // and the user checked the "remember password" box. Since we're here, |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
622 // it means the request succeeded, so we save the login. |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
623 if (this._authInfo) |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
624 this._saveLogin(); |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
625 |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
626 this._processSend(request.responseText); |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
627 }, |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
628 |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
629 onSendError: function(event) { |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
630 let request = event.target; |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
631 |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
632 // Sometimes an attempt to retrieve status text throws NS_ERROR_NOT_AVAILABLE |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
633 let statusText = ""; |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
634 try { |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
635 statusText = request.statusText; |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
636 } |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
637 catch(ex) {} |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
638 |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
639 this._log.error("onSendError: " + request.status + " (" + statusText + ")"); |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
640 }, |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
641 |
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
642 _processSend: function(responseText) { |
361
edb03b1ae143
add the sent message to the database once it has been sent
Myk Melez <myk@mozilla.org>
parents:
359
diff
changeset
|
643 let JSON = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON); |
359
57bbbcb76b0b
initial implementationi of writing; stream view only, still pretty hacky
Myk Melez <myk@mozilla.org>
parents:
358
diff
changeset
|
644 let response = JSON.decode(responseText); |
361
edb03b1ae143
add the sent message to the database once it has been sent
Myk Melez <myk@mozilla.org>
parents:
359
diff
changeset
|
645 this._addMessage(response, new Date()); |
190
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
646 } |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
647 |
8e61b480af10
make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
648 }; |
239
2116e44e4c17
Added a simple, tentative source type registration API to SnowlService. Rather than coupling SnowlService to specific source types by importing their JS modules in service.js, we now have the source types register with SnowlService upon import by calling a new method, SnowlService.addSourceType(). This makes it easy for third parties to add new source types without having to modify Snowl's source code.
Atul Varma <varmaa@toolness.com>
parents:
229
diff
changeset
|
649 |
380
6916b17a0536
Automated merge with http://hg.toolness.com/snowl/
Myk Melez <myk@mozilla.org>
parents:
364
diff
changeset
|
650 SnowlService.addAccountType(SnowlTwitter); |