Permalink
Browse files

[platform] firefox toolbar

Summary: Adding more sweetness to the toolbar:
 + Fixed the bug with posts on your wall
 + Added notification for new photos added to albums, and new photos created
 + Tested that it works with infinite sessions

Reviewed by: ari

Test plan: ran it for many a day

Revert: not trunk code, but go ahead
  • Loading branch information...
1 parent c3b392d commit dfd9df820b33f9f1ba416556710cae595653d861 Eugene Letuchy committed Mar 19, 2007
View
@@ -0,0 +1 @@
+zip -r ../facebook_toolbar.xpi chrome chrome.manifest components defaults install.rdf license.txt -x "*.svn*" -x "*.bat";
@@ -10,15 +10,16 @@
<children />
</content>
</binding>
- <binding id="friendBox" extends="chrome://global/content/bindings/richlistbox.xml#richlistitem">
+ <binding id="friendBox" extends="chrome://global/content/bindings/richlistbox.xml#richlistitem" flex="1">
<content>
<xul:vbox style="min-height: 50px;">
- <xul:image xbl:inherits="src=pic,onclick=oncommand" class="facebook-link friend-image" />
+ <xul:image xbl:inherits="src=pic,onclick=oncommand" class="facebook-link friend-image"
+ style="border: 1px solid black;" />
</xul:vbox>
- <xul:vbox>
+ <xul:vbox flex="1" style="padding: 3px;">
<xul:label xbl:inherits="value=friendname,onclick=oncommand" class="facebook-link user_name" />
<xul:label xbl:inherits="value=ptime,onclick=viewUpdCmd" class="facebook-link ptime" />
- <xul:description class="status" >
+ <xul:description class="status">
<children />
</xul:description>
<xul:label xbl:inherits="value=stime" class="stime" />
@@ -32,6 +33,7 @@
<xul:label value="wall post" xbl:inherits="onclick=postCmd"
class="facebook-link mini-link" />
</xul:hbox>
+ <xul:spacer flex="1" />
</xul:vbox>
</content>
</binding>
View
@@ -1,6 +1,6 @@
/**
* Facebook Firefox Toolbar Software License
- * Copyright (c) 2006 Facebook, Inc.
+ * Copyright (c) 2007 Facebook, Inc.
*
* Permission is hereby granted, free of charge, to any person or organization
* obtaining a copy of the software and accompanying documentation covered by
@@ -44,7 +44,6 @@ Cc['@mozilla.org/moz/jssubscript-loader;1']
function FacebookLoginClient() {
this.fbSvc = Cc['@facebook.com/facebook-service;1'].getService().QueryInterface(Ci.fbIFacebookService);
- default xml namespace = new Namespace("http://api.facebook.com/1.0/");
}
FacebookLoginClient.prototype = {
@@ -64,7 +63,7 @@ FacebookLoginClient.prototype = {
params.push('v=1.0');
params.push('sig=' + this.generateSig(params));
var req = new XMLHttpRequest();
- var namespace = this.findNamespace;
+ var ns_re = this.findNamespace;
req.onreadystatechange = function (event) {
if (req.readyState == 4) {
var status;
@@ -76,15 +75,18 @@ FacebookLoginClient.prototype = {
if (status == 200) {
dump( 'login:' + req.responseText.indexOf("\n") + "\n" );
- // default xml namespace='http://api.facebook.com/1.0/';
req.text = req.responseText.substr(req.responseText.indexOf("\n"));
- req.xmldata = new XML(req.text.replace(namespace,""));
+ var ns = req.text.match(ns_re);
+ if( ns )
+ default xml namespace = ns;
+ req.xmldata = new XML(req.text);
callback(req);
}
}
};
try {
- req.open('POST', 'https://api.facebook.com/restserver.php', true);
+ var restserver = 'https://api.facebook.com/restserver.php';
+ req.open('POST', restserver, true);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
req.send(params.join('&'));
dump( params.join('&') + "\n" );
View
@@ -1,6 +1,6 @@
/**
* Facebook Firefox Toolbar Software License
- * Copyright (c) 2006 Facebook, Inc.
+ * Copyright (c) 2007 Facebook, Inc.
*
* Permission is hereby granted, free of charge, to any person or organization
* obtaining a copy of the software and accompanying documentation covered by
@@ -88,12 +88,11 @@ function IsSidebarOpen() {
}
function GetFriendsListElement() {
- if (IsSidebarOpen()) {
- var list = top.document.getElementById('sidebar').contentDocument.getElementById('SidebarFriendsList');
- }
- if (!list) {
- var list = top.document.getElementById('PopupFacebookFriendsList');
- }
+ var list = IsSidebarOpen()
+ ? top.document.getElementById('sidebar').contentDocument.getElementById('SidebarFriendsList')
+ : null;
+ if( !list )
+ list = top.document.getElementById('PopupFacebookFriendsList');
return list;
}
@@ -176,35 +175,33 @@ function SearchFriends(search) {
SetHint(true, 'Press enter to search for "' + search + '" on Facebook',
"openUILink('http://www.facebook.com/s.php?src=fftb&q=' + encodeURIComponent(GetFBSearchBox().value), event);");
} else if (!sidebar && (numMatched > 4 || !search)) {
- var str = 'See all ' + numMatched + ' friends'
- if (search) {
- str += ' matching "' + search + '"';
- }
+ var str = 'See all ' + numMatched + ' friends';
+ if (search)
+ str += ' matching "' + search + '"';
str += '...';
SetHint(true, str, "toggleSidebar('viewFacebookSidebar');");
} else {
SetHint(false, '', '');
}
if (!sidebar) {
- var msger = document.getElementById('PopupMessager');
- var poker = document.getElementById('PopupPoker');
- var poster = document.getElementById('PopupPoster');
- if (numMatched == 1) {
- msger.setAttribute('userid', lastDisplayed.getAttribute('userid'));
- msger.setAttribute('value', 'Send ' + lastDisplayed.getAttribute('firstname') + ' a message');
- msger.style.display = '';
-
- poker.setAttribute('userid', lastDisplayed.getAttribute('userid'));
- poker.setAttribute('value', 'Poke ' + lastDisplayed.getAttribute('firstname'));
- poker.style.display = '';
-
- poster.setAttribute('userid', lastDisplayed.getAttribute('userid'));
- poster.setAttribute('value', 'Write on ' + lastDisplayed.getAttribute('firstname') + "'s wall");
- poster.style.display = '';
+ var msger = document.getElementById('PopupMessager'),
+ poker = document.getElementById('PopupPoker'),
+ poster = document.getElementById('PopupPoster');
+ if (1 == numMatched) {
+ var uid = lastDisplayed.getAttribute('userid'),
+ firstname = lastDisplayed.getAttribute('firstname');
+ msger.setAttribute('userid', uid );
+ msger.setAttribute('value', 'Send ' + firstname + ' a message');
+
+ poker.setAttribute('userid', uid );
+ poker.setAttribute('value', 'Poke ' + firstname );
+
+ poster.setAttribute('userid', uid);
+ poster.setAttribute('value', 'Write on ' + firstname + "'s wall");
+
+ msger.style.display = poker.style.display = poster.style.display = '';
} else {
- msger.style.display = 'none';
- poker.style.display = 'none';
- poster.style.display = 'none';
+ msger.style.display = poker.style.display = poster.style.display = 'none';
}
}
var item = list.selectedItem;
@@ -282,7 +279,7 @@ function FacebookLogin() {
// popup login page height is normally 436, but add 20 pixels for the
// button we show at the bottom of the page
window.open('chrome://facebook/content/login.xul', '',
- 'chrome,centerscreen,width=626,height=456,modal=yes,dialog=yes,close=yes');
+ 'chrome,centerscreen,width=626,height=476,modal=yes,dialog=yes,close=yes');
}
}
@@ -293,6 +290,11 @@ function RenderStatusMsg(msg) {
}
return msg;
}
+
+function SetProfileTime(item, time){
+ item.setAttribute('ptime',getProfileTime(time));
+}
+
function SetStatus(item, status, time) {
if (status) {
var firstName = item.getAttribute('firstname');
@@ -328,7 +330,7 @@ var dates_in_seconds = new DatesInSeconds();
* @param time - time in seconds from epoch
*/
function getRelativeTime(time) {
- var elapsed = (new Date().getTime()/1000 - time);
+ var elapsed = Math.floor(new Date().getTime()/1000) - time;
if (elapsed <= 1)
return 'a moment ago';
if (elapsed < dates_in_seconds.minute)
@@ -342,7 +344,8 @@ function getRelativeTime(time) {
if (elapsed < dates_in_seconds.day )
return Math.round(elapsed/dates_in_seconds.hour) + ' hours ago';
if (elapsed < dates_in_seconds.week) {
- var days = new Array( "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" );
+ var days = new Array( "Sunday", "Monday", "Tuesday", "Wednesday",
+ "Thursday", "Friday", "Saturday" );
var d = new Date;
d.setTime(time*1000);
return 'on ' + days[d.getDay()];
@@ -358,41 +361,61 @@ function getRelativeTime(time) {
return 'over a year ago';
}
+function getRelTime(time) {
+ var elapsed = Math.floor(new Date().getTime()/1000) - time;
+ if( elapsed < dates_in_seconds.week )
+ return getRelTimeWithinWeek(time, false);
+ if (elapsed < dates_in_seconds.week*1.5)
+ return 'about a week ago';
+ if (elapsed < dates_in_seconds.week*3.5)
+ return 'about ' + Math.round(elapsed/dates_in_seconds.week) + ' weeks ago';
+ if (elapsed < dates_in_seconds.month*1.5)
+ return 'about a month ago';
+ if (elapsed < dates_in_seconds.year)
+ return 'about ' + Math.round(elapsed/dates_in_seconds.month) + ' months ago';
+ return 'over a year ago';
+}
+
function getProfileTime(profile_time) {
- return "Updated profile " + getRelativeTime(profile_time);
+ return "Updated profile " + getRelTime(profile_time);
+ }
+
+function getRelTimeWithinWeek(time, initialCap ) {
+ var currentTime = new Date;
+
+ var updateTime = new Date;
+ updateTime.setTime(time*1000);
+
+ var days = new Array("Sunday", "Monday", "Tuesday", "Wednesday",
+ "Thursday", "Friday", "Saturday");
+ var day;
+
+ // assumption that status messages are only shown if in the last 7 days
+ if (updateTime.getDate() == currentTime.getDate()) {
+ day = initialCap ? "Today" : "today";
+ } else if ((updateTime.getDay() + 1) % 7 == currentTime.getDay()) {
+ day = initialCap ? "Yesterday" : "yesterday";
+ } else {
+ day = ( initialCap ? 'Last ' : 'last ' ) + days[updateTime.getDay()];
}
+ var hour = updateTime.getHours();
+ if (hour > 11) timeOfDay = 'pm';
+ else timeOfDay = 'am';
+ if (hour >= 13) hour -= 12;
+ if (hour == 0) hour = 12;
+
+ var minute = updateTime.getMinutes();
+ if (minute < 10) {
+ minute = '0' + minute;
+ }
+
+ var tstr = day + ' at ' + hour + ':' + minute + ' ' + timeOfDay;
+ return tstr;
+}
+
function getStatusTime(status_time) {
- var currentTime = new Date();
-
- var updateTime = new Date;
- updateTime.setTime(status_time*1000);
-
- var days = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
- var day;
-
- // assumption that status messages are only shown if in the last 7 days
- if (updateTime.getDate() == currentTime.getDate()) {
- day = "Today";
- } else if ((updateTime.getDay() + 1) % 7 == currentTime.getDay()) {
- day = "Yesterday";
- } else {
- day = 'Last ' + days[updateTime.getDay()];
- }
-
- var hour = updateTime.getHours();
- if (hour > 11) timeOfDay = 'pm';
- else timeOfDay = 'am';
- if (hour >= 13) hour -= 12;
- if (hour == 0) hour = 12;
-
- var minute = updateTime.getMinutes();
- if (minute < 10) {
- minute = '0' + minute;
- }
-
- stime = day + ' at ' + hour + ':' + minute + ' ' + timeOfDay;
- return stime;
+ return getRelTimeWithinWeek(status_time, true);
}
/**
View
@@ -1,6 +1,6 @@
/**
* Facebook Firefox Toolbar Software License
- * Copyright (c) 2006 Facebook, Inc.
+ * Copyright (c) 2007 Facebook, Inc.
*
* Permission is hereby granted, free of charge, to any person or organization
* obtaining a copy of the software and accompanying documentation covered by
@@ -43,7 +43,7 @@ Cc['@mozilla.org/moz/jssubscript-loader;1']
.loadSubScript('chrome://facebook/content/facebook.js');
var client = new FacebookLoginClient();
-
+var fbns = new Namespace( "http://api.facebook.com/1.0/" );
function startup() {
if (client.fbSvc.loggedIn) {
debug('already logged in!');
@@ -63,7 +63,8 @@ function startup() {
}
} else {
var browser = document.getElementById('facebook-login-body');
- browser.setAttribute('src', 'http://www.facebook.com/login.php?popup&v=1.0&api_key=' +
+ var login_base = 'http://www.facebook.com/login.php?popup&v=1.0&api_key=';
+ browser.setAttribute('src', login_base +
client.fbSvc.apiKey + '&auth_token=' + client.authToken);
browser.style.display = '';
document.getElementById('throbber-box').style.display = 'none';
@@ -83,9 +84,9 @@ function done() {
debug('received session response:');
debug(req.xmldata);
var data = req.xmldata;
- var sessionKey = data.session_key;
- var sessionSecret = data.secret;
- var uid = data.uid;
+ var sessionKey = data.fbns::session_key;
+ var sessionSecret = data.fbns::secret;
+ var uid = data.fbns::uid;
if (sessionKey && sessionSecret && uid) {
client.fbSvc.sessionStart(sessionKey, sessionSecret, uid);
client.authToken = null;
View
@@ -27,9 +27,13 @@
label="Cancel"
oncommand="window.close()"/>
-->
+ <hbox>
+ <spacer flex="1" /> -->
<button id="facebook-login-done"
class="dialog"
label="Close login window"
oncommand="done()"/>
- <!--</toolbar>-->
+ <spacer flex="1" />
+ </hbox>
+ <!-- </toolbar> -->
</window>
Oops, something went wrong.

0 comments on commit dfd9df8

Please sign in to comment.