Changeset 3192

Show
Ignore:
Timestamp:
04/11/06 02:12:40 (2 years ago)
Author:
timothy
Message:

More buddy list support.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Chat Core/MVChatConnection.m

    r3190 r3192  
    898898#pragma mark - 
    899899 
    900 - (MVChatUserWatchRule *) _watchRuleMatchingUser:(MVChatUser *) user { 
     900- (unsigned int) _watchRulesMatchingUser:(MVChatUser *) user { 
     901        unsigned int count = 0; 
    901902        @synchronized( _chatUserWatchRules ) { 
    902903                NSEnumerator *enumerator = [_chatUserWatchRules objectEnumerator]; 
     
    904905                while( ( rule = [enumerator nextObject] ) ) { 
    905906                        if( [rule matchChatUser:user] ) 
    906                                 return rule
     907                                count++
    907908                } 
    908909        } 
    909910 
    910         return nil
     911        return count
    911912} 
    912913 
    913914- (void) _sendPossibleOnlineNotificationForUser:(MVChatUser *) user { 
    914915        if( [user _onlineNotificationSent] ) return; 
    915         if( [user isWatched] || [self _watchRuleMatchingUser:user] ) { 
     916        if( [user isWatched] || [self _watchRulesMatchingUser:user] ) { 
    916917                [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:MVChatConnectionWatchedUserOnlineNotification object:user userInfo:nil]; 
    917918                [user _setOnlineNotificationSent:YES]; 
     
    921922- (void) _sendPossibleOfflineNotificationForUser:(MVChatUser *) user { 
    922923        if( ! [user _onlineNotificationSent] ) return; 
    923         if( [user isWatched] || [self _watchRuleMatchingUser:user] ) { 
     924        if( [user isWatched] ) { 
    924925                [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:MVChatConnectionWatchedUserOfflineNotification object:user userInfo:nil]; 
    925926                [user _setOnlineNotificationSent:NO]; 
  • trunk/Chat Core/MVChatConnectionPrivate.h

    r3186 r3192  
    1313- (void) _removeJoinedRoom:(MVChatRoom *) room; 
    1414 
    15 - (MVChatUserWatchRule *) _watchRuleMatchingUser:(MVChatUser *) user; 
     15- (unsigned int) _watchRulesMatchingUser:(MVChatUser *) user; 
    1616- (void) _sendPossibleOnlineNotificationForUser:(MVChatUser *) user; 
    1717- (void) _sendPossibleOfflineNotificationForUser:(MVChatUser *) user; 
  • trunk/Chat Core/MVIRCChatConnection.h

    r3186 r3192  
    1717        NSTimer *_sendQueueTimer; 
    1818        NSMutableDictionary *_knownUsers; 
     19        NSMutableSet *_matchedUsers; 
    1920        NSMutableSet *_fileTransfers; 
    2021        NSString *_server; 
  • trunk/Chat Core/MVIRCChatConnection.m

    r3190 r3192  
    992992#pragma mark - 
    993993 
    994 - (void) _whoisWatchedUsers { 
     994- (unsigned int) _watchRulesMatchingUser:(MVChatUser *) user { 
     995        if( ! _matchedUsers ) _matchedUsers = [[NSMutableSet allocWithZone:nil] initWithCapacity:25]; 
     996 
     997        unsigned int count = 0; 
    995998        @synchronized( _chatUserWatchRules ) { 
    996999                NSEnumerator *enumerator = [_chatUserWatchRules objectEnumerator]; 
    9971000                MVChatUserWatchRule *rule = nil; 
    998  
    9991001                while( ( rule = [enumerator nextObject] ) ) { 
    1000                         NSString *nick = [rule nickname]; 
    1001                         if( nick && ! [rule nicknameIsRegularExpression] ) 
    1002                                 [self sendRawMessageWithFormat:@"WHOIS %@ %1$@", nick]; 
    1003                 } 
    1004         } 
    1005  
     1002                        if( [rule matchChatUser:user] ) { 
     1003                                count++; 
     1004                                @synchronized( _matchedUsers ) { 
     1005                                        [_matchedUsers addObject:user]; 
     1006                                } 
     1007                        } 
     1008                } 
     1009        } 
     1010 
     1011        return count; 
     1012
     1013 
     1014- (void) _whoisWatchedUsers { 
    10061015        [self performSelector:@selector( _whoisWatchedUsers ) withObject:nil afterDelay:JVWatchedUserWHOISDelay]; 
     1016 
     1017        @synchronized( _matchedUsers ) { 
     1018                if( ! [_matchedUsers count] ) return; // nothing to do, return and wait until the next scheduled fire 
     1019 
     1020                NSEnumerator *enumerator = [_matchedUsers objectEnumerator]; 
     1021                MVChatUser *user = nil; 
     1022                while( ( user = [enumerator nextObject] ) ) 
     1023                        [self sendRawMessageWithFormat:@"WHOIS %@ %1$@", [user nickname]]; 
     1024        } 
    10071025} 
    10081026 
     
    10121030        [self performSelector:@selector( _checkWatchedUsers ) withObject:nil afterDelay:JVWatchedUserISONDelay]; 
    10131031 
    1014         @synchronized( _chatUserWatchRules ) { 
    1015                 if(    ! [_chatUserWatchRules count] ) return; // nothing to do, return and wait until the next scheduled fire 
     1032        @synchronized( _matchedUsers ) { 
     1033                if( ! [_matchedUsers count] ) return; // nothing to do, return and wait until the next scheduled fire 
    10161034        } 
    10171035 
     
    10211039        _isonSentCount = 0; 
    10221040 
    1023         @synchronized( _chatUserWatchRules ) { 
    1024                 [_lastSentIsonNicknames release]; 
    1025                 _lastSentIsonNicknames = [[NSMutableSet allocWithZone:nil] initWithCapacity:[_chatUserWatchRules count]]; 
    1026  
    1027                 NSEnumerator *enumerator = [_chatUserWatchRules objectEnumerator]; 
    1028                 MVChatUserWatchRule *rule = nil; 
    1029  
    1030                 while( ( rule = [enumerator nextObject] ) ) { 
    1031                         NSString *nick = [rule nickname]; 
    1032                         if( nick && ! [rule nicknameIsRegularExpression] ) { 
    1033                                 if( ( [nick length] + [request length] ) > 510 ) { 
    1034                                         [self sendRawMessage:request]; 
    1035                                         [request release]; 
    1036                                         _isonSentCount++; 
    1037  
    1038                                         request = [[NSMutableString allocWithZone:nil] initWithCapacity:510]; 
    1039                                         [request setString:@"ISON "]; 
    1040                                 } 
    1041  
    1042                                 [request appendString:nick]; 
    1043                                 [request appendString:@" "]; 
    1044  
    1045                                 [_lastSentIsonNicknames addObject:nick]; 
     1041        [_lastSentIsonNicknames release]; 
     1042        _lastSentIsonNicknames = [[NSMutableSet allocWithZone:nil] initWithCapacity:[_chatUserWatchRules count]]; 
     1043 
     1044        @synchronized( _matchedUsers ) { 
     1045                NSEnumerator *enumerator = [_matchedUsers objectEnumerator]; 
     1046                MVChatUser *user = nil; 
     1047 
     1048                while( ( user = [enumerator nextObject] ) ) { 
     1049                        NSString *nick = [user nickname]; 
     1050                        if( ( [nick length] + [request length] ) > 510 ) { 
     1051                                [self sendRawMessage:request]; 
     1052                                [request release]; 
     1053                                _isonSentCount++; 
     1054 
     1055                                request = [[NSMutableString allocWithZone:nil] initWithCapacity:510]; 
     1056                                [request setString:@"ISON "]; 
    10461057                        } 
     1058 
     1059                        [request appendString:nick]; 
     1060                        [request appendString:@" "]; 
     1061 
     1062                        [_lastSentIsonNicknames addObject:nick]; 
    10471063                } 
    10481064        } 
     
    16861702#pragma mark Misc. Replies 
    16871703 
    1688 - (void) _handlePingWithParameters:(NSArray *) parameters fromSender:(MVChatUser *) sender { 
     1704- (void) _handlePingWithParameters:(NSArray *) parameters fromSender:(id) sender { 
    16891705        if( [parameters count] >= 1 ) { 
    16901706                if( [parameters count] == 1 ) [self sendRawMessageImmediatelyWithComponents:@"PONG :", [parameters objectAtIndex:0], nil]; 
    16911707                else [self sendRawMessageImmediatelyWithComponents:@"PONG ", [parameters objectAtIndex:1], @" :", [parameters objectAtIndex:0], nil]; 
     1708                if( [sender isKindOfClass:[MVChatUser class]] ) [self _sendPossibleOnlineNotificationForUser:sender]; 
    16921709        } 
    16931710} 
     
    16971714                NSString *roomName = [self _stringFromPossibleData:[parameters objectAtIndex:1]]; 
    16981715                [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:MVChatRoomInvitedNotification object:self userInfo:[NSDictionary dictionaryWithObjectsAndKeys:sender, @"user", roomName, @"room", nil]]; 
     1716                [self _sendPossibleOnlineNotificationForUser:sender]; 
    16991717        } 
    17001718} 
     
    17051723                NSString *oldNickname = [[sender nickname] retain]; 
    17061724                NSString *oldIdentifier = [[sender uniqueIdentifier] retain]; 
    1707                 MVChatUserWatchRule *originalRule = ( [sender isWatched] ? [self _watchRuleMatchingUser:sender] : nil ); 
    17081725 
    17091726                if( [sender status] != MVChatUserAwayStatus ) 
     
    17351752                [oldIdentifier release]; 
    17361753 
    1737                 MVChatUserWatchRule *newRule = ( [sender isWatched] ? [self _watchRuleMatchingUser:sender] : nil ); 
    1738                 if( originalRule && ! newRule ) { 
    1739                         if( [originalRule nickname] && ! [originalRule nicknameIsRegularExpression] ) { 
    1740                                 newRule = [originalRule copyWithZone:nil]; 
    1741                                 [newRule setNickname:[sender nickname]]; 
    1742                                 [newRule setInterim:YES]; 
    1743                                 [self addChatUserWatchRule:newRule]; 
    1744                                 [newRule release]; 
    1745  
    1746                                 if( [originalRule isInterim] ) [self removeChatUserWatchRule:originalRule]; 
    1747                         } 
    1748                 } else if( originalRule && newRule && [originalRule isInterim] ) { 
    1749                         [self removeChatUserWatchRule:originalRule]; 
    1750                 } 
     1754                [self _sendPossibleOnlineNotificationForUser:sender]; 
    17511755        } 
    17521756} 
     
    17711775                                if( ! [user dateConnected] ) [user _setDateConnected:[NSDate date]]; 
    17721776                                [self _sendPossibleOnlineNotificationForUser:user]; 
    1773                         } else { 
     1777                                [_lastSentIsonNicknames removeObject:nick]; 
     1778                        } 
     1779                } 
     1780 
     1781                if( ! _isonSentCount ) { 
     1782                        enumerator = [_lastSentIsonNicknames objectEnumerator]; 
     1783                        while( ( nick = [enumerator nextObject] ) ) { 
     1784                                MVChatUser *user = [self chatUserWithUniqueIdentifier:nick]; 
    17741785                                if( ! [user dateDisconnected] ) [user _setDateDisconnected:[NSDate date]]; 
    17751786                                [self _sendPossibleOfflineNotificationForUser:user]; 
    17761787                        } 
    1777                 } 
    1778  
    1779                 if( ! _isonSentCount ) { 
     1788 
    17801789                        [_lastSentIsonNicknames release]; 
    17811790                        _lastSentIsonNicknames = nil; 
  • trunk/Controllers/MVBuddyListController.m

    r3190 r3192  
    166166 
    167167        while( ( buddy = [enumerator nextObject] ) ) 
    168                 if( [[buddy onlineUsers] containsObject:user] ) 
     168                if( [[buddy users] containsObject:user] ) 
    169169                        return buddy; 
    170170 
     
    641641        } else if( [[column identifier] isEqualToString:@"switch"] ) { 
    642642                JVBuddy *buddy = [_buddyOrder objectAtIndex:row]; 
    643                 NSSet *onlineUsers = [buddy onlineUsers]; 
    644                 id users = nil; 
    645  
    646                 if( _showOfflineBuddies ) users = [buddy users]; 
    647                 else users = onlineUsers; 
     643                id users = [buddy users]; 
    648644 
    649645                if( [users count] >= 2 ) { 
     
    685681        if( row == -1 || row >= [_buddyOrder count] ) return; 
    686682        JVBuddy *buddy = [_buddyOrder objectAtIndex:row]; 
    687         id users = nil; 
    688  
    689         if( _showOfflineBuddies ) users = [buddy users]; 
    690         else users = [buddy onlineUsers]; 
     683        id users = [buddy users]; 
    691684 
    692685        NSMutableArray *ordered = nil; 
  • trunk/Models/JVBuddy.h

    r3190 r3192  
    2525        NSMutableArray *_rules; 
    2626        NSMutableArray *_users; 
    27         NSMutableSet *_onlineUsers; 
    2827        MVChatUser *_activeUser; 
    2928} 
     
    5352 
    5453- (NSArray *) users; 
    55 - (NSSet *) onlineUsers; 
    5654 
    5755- (void) addWatchRule:(MVChatUserWatchRule *) rule; 
  • trunk/Models/JVBuddy.m

    r3190 r3192  
    3636                _rules = [[NSMutableArray allocWithZone:nil] initWithCapacity:10]; 
    3737                _users = [[NSMutableArray allocWithZone:nil] initWithCapacity:5]; 
    38                 _onlineUsers = [[NSMutableSet allocWithZone:nil] initWithCapacity:5]; 
    3938                _activeUser = nil; 
    4039 
     
    6463        [_rules release]; 
    6564        [_users release]; 
    66         [_onlineUsers release]; 
    6765        [_activeUser release]; 
    6866 
     
    7068        _users = nil; 
    7169        _rules = nil; 
    72         _onlineUsers = nil; 
    7370        _activeUser = nil; 
    7471 
     
    162159 
    163160- (BOOL) isOnline { 
    164         return ( [_onlineUsers count] > 0 ? YES : NO ); 
     161        return ( [_users count] > 0 ? YES : NO ); 
    165162} 
    166163 
     
    206203} 
    207204 
    208 - (NSSet *) onlineUsers { 
    209         return _onlineUsers; 
    210 } 
    211  
    212205#pragma mark - 
    213206 
     
    418411- (void) _buddyOnline:(NSNotification *) notification { 
    419412        MVChatUser *user = [notification object]; 
    420         BOOL cameOnline = ( ! [_onlineUsers count] ? YES : NO ); 
    421         [_onlineUsers addObject:user]; 
     413        BOOL cameOnline = ( ! [_users count] ? YES : NO ); 
     414        [_users addObject:user]; 
    422415 
    423416        if( [self status] != MVChatUserAvailableStatus || [self status] != MVChatUserAwayStatus ) [self setActiveUser:user]; 
    424417        if( cameOnline ) [[NSNotificationCenter defaultCenter] postNotificationName:JVBuddyCameOnlineNotification object:self userInfo:nil]; 
    425         [[NSNotificationCenter defaultCenter] postNotificationName:JVBuddyUserCameOnlineNotification object:self userInfo:[NSDictionary dictionaryWithObjectsAndKeys:user, @"user", nil]]; 
    426418} 
    427419 
    428420- (void) _buddyOffline:(NSNotification *) notification { 
    429421        MVChatUser *user = [notification object]; 
    430  
    431         [_onlineUsers removeObject:user]; 
     422        [_users removeObject:user]; 
    432423 
    433424        if( [[self activeUser] isEqualToChatUser:user] ) { 
    434                 if( [_onlineUsers count] ) [self setActiveUser:[_onlineUsers anyObject]]; 
    435                 else [self setActiveUser:[_users lastObject]]; 
    436         } 
    437  
    438         if( ! [_onlineUsers count] ) [[NSNotificationCenter defaultCenter] postNotificationName:JVBuddyWentOfflineNotification object:self userInfo:nil]; 
    439  
    440         [[NSNotificationCenter defaultCenter] postNotificationName:JVBuddyUserWentOfflineNotification object:self userInfo:[NSDictionary dictionaryWithObjectsAndKeys:user, @"user", nil]]; 
     425                if( [_users count] ) [self setActiveUser:[_users lastObject]]; 
     426                else [self setActiveUser:nil]; 
     427        } 
     428 
     429        if( ! [_users count] ) [[NSNotificationCenter defaultCenter] postNotificationName:JVBuddyWentOfflineNotification object:self userInfo:nil]; 
    441430} 
    442431 
     
    473462- (void) _disconnected:(NSNotification *) notification { 
    474463        MVChatConnection *connection = [notification object]; 
    475         NSEnumerator *enumerator = [[[_onlineUsers copy] autorelease] objectEnumerator]; 
     464        NSEnumerator *enumerator = [[[_users copy] autorelease] objectEnumerator]; 
    476465        MVChatUser *user = nil; 
    477466 
    478467        while( ( user = [enumerator nextObject] ) ) { 
    479468                if( [[user connection] isEqual:connection] ) { 
    480                         [_onlineUsers removeObject:user]; 
    481                         if( ! [_onlineUsers count] ) [[NSNotificationCenter defaultCenter] postNotificationName:JVBuddyWentOfflineNotification object:self userInfo:nil]; 
     469                        [_users removeObject:user]; 
     470                        if( ! [_users count] ) [[NSNotificationCenter defaultCenter] postNotificationName:JVBuddyWentOfflineNotification object:self userInfo:nil]; 
    482471                } 
    483472        } 
     
    523512- (NSArray *) onlineNicknamesArray { 
    524513        NSMutableArray *ret = [NSMutableArray arrayWithCapacity:[_users count]]; 
    525         NSEnumerator *enumerator = [_onlineUsers objectEnumerator]; 
     514        NSEnumerator *enumerator = [_users objectEnumerator]; 
    526515        NSURL *nick = nil; 
    527516