Changeset 3491

Show
Ignore:
Timestamp:
12/27/06 16:02:33 (2 years ago)
Author:
timothy
Message:

Some misc buddy list fixes.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Controllers/MVBuddyListController.h

    r3488 r3491  
    6464- (JVBuddy *) buddyForUser:(MVChatUser *) user; 
    6565- (NSArray *) buddies; 
    66 - (NSArray *) onlineBuddies; 
     66- (NSSet *) onlineBuddies; 
    6767 
    6868- (IBAction) showBuddyPickerSheet:(id) sender; 
  • trunk/Controllers/MVBuddyListController.m

    r3488 r3491  
    183183} 
    184184 
    185 - (NSArray *) onlineBuddies { 
    186         return [_onlineBuddies allObjects]
     185- (NSSet *) onlineBuddies { 
     186        return _onlineBuddies
    187187} 
    188188 
     
    298298        MVChatUserWatchRule *rule = [[MVChatUserWatchRule allocWithZone:nil] init]; 
    299299        [rule setNickname:[nickname stringValue]]; 
    300         [rule setApplicableServerDomains:[_addServers allObjects]]; 
     300 
     301        NSMutableArray *newServers = [[NSMutableArray allocWithZone:nil] initWithCapacity:[_addServers count]]; 
     302        NSEnumerator *enumerator = [_addServers objectEnumerator]; 
     303        NSString *server = nil; 
     304 
     305        while( ( server = [enumerator nextObject] ) ) { 
     306                unsigned int ip = 0; 
     307                BOOL ipAddress = ( sscanf( [server UTF8String], "%u.%u.%u.%u", &ip, &ip, &ip, &ip ) == 4 ); 
     308 
     309                if( ! ipAddress ) { 
     310                        NSArray *parts = [server componentsSeparatedByString:@"."]; 
     311                        unsigned count = [parts count]; 
     312                        if( count > 2 ) 
     313                                server = [NSString stringWithFormat:@"%@.%@", [parts objectAtIndex:(count - 2)], [parts objectAtIndex:(count - 1)]]; 
     314                } 
     315 
     316                [newServers addObject:server]; 
     317        } 
     318 
     319        [rule setApplicableServerDomains:newServers]; 
     320        [newServers release]; 
     321 
    301322        [buddy addWatchRule:rule]; 
    302323 
     
    624645        } else if( [[column identifier] isEqualToString:@"switch"] ) { 
    625646                JVBuddy *buddy = [_buddyOrder objectAtIndex:row]; 
    626                 id users = [buddy users]; 
     647                NSSet *users = [buddy users]; 
    627648 
    628649                if( [users count] >= 2 ) { 
     
    682703 
    683704        JVBuddy *buddy = [_buddyOrder objectAtIndex:row]; 
    684         id users = [buddy users]; 
    685  
    686         NSMutableArray *ordered = nil; 
    687         if( [users isKindOfClass:[NSArray class]] ) ordered = [users mutableCopyWithZone:nil]; 
    688         else if( [users isKindOfClass:[NSSet class]] ) ordered = [[users allObjects] mutableCopyWithZone:nil]; 
    689  
     705        NSSet *users = [buddy users]; 
     706 
     707        NSMutableArray *ordered = [[users allObjects] mutableCopyWithZone:nil]; 
    690708        [ordered sortUsingSelector:@selector( compareByNickname: )]; 
    691709 
  • trunk/Controllers/MVConnectionsController.m

    r3486 r3491  
    119119                [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector( _applicationQuitting: ) name:NSApplicationWillTerminateNotification object:nil]; 
    120120 
    121                 // do this later to catch modifier keys being held down to prevent automatic actions 
    122                 [self performSelector:@selector( _loadBookmarkList ) withObject:nil afterDelay:0.]; 
     121                [self _loadBookmarkList]; 
    123122        } 
    124123 
     
    567566        id info = nil; 
    568567 
     568        address = [address stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@". \t\n"]]; 
     569 
    569570        while( ( info = [enumerator nextObject] ) ) { 
    570571                MVChatConnection *connection = [info objectForKey:@"connection"]; 
    571                 if( [[connection server] compare:address options:( NSCaseInsensitiveSearch | NSLiteralSearch | NSBackwardsSearch | NSAnchoredSearch )] == NSOrderedSame ) { 
    572                        if( [connection isConnected] ) 
    573                                return connection; 
    574                 } 
     572                NSString *server = [connection server]; 
     573                NSRange range = [server rangeOfString:address options:( NSCaseInsensitiveSearch | NSLiteralSearch | NSBackwardsSearch | NSAnchoredSearch ) range:NSMakeRange( 0, [server length] )]; 
     574                if( range.location != NSNotFound && ( range.location == 0 || [server characterAtIndex:( range.location - 1 )] == '.' ) ) 
     575                       return connection; 
    575576        } 
    576577 
     
    583584        id info = nil; 
    584585 
    585         while( ( info = [enumerator nextObject] ) ) 
    586                 if( [[(MVChatConnection *)[info objectForKey:@"connection"] server] compare:address options:( NSCaseInsensitiveSearch | NSLiteralSearch | NSBackwardsSearch | NSAnchoredSearch )] == NSOrderedSame ) 
    587                         [ret addObject:[info objectForKey:@"connection"]]; 
     586        address = [address stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@". \t\n"]]; 
     587 
     588        while( ( info = [enumerator nextObject] ) ) { 
     589                MVChatConnection *connection = [info objectForKey:@"connection"]; 
     590                NSString *server = [connection server]; 
     591                NSRange range = [server rangeOfString:address options:( NSCaseInsensitiveSearch | NSLiteralSearch | NSBackwardsSearch | NSAnchoredSearch ) range:NSMakeRange( 0, [server length] )]; 
     592                if( range.location != NSNotFound && ( range.location == 0 || [server characterAtIndex:( range.location - 1 )] == '.' ) ) 
     593                        [ret addObject:connection]; 
     594        } 
    588595 
    589596        return ret; 
  • trunk/Models/JVBuddy.h

    r3488 r3491  
    2323        ABPerson *_person; 
    2424        NSMutableArray *_rules; 
    25         NSMutableArray *_users; 
     25        NSMutableSet *_users; 
    2626        MVChatUser *_activeUser; 
    2727        NSImage *_picture; 
     
    5959- (NSString *) nickname; 
    6060 
    61 - (NSArray *) users; 
     61- (NSSet *) users; 
    6262 
    6363- (NSArray *) watchRules; 
  • trunk/Models/JVBuddy.m

    r3488 r3491  
    3333        if( ( self = [super init] ) ) { 
    3434                _rules = [[NSMutableArray allocWithZone:nil] initWithCapacity:5]; 
    35                 _users = [[NSMutableArray allocWithZone:nil] initWithCapacity:5]; 
     35                _users = [[NSMutableSet allocWithZone:nil] initWithCapacity:5]; 
    3636                _uniqueIdentifier = [[NSString locallyUniqueString] retain]; 
    3737 
     
    308308#pragma mark - 
    309309 
    310 - (NSArray *) users { 
     310- (NSSet *) users { 
    311311        return _users; 
    312312} 
     
    559559 
    560560        if( [[self activeUser] isEqualToChatUser:user] ) 
    561                 [self setActiveUser:[_users lastObject]]; 
     561                [self setActiveUser:[_users anyObject]]; 
    562562 
    563563        if( ! [_users count] ) [[NSNotificationCenter defaultCenter] postNotificationName:JVBuddyWentOfflineNotification object:self userInfo:nil]; 
     
    591591 
    592592        if( [[[self activeUser] connection] isEqual:connection] ) 
    593                 [self setActiveUser:[_users lastObject]]; 
     593                [self setActiveUser:[_users anyObject]]; 
    594594 
    595595        if( ! [_users count] )