adium-1.4 3525:d591088f7a6f: * Added indication of progress in t...
commits at adium.im
commits at adium.im
Fri Jun 24 20:55:27 UTC 2011
details: http://hg.adium.im/adium-1.4/rev/d591088f7a6f
revision: 3525:d591088f7a6f
branch: facebook-xmpp
author: Evan Schoenberg
date: Fri Jun 24 15:55:08 2011 -0500
* Added indication of progress in the Facebook XMPP account setup window
* Handle failure more gracefully
Fixes #15041
diffs (183 lines):
diff -r 72840c154304 -r d591088f7a6f Plugins/Purple Service/AIFacebookXMPPAccount.h
--- a/Plugins/Purple Service/AIFacebookXMPPAccount.h Fri Jun 24 15:38:55 2011 -0500
+++ b/Plugins/Purple Service/AIFacebookXMPPAccount.h Fri Jun 24 15:55:08 2011 -0500
@@ -16,6 +16,18 @@
/* deprecated? This is called the 'App Secret' on Facebook's developer page. */
#define ADIUM_API_SECRET "bb9d2d9771790e69a0e943771ddf33c8"
+#define AIFacebookXMPPAuthProgressNotification @"AIFacebookXMPPAuthProgressNotification"
+#define KEY_FB_XMPP_AUTH_STEP @"AuthStep"
+
+typedef enum {
+ AIFacebookXMPPAuthProgressPromptingUser,
+ AIFacebookXMPPAuthProgressContactingServer,
+ AIFacebookXMPPAuthProgressPromotingForChat,
+ AIFacebookXMPPAuthProgressSuccess,
+ AIFacebookXMPPAuthProgressFailure
+} AIFacebookXMPPAuthProgressStep;
+
+
@interface AIFacebookXMPPAccount : CBPurpleAccount {
AIFacebookXMPPOAuthWebViewWindowController *oAuthWC;
AIAccount *migratingAccount; // weak
@@ -28,6 +40,8 @@
NSMutableData *connectionData;
}
++ (BOOL)uidIsValidForFacebook:(NSString *)inUID;
+
@property (nonatomic, retain) AIFacebookXMPPOAuthWebViewWindowController *oAuthWC;
@property (nonatomic, assign) AIAccount *migratingAccount;
- (void)requestFacebookAuthorization;
diff -r 72840c154304 -r d591088f7a6f Plugins/Purple Service/AIFacebookXMPPAccount.m
--- a/Plugins/Purple Service/AIFacebookXMPPAccount.m Fri Jun 24 15:38:55 2011 -0500
+++ b/Plugins/Purple Service/AIFacebookXMPPAccount.m Fri Jun 24 15:55:08 2011 -0500
@@ -246,8 +246,11 @@
self.oAuthWC = [[[AIFacebookXMPPOAuthWebViewWindowController alloc] init] autorelease];
self.oAuthWC.account = self;
- NSLog(@"Requesting facebook auth for %@; UID %@; password %@", self, self.UID, [adium.accountController passwordForAccount:self]);
-
+ [[NSNotificationCenter defaultCenter] postNotificationName:AIFacebookXMPPAuthProgressNotification
+ object:self
+ userInfo:
+ [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:AIFacebookXMPPAuthProgressPromptingUser]
+ forKey:KEY_FB_XMPP_AUTH_STEP]];
if (self.migratingAccount) {
/* We're migrating from an entirely separate AIAccount (an old, http-based Facebook account) to this one */
self.oAuthWC.autoFillUsername = self.migratingAccount.UID;
@@ -274,6 +277,24 @@
self.networkState = AIMeGraphAPINetworkState;
self.connectionData = [NSMutableData data];
self.connection = [NSURLConnection connectionWithRequest:request delegate:self];
+
+ [[NSNotificationCenter defaultCenter] postNotificationName:AIFacebookXMPPAuthProgressNotification
+ object:self
+ userInfo:
+ [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:AIFacebookXMPPAuthProgressContactingServer]
+ forKey:KEY_FB_XMPP_AUTH_STEP]];
+}
+
+- (void)oAuthWebViewControllerDidFail:(AIFacebookXMPPOAuthWebViewWindowController *)wc
+{
+ [self setOAuthToken:nil];
+
+ [[NSNotificationCenter defaultCenter] postNotificationName:AIFacebookXMPPAuthProgressNotification
+ object:self
+ userInfo:
+ [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:AIFacebookXMPPAuthProgressFailure]
+ forKey:KEY_FB_XMPP_AUTH_STEP]];
+
}
- (void)meGraphAPIDidFinishLoading:(NSData *)graphAPIData response:(NSURLResponse *)inResponse error:(NSError *)inError
@@ -305,6 +326,12 @@
self.networkState = AIPromoteSessionNetworkState;
self.connectionData = [NSMutableData data];
self.connection = [NSURLConnection connectionWithRequest:secretRequest delegate:self];
+
+ [[NSNotificationCenter defaultCenter] postNotificationName:AIFacebookXMPPAuthProgressNotification
+ object:self
+ userInfo:
+ [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:AIFacebookXMPPAuthProgressPromotingForChat]
+ forKey:KEY_FB_XMPP_AUTH_STEP]];
}
- (void)promoteSessionDidFinishLoading:(NSData *)secretData response:(NSURLResponse *)response error:(NSError *)inError
@@ -350,6 +377,12 @@
if (self.migratingAccount) {
[self finishMigration];
}
+
+ [[NSNotificationCenter defaultCenter] postNotificationName:AIFacebookXMPPAuthProgressNotification
+ object:self
+ userInfo:
+ [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:AIFacebookXMPPAuthProgressSuccess]
+ forKey:KEY_FB_XMPP_AUTH_STEP]];
}
#pragma mark NSURLConnectionDelegate
@@ -452,4 +485,3 @@
}
@end
-
\ No newline at end of file
diff -r 72840c154304 -r d591088f7a6f Plugins/Purple Service/AIFacebookXMPPAccountViewController.m
--- a/Plugins/Purple Service/AIFacebookXMPPAccountViewController.m Fri Jun 24 15:38:55 2011 -0500
+++ b/Plugins/Purple Service/AIFacebookXMPPAccountViewController.m Fri Jun 24 15:55:08 2011 -0500
@@ -18,6 +18,7 @@
- (void)dealloc
{
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
@@ -53,8 +54,44 @@
if ([[AIFacebookXMPPAccount class] uidIsValidForFacebook:account.UID] &&
[adium.accountController passwordForAccount:account].length) {
- [textField_OAuthStatus setStringValue:AILocalizedString(@"Adium currently has access to your account.", nil)];
+ [textField_OAuthStatus setStringValue:AILocalizedString(@"Adium is authorized for Facebook Chat.", nil)];
[button_OAuthStart setEnabled:NO];
+ } else {
+ [textField_OAuthStatus setStringValue:@""];
+ [button_OAuthStart setEnabled:YES];
+ }
+
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(authProgressDidChange:)
+ name: AIFacebookXMPPAuthProgressNotification
+ object:inAccount];
+}
+
+- (void) authProgressDidChange:(NSNotification *)notification
+{
+ AIFacebookXMPPAuthProgressStep step = [[notification.userInfo objectForKey:KEY_FB_XMPP_AUTH_STEP] intValue];
+
+ switch (step) {
+ case AIFacebookXMPPAuthProgressPromptingUser:
+ [textField_OAuthStatus setStringValue:[AILocalizedString(@"Requesting authorization", nil) stringByAppendingEllipsis]];
+ break;
+
+ case AIFacebookXMPPAuthProgressContactingServer:
+ [textField_OAuthStatus setStringValue:[AILocalizedString(@"Contacting authorization server", nil) stringByAppendingEllipsis]];
+ break;
+
+ case AIFacebookXMPPAuthProgressPromotingForChat:
+ [textField_OAuthStatus setStringValue:[AILocalizedString(@"Promoting authorization for chat", nil) stringByAppendingEllipsis]];
+ break;
+
+ case AIFacebookXMPPAuthProgressSuccess:
+ [textField_OAuthStatus setStringValue:AILocalizedString(@"Adium is authorized for Facebook Chat.", nil)];
+ break;
+
+ case AIFacebookXMPPAuthProgressFailure:
+ [textField_OAuthStatus setStringValue:AILocalizedString(@"Could not complete authorization.", nil)];
+ [button_OAuthStart setEnabled:YES];
+ break;
}
}
@@ -67,7 +104,7 @@
{
if (sender == button_OAuthStart || sender == button_migrationOAuthStart) {
[(AIFacebookXMPPAccount *)account requestFacebookAuthorization];
- [textField_OAuthStatus setStringValue:[AILocalizedString(@"Requesting authorization", nil) stringByAppendingEllipsis]];
+ [button_OAuthStart setEnabled:NO];
} else if (sender == button_migrationHelp) {
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://trac.adium.im/wiki/FacebookChat"]];
diff -r 72840c154304 -r d591088f7a6f Plugins/Purple Service/AIFacebookXMPPOAuthWebViewWindowController.m
--- a/Plugins/Purple Service/AIFacebookXMPPOAuthWebViewWindowController.m Fri Jun 24 15:38:55 2011 -0500
+++ b/Plugins/Purple Service/AIFacebookXMPPOAuthWebViewWindowController.m Fri Jun 24 15:55:08 2011 -0500
@@ -114,6 +114,8 @@
[self.account oAuthWebViewController:self didSucceedWithToken:token];
} else {
/* Got a bad token, or the user canceled */
+ [self.account oAuthWebViewControllerDidFail:self];
+
}
[self closeWindow:nil];
More information about the commits
mailing list