* Added $apply and some other collection utils.
* Moved logging code to a separate code segment.
* Fixed uninitialized variable in Target.
5 // Created by Jens Alfke on 3/3/08.
6 // Copyright 2008 Jens Alfke. All rights reserved.
10 #import "iChatBridge.h"
12 @implementation IChatUtils
15 static iChatApplication *sIChatApp;
20 sIChatApp = [SBApplication applicationWithBundleIdentifier: @"com.apple.iChat"];
21 sIChatApp.timeout = 5*60; // in ticks
26 + (SBApplication*) app {return sIChatApp;}
27 + (BOOL) isRunning {return sIChatApp.isRunning;}
28 + (void) activate {[sIChatApp activate];}
31 + (iChatTextChat*) activeChat
33 if( ! [sIChatApp isRunning] )
35 SBElementArray *chats = sIChatApp.textChats;
38 iChatTextChat *chat = [chats objectAtIndex: 0];
39 /*if( ! chat.active ) // somehow this returns NO for Bonjour chats
44 + (NSString*) activeChatPartner
46 iChatTextChat *chat = [self activeChat];
47 Log(@"Active chat = %@",chat);
50 NSMutableArray *names = $marray();
51 for( iChatBuddy *b in [chat participants] )
52 [names addObject: (b.fullName ?: b.name)];
53 Log(@"Particpants = %@",names);
54 return [names componentsJoinedByString: @", "];
57 + (BOOL) sendMessage: (NSString*)msg
59 iChatTextChat *chat = [self activeChat];
62 [sIChatApp send: msg to: chat];