Changeset 3192
- Timestamp:
- 04/11/06 02:12:40 (2 years ago)
- Files:
-
- trunk/Chat Core/MVChatConnection.m (modified) (3 diffs)
- trunk/Chat Core/MVChatConnectionPrivate.h (modified) (1 diff)
- trunk/Chat Core/MVIRCChatConnection.h (modified) (1 diff)
- trunk/Chat Core/MVIRCChatConnection.m (modified) (8 diffs)
- trunk/Controllers/MVBuddyListController.m (modified) (3 diffs)
- trunk/Models/JVBuddy.h (modified) (2 diffs)
- trunk/Models/JVBuddy.m (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Chat Core/MVChatConnection.m
r3190 r3192 898 898 #pragma mark - 899 899 900 - (MVChatUserWatchRule *) _watchRuleMatchingUser:(MVChatUser *) user { 900 - (unsigned int) _watchRulesMatchingUser:(MVChatUser *) user { 901 unsigned int count = 0; 901 902 @synchronized( _chatUserWatchRules ) { 902 903 NSEnumerator *enumerator = [_chatUserWatchRules objectEnumerator]; … … 904 905 while( ( rule = [enumerator nextObject] ) ) { 905 906 if( [rule matchChatUser:user] ) 906 return rule;907 count++; 907 908 } 908 909 } 909 910 910 return nil;911 return count; 911 912 } 912 913 913 914 - (void) _sendPossibleOnlineNotificationForUser:(MVChatUser *) user { 914 915 if( [user _onlineNotificationSent] ) return; 915 if( [user isWatched] || [self _watchRule MatchingUser:user] ) {916 if( [user isWatched] || [self _watchRulesMatchingUser:user] ) { 916 917 [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:MVChatConnectionWatchedUserOnlineNotification object:user userInfo:nil]; 917 918 [user _setOnlineNotificationSent:YES]; … … 921 922 - (void) _sendPossibleOfflineNotificationForUser:(MVChatUser *) user { 922 923 if( ! [user _onlineNotificationSent] ) return; 923 if( [user isWatched] || [self _watchRuleMatchingUser:user]) {924 if( [user isWatched] ) { 924 925 [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:MVChatConnectionWatchedUserOfflineNotification object:user userInfo:nil]; 925 926 [user _setOnlineNotificationSent:NO]; trunk/Chat Core/MVChatConnectionPrivate.h
r3186 r3192 13 13 - (void) _removeJoinedRoom:(MVChatRoom *) room; 14 14 15 - ( MVChatUserWatchRule *) _watchRuleMatchingUser:(MVChatUser *) user;15 - (unsigned int) _watchRulesMatchingUser:(MVChatUser *) user; 16 16 - (void) _sendPossibleOnlineNotificationForUser:(MVChatUser *) user; 17 17 - (void) _sendPossibleOfflineNotificationForUser:(MVChatUser *) user; trunk/Chat Core/MVIRCChatConnection.h
r3186 r3192 17 17 NSTimer *_sendQueueTimer; 18 18 NSMutableDictionary *_knownUsers; 19 NSMutableSet *_matchedUsers; 19 20 NSMutableSet *_fileTransfers; 20 21 NSString *_server; trunk/Chat Core/MVIRCChatConnection.m
r3190 r3192 992 992 #pragma mark - 993 993 994 - (void) _whoisWatchedUsers { 994 - (unsigned int) _watchRulesMatchingUser:(MVChatUser *) user { 995 if( ! _matchedUsers ) _matchedUsers = [[NSMutableSet allocWithZone:nil] initWithCapacity:25]; 996 997 unsigned int count = 0; 995 998 @synchronized( _chatUserWatchRules ) { 996 999 NSEnumerator *enumerator = [_chatUserWatchRules objectEnumerator]; 997 1000 MVChatUserWatchRule *rule = nil; 998 999 1001 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 { 1006 1015 [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 } 1007 1025 } 1008 1026 … … 1012 1030 [self performSelector:@selector( _checkWatchedUsers ) withObject:nil afterDelay:JVWatchedUserISONDelay]; 1013 1031 1014 @synchronized( _ chatUserWatchRules ) {1015 if( ! [_chatUserWatchRules count] ) return; // nothing to do, return and wait until the next scheduled fire1032 @synchronized( _matchedUsers ) { 1033 if( ! [_matchedUsers count] ) return; // nothing to do, return and wait until the next scheduled fire 1016 1034 } 1017 1035 … … 1021 1039 _isonSentCount = 0; 1022 1040 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 "]; 1046 1057 } 1058 1059 [request appendString:nick]; 1060 [request appendString:@" "]; 1061 1062 [_lastSentIsonNicknames addObject:nick]; 1047 1063 } 1048 1064 } … … 1686 1702 #pragma mark Misc. Replies 1687 1703 1688 - (void) _handlePingWithParameters:(NSArray *) parameters fromSender:( MVChatUser *) sender {1704 - (void) _handlePingWithParameters:(NSArray *) parameters fromSender:(id) sender { 1689 1705 if( [parameters count] >= 1 ) { 1690 1706 if( [parameters count] == 1 ) [self sendRawMessageImmediatelyWithComponents:@"PONG :", [parameters objectAtIndex:0], nil]; 1691 1707 else [self sendRawMessageImmediatelyWithComponents:@"PONG ", [parameters objectAtIndex:1], @" :", [parameters objectAtIndex:0], nil]; 1708 if( [sender isKindOfClass:[MVChatUser class]] ) [self _sendPossibleOnlineNotificationForUser:sender]; 1692 1709 } 1693 1710 } … … 1697 1714 NSString *roomName = [self _stringFromPossibleData:[parameters objectAtIndex:1]]; 1698 1715 [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:MVChatRoomInvitedNotification object:self userInfo:[NSDictionary dictionaryWithObjectsAndKeys:sender, @"user", roomName, @"room", nil]]; 1716 [self _sendPossibleOnlineNotificationForUser:sender]; 1699 1717 } 1700 1718 } … … 1705 1723 NSString *oldNickname = [[sender nickname] retain]; 1706 1724 NSString *oldIdentifier = [[sender uniqueIdentifier] retain]; 1707 MVChatUserWatchRule *originalRule = ( [sender isWatched] ? [self _watchRuleMatchingUser:sender] : nil );1708 1725 1709 1726 if( [sender status] != MVChatUserAwayStatus ) … … 1735 1752 [oldIdentifier release]; 1736 1753 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]; 1751 1755 } 1752 1756 } … … 1771 1775 if( ! [user dateConnected] ) [user _setDateConnected:[NSDate date]]; 1772 1776 [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]; 1774 1785 if( ! [user dateDisconnected] ) [user _setDateDisconnected:[NSDate date]]; 1775 1786 [self _sendPossibleOfflineNotificationForUser:user]; 1776 1787 } 1777 } 1778 1779 if( ! _isonSentCount ) { 1788 1780 1789 [_lastSentIsonNicknames release]; 1781 1790 _lastSentIsonNicknames = nil; trunk/Controllers/MVBuddyListController.m
r3190 r3192 166 166 167 167 while( ( buddy = [enumerator nextObject] ) ) 168 if( [[buddy onlineUsers] containsObject:user] )168 if( [[buddy users] containsObject:user] ) 169 169 return buddy; 170 170 … … 641 641 } else if( [[column identifier] isEqualToString:@"switch"] ) { 642 642 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]; 648 644 649 645 if( [users count] >= 2 ) { … … 685 681 if( row == -1 || row >= [_buddyOrder count] ) return; 686 682 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]; 691 684 692 685 NSMutableArray *ordered = nil; trunk/Models/JVBuddy.h
r3190 r3192 25 25 NSMutableArray *_rules; 26 26 NSMutableArray *_users; 27 NSMutableSet *_onlineUsers;28 27 MVChatUser *_activeUser; 29 28 } … … 53 52 54 53 - (NSArray *) users; 55 - (NSSet *) onlineUsers;56 54 57 55 - (void) addWatchRule:(MVChatUserWatchRule *) rule; trunk/Models/JVBuddy.m
r3190 r3192 36 36 _rules = [[NSMutableArray allocWithZone:nil] initWithCapacity:10]; 37 37 _users = [[NSMutableArray allocWithZone:nil] initWithCapacity:5]; 38 _onlineUsers = [[NSMutableSet allocWithZone:nil] initWithCapacity:5];39 38 _activeUser = nil; 40 39 … … 64 63 [_rules release]; 65 64 [_users release]; 66 [_onlineUsers release];67 65 [_activeUser release]; 68 66 … … 70 68 _users = nil; 71 69 _rules = nil; 72 _onlineUsers = nil;73 70 _activeUser = nil; 74 71 … … 162 159 163 160 - (BOOL) isOnline { 164 return ( [_ onlineUsers count] > 0 ? YES : NO );161 return ( [_users count] > 0 ? YES : NO ); 165 162 } 166 163 … … 206 203 } 207 204 208 - (NSSet *) onlineUsers {209 return _onlineUsers;210 }211 212 205 #pragma mark - 213 206 … … 418 411 - (void) _buddyOnline:(NSNotification *) notification { 419 412 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]; 422 415 423 416 if( [self status] != MVChatUserAvailableStatus || [self status] != MVChatUserAwayStatus ) [self setActiveUser:user]; 424 417 if( cameOnline ) [[NSNotificationCenter defaultCenter] postNotificationName:JVBuddyCameOnlineNotification object:self userInfo:nil]; 425 [[NSNotificationCenter defaultCenter] postNotificationName:JVBuddyUserCameOnlineNotification object:self userInfo:[NSDictionary dictionaryWithObjectsAndKeys:user, @"user", nil]];426 418 } 427 419 428 420 - (void) _buddyOffline:(NSNotification *) notification { 429 421 MVChatUser *user = [notification object]; 430 431 [_onlineUsers removeObject:user]; 422 [_users removeObject:user]; 432 423 433 424 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]; 441 430 } 442 431 … … 473 462 - (void) _disconnected:(NSNotification *) notification { 474 463 MVChatConnection *connection = [notification object]; 475 NSEnumerator *enumerator = [[[_ onlineUsers copy] autorelease] objectEnumerator];464 NSEnumerator *enumerator = [[[_users copy] autorelease] objectEnumerator]; 476 465 MVChatUser *user = nil; 477 466 478 467 while( ( user = [enumerator nextObject] ) ) { 479 468 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]; 482 471 } 483 472 } … … 523 512 - (NSArray *) onlineNicknamesArray { 524 513 NSMutableArray *ret = [NSMutableArray arrayWithCapacity:[_users count]]; 525 NSEnumerator *enumerator = [_ onlineUsers objectEnumerator];514 NSEnumerator *enumerator = [_users objectEnumerator]; 526 515 NSURL *nick = nil; 527 516
