annotate modules/twitter.js @ 283:ae23e6f323db

refresh twitter every three minutes
author Myk Melez <myk@mozilla.org>
date Mon, 01 Sep 2008 20:15:33 -0700
parents 76ee747a1dba
children 113312a23f53
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
ce534ed8a39e make refreshing twitter work
Myk Melez <myk@mozilla.org>
parents: 193
diff changeset
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
8e61b480af10 make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff changeset
48 // modules that should 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
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
8e61b480af10 make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff changeset
53 // Snowl-specific modules
8e61b480af10 make 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");
8e61b480af10 make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff changeset
56 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
57 Cu.import("resource://snowl/modules/message.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
58
193
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
59 // FIXME: factor this out into a common file.
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
60 const PART_TYPE_CONTENT = 1;
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
61 const PART_TYPE_SUMMARY = 2;
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
62
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
63 const NAME = "Twitter";
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
64 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
65 // XXX Should this be simply http://twitter.com ?
193
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
66 const HUMAN_URI = URI.get("http://twitter.com/home");
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
67
283
ae23e6f323db refresh twitter every three minutes
Myk Melez <myk@mozilla.org>
parents: 282
diff changeset
68 function SnowlTwitter(aID, aName, aMachineURI, aHumanURI, aLastRefreshed, aImportance) {
193
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
69 // 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
70 // to subscribe to multiple Twitter accounts?
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
71
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
72 // Call the superclass's constructor to initialize the new instance.
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);
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
74 }
8e61b480af10 make 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 SnowlTwitter.prototype = {
283
ae23e6f323db refresh twitter every three minutes
Myk Melez <myk@mozilla.org>
parents: 282
diff changeset
77 // How often to refresh sources, in milliseconds.
ae23e6f323db refresh twitter every three minutes
Myk Melez <myk@mozilla.org>
parents: 282
diff changeset
78 refreshInterval: 1000 * 60 * 3, // 30 minutes
ae23e6f323db refresh twitter every three minutes
Myk Melez <myk@mozilla.org>
parents: 282
diff changeset
79
205
ce534ed8a39e make refreshing twitter work
Myk Melez <myk@mozilla.org>
parents: 193
diff changeset
80 constructor: SnowlTwitter,
ce534ed8a39e make refreshing twitter work
Myk Melez <myk@mozilla.org>
parents: 193
diff changeset
81
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
82 __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
83
8e61b480af10 make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff changeset
84 _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
85
8e61b480af10 make 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 // Observer Service
8e61b480af10 make 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 get _obsSvc() {
8e61b480af10 make 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 let obsSvc = Cc["@mozilla.org/observer-service;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
89 getService(Ci.nsIObserverService);
8e61b480af10 make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff changeset
90 this.__defineGetter__("_obsSvc", function() { return obsSvc });
8e61b480af10 make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff changeset
91 return this._obsSvc;
8e61b480af10 make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff changeset
92 },
8e61b480af10 make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff changeset
93
193
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
94
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
95 //**************************************************************************//
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
96 // Notification Callbacks for Authentication
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
97
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
98 // 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
99
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
100 // 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
101 // 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
102 // 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
103 _authInfo: null,
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
104
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
105 // 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
106 // or one of them works.
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
107 // 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
108 // 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
109 // 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
110 _logins: null,
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
111 _loginIndex: 0,
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
112
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
113 // 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
114
8e61b480af10 make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff changeset
115 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
116
8e61b480af10 make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff changeset
117 // 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
118
8e61b480af10 make 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 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
120 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
121 },
8e61b480af10 make 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 // 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
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 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
126 // 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
127 // 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
128 // 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
129 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
130 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
131 // 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
132 // 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
133 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
134 }
8e61b480af10 make 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
8e61b480af10 make 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 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
137 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
138 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
139 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
140 ++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
141 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
142 }
8e61b480af10 make 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
8e61b480af10 make 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 // 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
145 // 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
146 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
147 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
148 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
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 // |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
151 // 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
152 // 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
153 // 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
154 // 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
155 // 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
156 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
157 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
158
8e61b480af10 make 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 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
160 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
161 "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
162 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
163 "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
164 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
165
8e61b480af10 make 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 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
167 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
168
8e61b480af10 make 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 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
170 },
8e61b480af10 make 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 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
173 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
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
193
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
176
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
177 //**************************************************************************//
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
178 // Subscription
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
179
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
180 subscribe: function(credentials) {
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
181 Observers.notify(this, "snowl:subscribe:connect:start", null);
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
182
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
183 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
184
8e61b480af10 make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff changeset
185 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
186 let t = this;
193
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
187 request.addEventListener("load", function(e) { t.onSubscribeLoad(e) }, false);
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
188 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
189
8e61b480af10 make 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 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
191
8e61b480af10 make 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 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
193
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
194 // 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
195 // 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
196 // 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
197 // 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
198 // 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
199
193
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
200 // 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
201 // 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
202 // 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
203 // 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
204 // for them).
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
205 request.channel.notificationCallbacks = {
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
206 QueryInterface: XPCOMUtils.generateQI([Ci.nsIAuthPrompt2]),
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
207 getInterface: function(iid) { return this.QueryInterface(iid) },
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
208 _firstAttempt: true,
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
209 promptAuth: function(channel, level, authInfo) {
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
210 if (!this._firstAttempt) {
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
211 if (credentials.remember)
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
212 this._authInfo = null;
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
213 return false;
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
214 }
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
215 authInfo.username = credentials.username;
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
216 authInfo.password = credentials.password;
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 = authInfo;
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
219 this._firstAttempt = false;
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
220 return true;
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
221 },
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
222 asyncPromptAuth: function() { throw Cr.NS_ERROR_NOT_IMPLEMENTED }
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
223 };
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
224
8e61b480af10 make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff changeset
225 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
226 },
8e61b480af10 make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff changeset
227
193
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
228 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
229 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
230
193
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
231 // request.responseText should be: {"authorized":true}
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
232 this._log.info("onSubscribeLoad: " + request.responseText);
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
233
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
234 // 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
235 // 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
236 if (request.status < 200 || request.status > 299) {
193
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
237 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
238 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
239 }
8e61b480af10 make 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
8e61b480af10 make 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 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
242 if (request.responseText.length == 0) {
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
193
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
247 Observers.notify(this, "snowl:subscribe:connect:end", request.status);
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
248
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
249 // _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
250 // 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
251 // 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
252 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
253 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
254
205
ce534ed8a39e make refreshing twitter work
Myk Melez <myk@mozilla.org>
parents: 193
diff changeset
255 // Save the source to the database.
ce534ed8a39e make refreshing twitter work
Myk Melez <myk@mozilla.org>
parents: 193
diff changeset
256 this.persist();
193
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
257
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
258 // Let observers know about the new source.
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
259 this._obsSvc.notifyObservers(null, "sources:changed", null);
205
ce534ed8a39e make refreshing twitter work
Myk Melez <myk@mozilla.org>
parents: 193
diff changeset
260
193
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
261 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
262 },
8e61b480af10 make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff changeset
263
193
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
264 onSubscribeError: function(event) {
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
265 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
266
193
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
267 // request.responseText should be: Could not authenticate you.
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
268 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
269
8e61b480af10 make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff changeset
270 // 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
271 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
272 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
273 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
274 }
8e61b480af10 make 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 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
276
193
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
277 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
278
193
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
279 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
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
8e61b480af10 make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff changeset
282
193
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
283 //**************************************************************************//
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
284 // 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
285
8e61b480af10 make 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 refresh: function() {
193
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
287 Observers.notify(this, "snowl:subscribe:get:start", null);
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
288
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
289 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
290
8e61b480af10 make 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 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
292 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
293 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
294 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
295
8e61b480af10 make 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 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
297
193
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
298 // 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
299 // 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
300 // 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
301 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
302
8e61b480af10 make 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 // 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
304 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
305
8e61b480af10 make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff changeset
306 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
307 },
8e61b480af10 make 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
193
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
309 onRefreshLoad: function(event) {
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
310 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
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 // 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
313 // 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
314 if (request.status < 200 || request.status > 299) {
193
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
315 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
316 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
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
8e61b480af10 make 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 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
320 if (request.responseText.length == 0) {
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 // _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
326 // 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
327 // 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
328 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
329 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
330
193
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
331 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
332 },
8e61b480af10 make 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
193
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
334 onRefreshError: function(event) {
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
335 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
336
8e61b480af10 make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff changeset
337 // 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
338 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
339 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
340 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
341 }
8e61b480af10 make 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 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
343
8e61b480af10 make 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 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
345 },
8e61b480af10 make 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
193
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
347 _processRefresh: function(responseText) {
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
348 // 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
349 // 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
350 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
351
193
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
352 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
353 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
354
193
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
355 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
356 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
357
8e61b480af10 make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff changeset
358 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
359 try {
193
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
360 for each (let message in messages) {
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
361 let externalID = message.id;
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
362 let internalID = this._getInternalIDForExternalID(externalID);
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
363 if (internalID) {
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
364 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
365 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
366 }
8e61b480af10 make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff changeset
367
8e61b480af10 make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff changeset
368 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
369 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
370 internalID = this._addMessage(message, this.lastRefreshed);
193
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
371 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
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 // 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
375 // 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
376 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
377 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
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 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
380 }
8e61b480af10 make 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 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
382 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
383 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
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
8e61b480af10 make 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 if (messagesChanged)
8e61b480af10 make 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 this._obsSvc.notifyObservers(null, "messages:changed", 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
388
205
ce534ed8a39e make refreshing twitter work
Myk Melez <myk@mozilla.org>
parents: 193
diff changeset
389 // FIXME: if we added people, refresh the collections view too.
ce534ed8a39e make refreshing twitter work
Myk Melez <myk@mozilla.org>
parents: 193
diff changeset
390
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
391 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
392 },
8e61b480af10 make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff changeset
393
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
394 _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
395 // 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
396 // 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
397 // 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
398 // 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
399 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
400
193
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
401 // 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
402 // automatically creates a person record with the provided name.
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
403 let identity = SnowlIdentity.get(this.id, message.user.id) ||
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
404 SnowlIdentity.create(this.id,
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
405 message.user.id,
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
406 message.user.screen_name,
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
407 message.user.url,
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
408 message.user.profile_image_url);
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
409 // 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
410 //identity.updateProperties(this.machineURI, message.user);
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
411 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
412
193
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
413 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
414
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
415 // 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
416 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
417
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
418 // Add the message's content.
193
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
419 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
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's metadata.
193
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
422 for (let [name, value] in Iterator(message)) {
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
423 // Ignore properties we have already handled specially.
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
424 // 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
425 // (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
426 if (["user", "created_at", "text"].indexOf(name) != -1)
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
427 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
428
193
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
429 // 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
430
193
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
431 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
432 }
8e61b480af10 make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff changeset
433
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
434 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
435
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 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
437 },
8e61b480af10 make 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 // 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
440 // 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
441
8e61b480af10 make 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 /**
8e61b480af10 make 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 * 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
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 * @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
446 * 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
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 * @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
449 * 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
450 * 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
451 */
8e61b480af10 make 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 _getInternalIDForExternalID: function(aExternalID) {
193
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
453 // 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
454 // (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
455 // 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
456 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
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
8e61b480af10 make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff changeset
459 /**
8e61b480af10 make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff changeset
460 * 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
461 *
8e61b480af10 make 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 * @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
463 * @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
464 * @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
465 * @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
466 * @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
467 * @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
468 * @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
469 * 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
470 *
8e61b480af10 make 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 * @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
472 */
8e61b480af10 make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff changeset
473 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
474 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
475 // Convert the link to its string spec, which is how we store 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
476 // in 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
477 let link = aLink ? aLink.spec : 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
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 let 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
480 SnowlDatastore.insertMessage(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
481 aTimestamp, aReceived, link);
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
482
8e61b480af10 make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff changeset
483 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
484 },
8e61b480af10 make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff changeset
485
8e61b480af10 make the subscribe dialog more generic, and add the beginnings of Twitter support (doesn't work yet)
Myk Melez <myk@mozilla.org>
parents:
diff changeset
486 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
487 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
488 "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
489 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
490 );
8e61b480af10 make 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 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
492 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
493 },
8e61b480af10 make 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
8e61b480af10 make 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 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
496 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
497 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
498 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
499 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
500 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
501 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
502 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
503 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
504
8e61b480af10 make 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 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
506 },
8e61b480af10 make 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
8e61b480af10 make 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 _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
509 // 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
510 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
511 || 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
512 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
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
193
b5033574560f basic, primitive, primordial twitter support
Myk Melez <myk@mozilla.org>
parents: 190
diff changeset
515 // 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
516 _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
517 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
518
8e61b480af10 make 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 // 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
520 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
521 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
522 "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
523 // 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
524 // 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
525 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
526 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
527 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
528 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
529 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
530 "",
8e61b480af10 make 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 "");
8e61b480af10 make 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
8e61b480af10 make 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 // 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
534 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
535
8e61b480af10 make 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 // 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
537 // 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
538 // 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
539 // 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
540 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
541 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
542 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
543 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
544 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
545
8e61b480af10 make 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 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
547 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
548 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
549 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
550
8e61b480af10 make 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 // 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
552 this._authInfo = 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
553 }
8e61b480af10 make 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
8e61b480af10 make 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 };