// // ConversationController.m // Proteus // // Created by Julian Cain on 7/18/10. // Copyright 2010 __MyCompanyName__. All rights reserved. // #import "BuddyController.h" #import "ChatWindowController.h" #import "Conversation.h" #import "ConversationController.h" #import "Proteus_AppDelegate.h" @implementation ConversationController @synthesize conversations = _conversations; - (id)init { if (self = [super init]) { self.conversations = [[[NSMutableArray alloc] init] autorelease]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(purpConversationDidReceiveNotification:) name:kPurpConversationDidReceiveNotification object:nil ]; return self; } return nil; } - (Conversation *)converseWith:(NSString *)aName { NSLog(@"Starting conversation with %@.", aName); Conversation * conversation = nil; for (conversation in self.conversations) { if ([conversation.name isEqualToString:aName]) { NSLog(@"Using existing conversation for %@.", aName); break; } } if (!conversation) { NSLog(@"Allocating new conversation for %@.", aName); conversation = [[[Conversation alloc] init] autorelease]; conversation.name = aName; /** * Initialize the conversation's wevview. */ [conversation initWebView]; } return conversation; } - (void)purpConversationDidReceiveNotification:(NSNotification *)aNotification { NSDictionary * dict = [aNotification object]; NSLog(@"purpConversationDidReceiveNotification: %@", [dict description]); NSString * alias = [dict objectForKey:@"alias"]; NSString * message = [dict objectForKey:@"message"];; NSDate * time = [dict objectForKey:@"time"];; NSString * who = [dict objectForKey:@"who"];; Proteus_AppDelegate * delegate = (Proteus_AppDelegate *)[NSApp delegate] ; [delegate.buddyController.chatWindowController.window center]; [delegate.buddyController.chatWindowController showWindow:nil]; Conversation * conversation = nil; for (conversation in self.conversations) { if ([conversation.name isEqualToString:who]) { [delegate.buddyController.chatWindowController updateConversation:conversation message:message time:time ]; break; } } [delegate.buddyController.chatWindowController.window makeKeyAndOrderFront:nil ]; } - (void)dealloc { [_conversations release], _conversations = nil; [[NSNotificationCenter defaultCenter] removeObserver:self]; [super dealloc]; } @end