From: Fraser S. <fra...@us...> - 2004-10-10 16:36:24
|
Update of /cvsroot/ljkit/LJKit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24647 Modified Files: LJAccount.h LJAccount.m LJAccount_EditFriends.h LJAccount_EditFriends.m Log Message: Improvements to better support Key-Value Observing. Added -relationshipArray method to return all friends incoming, outgoing and mutual. Added LJAccount{Will,Did}DownloadFriendsNotification to better support aynchronous logging in. Added -defaultUserPictureKeyword: method, which helps with object selection in a Cocoa-bound popup list. I've tried to surround changes with "[FS]" for easy searching. Index: LJAccount_EditFriends.m =================================================================== RCS file: /cvsroot/ljkit/LJKit/LJAccount_EditFriends.m,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** LJAccount_EditFriends.m 6 Oct 2004 08:21:31 -0000 1.4 --- LJAccount_EditFriends.m 10 Oct 2004 16:35:51 -0000 1.5 *************** *** 52,55 **** --- 52,60 ---- - (void)downloadFriends { + // [FS] + NSNotification *note = [NSNotification notificationWithName: LJAccountWillDownloadFriendsNotification object: self]; + [[NSNotificationCenter defaultCenter] performSelectorOnMainThread: @selector(postNotification:) + withObject: note + waitUntilDone: YES]; NSDictionary *parameters, *reply; *************** *** 68,71 **** --- 73,81 ---- _friendsSyncDate = [[NSDate alloc] init]; [self updateGroupSetWithReply:reply]; + + note = [NSNotification notificationWithName: LJAccountDidDownloadFriendsNotification object: self]; + [[NSNotificationCenter defaultCenter] performSelectorOnMainThread: @selector(postNotification:) + withObject: note + waitUntilDone: NO]; } *************** *** 202,205 **** --- 212,223 ---- } + - (NSArray *)relationshipArray { + NSMutableSet *set = [[NSMutableSet alloc] init]; + [set addObjectsFromArray: [self friendArray]]; + [set addObjectsFromArray: [self friendOfArray]]; + + return [[set allObjects] sortedArrayUsingSelector: @selector(compare:)]; + } + - (NSEnumerator *)friendOfEnumerator { *************** *** 303,308 **** [buddy _setOutgoingFriendship:YES]; [_friendSet addObject:buddy]; - [buddy release]; if(_orderedFriendArrayCache) { // The underlying set changed, so change the cache --- 321,327 ---- [buddy _setOutgoingFriendship:YES]; [_friendSet addObject:buddy]; + [buddy release]; + if(_orderedFriendArrayCache) { // The underlying set changed, so change the cache Index: LJAccount.h =================================================================== RCS file: /cvsroot/ljkit/LJKit/LJAccount.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** LJAccount.h 6 Oct 2004 08:21:31 -0000 1.7 --- LJAccount.h 10 Oct 2004 16:35:51 -0000 1.8 *************** *** 133,136 **** --- 133,152 ---- /*! + @const LJAccountWillDownloadFriendsNotification + @discussion + Posted before an account object downloads friend/group info. + The notification object is the account instance. + */ + FOUNDATION_EXPORT NSString * const LJAccountWillDownloadFriendsNotification; + + /*! + @const LJAccountDidDownloadFriendsNotification + @discussion + Posted after an account object downloads friend/group info. + The notification object is the account instance. + */ + FOUNDATION_EXPORT NSString * const LJAccountDidDownloadFriendsNotification; + + /*! @class LJAccount *************** *** 453,456 **** --- 469,480 ---- /*! + @method defaultUserPictureURL + @abstract Returns the URL of the default user picture. + @discussion + This property is preserved during archiving. + */ + - (NSString *)defaultUserPictureKeyword; + + /*! @method userPicturesMenu @abstract Returns an NSMenu of all picture keywords for the receiver. Index: LJAccount_EditFriends.h =================================================================== RCS file: /cvsroot/ljkit/LJKit/LJAccount_EditFriends.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** LJAccount_EditFriends.h 14 May 2003 05:39:39 -0000 1.1.1.1 --- LJAccount_EditFriends.h 10 Oct 2004 16:35:51 -0000 1.2 *************** *** 143,146 **** --- 143,155 ---- /*! + @method relationshipArray + @abstract Returns all the friends with which the receiver has a relationship + @discussion + In contrast to -friendArray and -friendOfArray, this method returns + a sorted array in which are mixed mutual, incoming and outgoing relationships. + */ + - (NSArray *)relationshipArray; + + /*! @method watchedCommunityArray @abstract Returns the communities the receiver is watching. Index: LJAccount.m =================================================================== RCS file: /cvsroot/ljkit/LJKit/LJAccount.m,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** LJAccount.m 6 Oct 2004 08:21:31 -0000 1.9 --- LJAccount.m 10 Oct 2004 16:35:51 -0000 1.10 *************** *** 48,51 **** --- 48,55 ---- NSString * const LJAccountDidLogoutNotification = @"LJAccountDidLogout"; + // [FS] These are handy if we're doing asynchronous login and download + NSString * const LJAccountWillDownloadFriendsNotification = @"LJAccountWillDownloadFriends"; + NSString * const LJAccountDidDownloadFriendsNotification = @"LJAccountDidDownloadFriends"; + static NSString *gClientVersion = nil; *************** *** 603,606 **** --- 607,622 ---- } + - (NSString *)defaultUserPictureKeyword { + // This may potentially be expensive + NSEnumerator *en = [[_userPicturesDictionary allKeys] objectEnumerator]; + NSURL *defaultURL = [self defaultUserPictureURL]; + NSString *key; + while(key = [en nextObject]) { + if([[_userPicturesDictionary objectForKey: key] isEqualTo: defaultURL]) + return key; + } + return nil; + } + - (NSMenu *)userPicturesMenu { *************** *** 761,763 **** --- 777,793 ---- } + // [FS] KVO - there may be simplifcations to be made here. + + (BOOL)automaticallyNotifiesObserversForKey:(NSString *)theKey { + BOOL automatic; + if ([theKey isEqualToString:@"friendArray"]) { + automatic=NO; + } + else if ([theKey isEqualToString:@"groupArray"]) { + automatic=NO; + } + else { + automatic=[super automaticallyNotifiesObserversForKey:theKey]; + } + return automatic; + } @end |