Permalink
Browse files

pages.

  • Loading branch information...
1 parent 209ba0b commit a564dfe5486cb3b0e1ab34f66d9db691f056e877 @jubishop committed Jul 24, 2009
View
@@ -37,7 +37,7 @@ package fb {
public class FBAPI {
private static const restURL:String =
- "http://api.jubishop.devrs006.facebook.com/restserver.php";
+ "http://api.facebook.com/restserver.php";
private static var auth_token:String;
private static var session_key:String;
View
@@ -46,23 +46,10 @@ package fb {
public static var api_key:String;
[Bindable] public static var session:FBSession;
+ // List of extra session params passed to requireSession()
+ private static var extraSessionParams:Object;
+
// Permissions
- private static const allPermissions:Array = [
- 'email',
- 'offline_access',
- 'status_update',
- 'photo_upload',
- 'create_listing',
- 'create_event',
- 'rsvp_event',
- 'sms',
- 'video_upload',
- 'create_note',
- 'share_item',
- 'read_stream',
- 'publish_stream',
- 'auto_publish_short_feed'
- ];
private static var permissions:Array = new Array();
private static var validating_permissions:Array;
@@ -113,9 +100,6 @@ package fb {
// Call this to require/validate a permission
public static function requirePermissions(permission_names:Array):void {
- for each (var permission_name:String in permission_names) {
- if (allPermissions.indexOf(permission_name) == -1) return;
- }
if (validating_permissions) return;
// Ask about all these first, to see if we're already auth'd
@@ -220,13 +204,15 @@ package fb {
// This will require we get a session key.
// And validate if we already have one.
- public static function requireSession():void {
+ public static function requireSession(extra_params:Object = null):void {
if (!api_key) return;
+ extraSessionParams = extra_params;
+
if (session) {
validateSession();
} else {
- var dialog:FBAuthDialog = new FBAuthDialog();
+ var dialog:FBAuthDialog = new FBAuthDialog(extraSessionParams);
dialog.addEventListener(FBEvent.CLOSED, loginDialogClosed);
dialog.show();
}
@@ -236,7 +222,7 @@ package fb {
private static function noLoggedInUser(event:FBEvent = null):void {
session = null;
SharedObject.getLocal(api_key).data["session_key"] = null;
- requireSession();
+ requireSession(extraSessionParams);
}
// Callback from restserver of whether session key is valid
@@ -266,9 +252,6 @@ package fb {
sharedObject.data["secret"] = session.secret;
status = Connected;
-
- Output.log("Loaded session from login dialog: ",
- session.key, session.uid, session.expires, session.secret);
} else {
status = NotLoggedIn;
}
@@ -25,12 +25,15 @@ package fb.display {
private static const FailurePath:String = FBDialog.FacebookURL +
"/connect/login_failure.html";
- public function FBAuthDialog() {
+ public function FBAuthDialog(extra_params:Object) {
title = "Facebook Connect Authorization";
location = "/login.php";
extraParams["next"] = NextPath;
extraParams["return_session"] = true;
extraParams["cancel_url"] = FailurePath;
+ for (var param:String in extra_params) {
+ extraParams[param] = extra_params[param];
+ }
}
override protected function htmlLocationChange(event:Event):void {
@@ -39,8 +42,8 @@ package fb.display {
if (!htmlWindow || htmlWindow.location == '' ||
htmlWindow.location == location || closed) return;
- Output.log("Authorization location: " + htmlWindow.location);
-
+ Output.bug("Authorization location: " + htmlWindow.location);
+
if (htmlWindow.location.indexOf(NextPath) == 0)
hide(true);
else if (htmlWindow.location.indexOf(FailurePath) == 0)
View
@@ -61,7 +61,7 @@
private static const MINIMUM_HEIGHT:int = 8;
public static const FacebookURL:String =
- "http://www.jubishop.devrs006.facebook.com";
+ "http://www.facebook.com";
public static const NextPath:String = FacebookURL +
"/connect/login_success.html";
View
@@ -24,7 +24,7 @@ package fb.util {
import fb.util.FlexUtil;
public class Output {
- private static var verbose:Boolean = true;
+ private static var verbose:Boolean = false;
private static var debugFile:File = FlexUtil.getUserPath("air_debug.txt");
private static var debugStream:FileStream = new FileStream();
private static var loggedItems:Array = new Array();
View
@@ -117,9 +117,12 @@
// Set nile stuff first to prepare for events
var stream_filters:Object = new Object();
- for each (var tab:Object in filtersData.tabData)
- stream_filters[tab.filter_key] = true;
- nileContainer.loadInitialFilters(stream_filters);
+ var pages:Object = new Object();
+ for each (var tab:Object in filtersData.tabData) {
+ if (tab.is_page) pages[tab.filter_key] = true;
+ else stream_filters[tab.filter_key] = true;
+ }
+ nileContainer.loadInitialFilters(stream_filters, pages);
// Now set filtersBar and we're off and running
filtersBar.focusHistory = filtersData.focusHistory;
@@ -144,7 +147,7 @@
// Now we call this to init our application.
// Always call this only once, in the applicationComplete callback.
- FBConnect.init('4b38d3e1a6df930669e13b82e3ba8974');//39f0aec9479177cddacef90da714b037');
+ FBConnect.init('39f0aec9479177cddacef90da714b037');
// This function checks to see if we're already connected
statusChanged();
@@ -163,7 +166,7 @@
else if (FBConnect.status == FBConnect.NotLoggedIn) {
requiredSession = true;
requiredPermissions = false;
- FBConnect.requireSession();
+ FBConnect.requireSession({"req_perms":"read_stream,publish_stream"});
}
}
@@ -232,7 +235,7 @@
// Filter tab switching
private function filterTabAdded(event:FBEvent):void {
- nileContainer.filterAdded(event.data);
+ nileContainer.filterAdded(event.data.key, event.data.is_page);
}
private function filterTabRemoved(event:FBEvent):void {
@@ -77,9 +77,13 @@
composerInput.editable = false;
shareButton.enabled = false;
- // Call the server with status.set to set our new status
- FBAPI.callMethod("stream.publish", {message:submittedMessage}
- ).addEventListener(FBEvent.SUCCESS, statusUpdated);
+ // Stream.publish mofo!
+ var publish_options:Object = {message:submittedMessage};
+ if (NileContainer.FilterIsPage)
+ publish_options.uid = NileContainer.CurrentFilter;
+
+ FBAPI.callMethod("stream.publish", publish_options)
+ .addEventListener(FBEvent.SUCCESS, statusUpdated);
}
// Called when the server has verified status.set
@@ -95,6 +99,7 @@
likes:{count:0, user_likes:false, can_like:true},
comments:{count:0, posts:[], can_post:true, can_remove:true},
created_time:(new Date().time / 1000),
+ is_page:NileContainer.FilterIsPage,
filter_key:NileContainer.CurrentFilter,
attachment:{}
}));
@@ -64,7 +64,7 @@
import fbair.gc.Depot;
import fbair.gui.FBTooltip;
- import fbair.gui.filters.FilterTab;
+ import fbair.gui.filters.TabItem;
import fbair.util.HashArray;
import flash.events.Event;
@@ -105,7 +105,8 @@
menu.x = width - menu.width - 2;
});
menu.visible = false;
- menu.addEventListener("itemClick", menuItemClicked);
+ menu.addEventListener(FiltersMenu.FILTER_CLICK, menuFilterClicked);
+ menu.addEventListener(FiltersMenu.PAGE_CLICK, menuPageClicked);
PopUpManager.addPopUp(menu, this);
}
@@ -146,7 +147,7 @@
if (tmpIndex >= tabsHash.length) tmpIndex = 0;
else if (tmpIndex < 0) tmpIndex = tabsHash.length - 1;
currentTab = tabsHash.keyAtIndex(tmpIndex);
- var currentRenderer:FilterTab = tabsHash.getAtKey(currentTab);
+ var currentRenderer:TabItem = tabsHash.getAtKey(currentTab);
if (currentRenderer.labelObscured)
FBTooltip.flash(tabData[tmpIndex].name, currentRenderer);
else
@@ -159,24 +160,53 @@
fbLogo.visible = (width - 98) > filterTabs.measuredWidth;
}
- // Button click callbacks
- private function menuItemClicked(event:FBEvent):void {
+ // Menu item click callbacks
+ private function menuFilterClicked(event:FBEvent):void {
addTab(event.data);
menu.hide();
}
+ private function menuPageClicked(event:FBEvent):void {
+ addTab(event.data, true);
+ menu.hide();
+ }
+ // Button to show the menu
private function menuButtonClicked(event:MouseEvent):void {
menu.show();
}
// Filter fetching
public function fetchFilters():void {
- FBAPI.callMethod("fql.query", {
- query:"select filter_key, name, rank, icon_url, is_visible, " +
- "type, value from stream_filter where uid = " +
- FBConnect.session.uid + " order by rank"
+ FBAPI.callMethod("fql.multiquery", {
+ queries:{
+ filters:"select filter_key, name, rank, icon_url, is_visible, " +
+ "type, value from stream_filter where uid = " +
+ FBConnect.session.uid + " order by rank",
+ page_admins:"select page_id from page_admin where uid = " +
+ FBConnect.session.uid,
+ pages:"select name, pic_square, page_id " +
+ "from page where page_id in " +
+ "(select page_id from #page_admins)"
+ }
}).addEventListener(FBEvent.SUCCESS, function(event:FBEvent):void {
- data = new HashArray(event.data, 'filter_key');
+ // Break out the results into a hash keyed by result name
+ var resultObject:Object = new Object();
+ for each (var result:Object in event.data)
+ resultObject[result.name] = result.fql_result_set;
+
+ // We're going to force our page objects into looking like filters,
+ // but attach an extra flag to indicate they are in fact pages...
+ // this way the FiltersBar can just treat them all as "Filters"
+ for each (var page:Object in resultObject.pages) {
+ resultObject.filters.unshift({
+ is_page:true,
+ name:page.name,
+ filter_key:page.page_id,
+ is_visible:true,
+ icon_url:page.pic_square
+ })
+ }
+ data = new HashArray(resultObject.filters, 'filter_key');
});
}
@@ -194,7 +224,7 @@
// Add everything
_tabData = new_tabData;
for each (var tab:Object in tabData) {
- var renderer:FilterTab = Depot.get(FilterTab);
+ var renderer:TabItem = Depot.get(TabItem);
renderer.data = tab;
tabsHash.push(tab.filter_key, renderer);
filterTabs.addChild(renderer);
@@ -211,7 +241,7 @@
// if this is your first launch, we'll give you default feed
if (tabsHash.length == 0)
- addTab(data.getAt(0).filter_key);
+ addTab('nf');
}
// Tab clicking
@@ -224,7 +254,7 @@
}
// Tab adding/removing
- public function addTab(key:String):void {
+ public function addTab(key:String, is_page:Boolean = false):void {
// if a tab already exists for this filter, focus it.
if (tabsHash.hasKey(key)) {
currentTab = key;
@@ -236,7 +266,7 @@
removeTab(focusHistory.first(), false);
// Create new tab
- var renderer:FilterTab = Depot.get(FilterTab);
+ var renderer:TabItem = Depot.get(TabItem);
renderer.data = data.getAtKey(key);
tabData.addItem(data.getAtKey(key));
tabsHash.push(key, renderer);
@@ -246,7 +276,10 @@
TabCount = tabsHash.length;
// Dispatch event of add
- dispatchEvent(new FBEvent("tabAdded", key));
+ dispatchEvent(new FBEvent("tabAdded", {
+ key:key,
+ is_page:is_page
+ }));
// Select current tab
currentTab = key;
@@ -265,7 +298,7 @@
// Remove tab
tabData.removeItemAt(tabsHash.indexAtKey(key));
- var deadRenderer:FilterTab = tabsHash.removeKey(key);
+ var deadRenderer:TabItem = tabsHash.removeKey(key);
Depot.put(filterTabs.removeChild(deadRenderer));
// Focus new tab if this was the current
Oops, something went wrong.

0 comments on commit a564dfe

Please sign in to comment.