Skip to content

Commit

Permalink
Bring conversation to front when launching from UILocalNotification
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisballinger committed Sep 11, 2012
1 parent 6574461 commit 4210e2c
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 35 deletions.
24 changes: 14 additions & 10 deletions Off the Record/OTRAppDelegate.m
Expand Up @@ -30,6 +30,7 @@
#import "DDLog.h"
#import "OTRUIKeyboardListener.h"
#import "Appirater.h"
#import "OTRConstants.h"

// Log levels: off, error, warn, info, verbose
#if DEBUG
Expand Down Expand Up @@ -92,12 +93,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];

UILocalNotification *localNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotification) {
NSLog(@"Notification Body: %@",localNotification.alertBody);
NSLog(@"%@", localNotification.userInfo);
}

application.applicationIconBadgeNumber = 0;
[OTRUIKeyboardListener shared];

Expand Down Expand Up @@ -240,11 +235,20 @@ - (void)tabBarController:(UITabBarController *)tabBarController didEndCustomizin
}
*/

/*- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
NSLog(@"Notification Body: %@", notification.alertBody);
NSLog(@"%@", notification.userInfo);
NSLog(@"User Info: %@", notification.userInfo);

application.applicationIconBadgeNumber = 0;
}*/
NSDictionary *userInfo = notification.userInfo;
NSString *accountName = [userInfo objectForKey:kOTRNotificationAccountNameKey];
NSString *userName = [userInfo objectForKey:kOTRNotificationUserNameKey];
NSString *protocol = [userInfo objectForKey:kOTRNotificationProtocolKey];
if (!accountName || !userName || !protocol) {
return;
}
OTRProtocolManager *protocolManager = [OTRProtocolManager sharedInstance];
OTRBuddy *buddy = [protocolManager buddyForUserName:userName accountName:accountName protocol:protocol];
[buddyListViewController enterConversationWithBuddy:buddy];
}

@end
6 changes: 6 additions & 0 deletions Off the Record/OTRBuddy.m
Expand Up @@ -127,6 +127,12 @@ -(void)receiveMessage:(NSString *)message
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.applicationIconBadgeNumber = [UIApplication sharedApplication].applicationIconBadgeNumber + 1;
localNotification.alertBody = [NSString stringWithFormat:@"%@: %@",self.displayName,self.lastMessage];

NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithCapacity:3];
[userInfo setObject:accountName forKey:kOTRNotificationUserNameKey];
[userInfo setObject:protocol.account.username forKey:kOTRNotificationAccountNameKey];
[userInfo setObject:protocol.account.protocol forKey:kOTRNotificationProtocolKey];
localNotification.userInfo = userInfo;

[[UIApplication sharedApplication] presentLocalNotificationNow:localNotification];
}
Expand Down
2 changes: 1 addition & 1 deletion Off the Record/OTRBuddyList.h
Expand Up @@ -32,7 +32,7 @@
-(void)addBuddy:(OTRBuddy*)newBuddy;
-(void)removeBuddiesforAccount:(OTRAccount *)account;
-(NSUInteger)count;
-(OTRBuddy*)getbuddyForUserName:(NSString *)buddyUserName accountUniqueIdentifier:(NSString *)uniqueIdentifier;
-(OTRBuddy*)getBuddyForUserName:(NSString *)buddyUserName accountUniqueIdentifier:(NSString *)uniqueIdentifier;
-(void) updateBuddies:(NSArray *)arrayOfBuddies;

+(NSArray*)sortBuddies:(NSMutableDictionary*)buddies;
Expand Down
2 changes: 1 addition & 1 deletion Off the Record/OTRBuddyList.m
Expand Up @@ -94,7 +94,7 @@ -(void) updateBuddies:(NSArray *)arrayOfBuddies
}
}

-(OTRBuddy *)getbuddyForUserName:(NSString *)buddyUserName accountUniqueIdentifier:(NSString *)uniqueIdentifier
-(OTRBuddy *)getBuddyForUserName:(NSString *)buddyUserName accountUniqueIdentifier:(NSString *)uniqueIdentifier
{
return [[allBuddies objectForKey:uniqueIdentifier] objectForKey:buddyUserName];
}
Expand Down
2 changes: 1 addition & 1 deletion Off the Record/OTRBuddyListViewController.m
Expand Up @@ -367,7 +367,7 @@ -(void)enterConversationWithBuddy:(OTRBuddy*)buddy

BOOL chatViewIsVisible = chatViewController.isViewLoaded && chatViewController.view.window;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && !chatViewIsVisible && self.navigationController.visibleViewController != chatViewController) {
[self.navigationController pushViewController:chatViewController animated:YES];
[self.navigationController setViewControllers:[NSArray arrayWithObjects:self, chatViewController, nil] animated:YES];
}
[self refreshActiveConversations];
}
Expand Down
4 changes: 4 additions & 0 deletions Off the Record/OTRConstants.h
Expand Up @@ -34,6 +34,10 @@
#define kOTRProtocolTypeXMPP @"xmpp"
#define kOTRProtocolTypeAIM @"prpl-oscar"

#define kOTRNotificationAccountNameKey @"kOTRNotificationAccountNameKey"
#define kOTRNotificationUserNameKey @"kOTRNotificationUserNameKey"
#define kOTRNotificationProtocolKey @"kOTRNotificationProtocolKey"

#define kOTRXMPPAccountAllowSelfSignedSSLKey @"kOTRXMPPAccountAllowSelfSignedSSLKey"
#define kOTRXMPPAccountAllowSSLHostNameMismatch @"kOTRXMPPAccountAllowSSLHostNameMismatch"

Expand Down
2 changes: 1 addition & 1 deletion Off the Record/OTRProtocolManager.m
Expand Up @@ -124,7 +124,7 @@ -(void)buddyListUpdate

-(OTRBuddy *)buddyForUserName:(NSString *)buddyUserName accountName:(NSString *)accountName protocol:(NSString *)protocol
{
return [self.buddyList getbuddyForUserName:buddyUserName accountUniqueIdentifier:[self.accountsManager accountForProtocol:protocol accountName:accountName].uniqueIdentifier];
return [self.buddyList getBuddyForUserName:buddyUserName accountUniqueIdentifier:[self.accountsManager accountForProtocol:protocol accountName:accountName].uniqueIdentifier];


}
Expand Down
21 changes: 0 additions & 21 deletions Off the Record/OTRXMPPManager.m
Expand Up @@ -706,27 +706,6 @@ - (void)xmppRoster:(XMPPRoster *)sender didReceiveBuddyRequest:(XMPPPresence *)p
{
body = [NSString stringWithFormat:@"Buddy request from %@", displayName];
}


if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateActive)
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:displayName
message:body
delegate:nil
cancelButtonTitle:@"Not implemented"
otherButtonTitles:nil];
[alertView show];
}
else
{
// We are not active, so use a local notification instead
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.alertAction = @"Not implemented";
localNotification.alertBody = body;

[[UIApplication sharedApplication] presentLocalNotificationNow:localNotification];
}

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 4210e2c

Please sign in to comment.