Changeset 3588

Show
Ignore:
Timestamp:
02/25/07 18:03:42 (2 years ago)
Author:
jmmv
Message:

Add support to handle nickname changes of the local user and remote users.

OK'ed by timothy@.

Files:

Legend:

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

    r3585 r3588  
    4646#import "ICBPacket.h" 
    4747#import "InterThreadMessaging.h" 
     48#import "MVUtilities.h" 
    4849#import "NSStringAdditions.h" 
    4950#import "NSNotificationAdditions.h" 
     
    6465                 withPassphrase:(NSString *) passphrase 
    6566             alreadyJoined:(BOOL) joined; 
     67- (void) _updateKnownUser:(MVChatUser *) user 
     68         withNewNickname:(NSString *) newNickname; 
    6669@end 
    6770 
     
    141144 
    142145        if( ! [newNickname isEqualToString:_nickname] ) { 
    143                 id old = _nickname; 
    144                 _nickname = [newNickname copyWithZone:nil]; 
    145                 [old release]; 
    146  
    147146                if( [self isConnected] ) 
    148147                        [self performSelector:@selector( ctsCommandName: ) 
    149                               withObject:_nickname inThread:_connectionThread]; 
     148                              withObject:newNickname inThread:_connectionThread]; 
     149                else 
     150                        MVSafeCopyAssign( &_nickname, newNickname ); 
    150151        } 
    151152} 
     
    238239- (void) sendRawMessage:(id) raw immediately:(BOOL) now { 
    239240        NSParameterAssert( raw ); 
    240         NSParameterAssert( [raw isKindOfClass:[NSData class]] || 
    241                            [raw isKindOfClass:[NSString class]] ); 
     241         
     242        // XXX Colloquy assumes in multiple places that sendRawMessage can 
     243        // take a plain string and send it to the server as a valid message. 
     244        // This is not the case for ICB, nor it is a proper abstraction 
     245        // because different protocols need not share the same protocol syntax. 
     246        // We simply discard such messages at the moment until the code in 
     247        // the upper layers is "corrected". 
     248        if( [raw isKindOfClass:[NSString class]] ) { 
     249                NSLog(@"MVICBChatConnection: sendRawMessage ignored message %@", 
     250                      raw); 
     251                return; 
     252        } 
     253 
     254        NSParameterAssert( [raw isKindOfClass:[NSData class]] ); 
    242255 
    243256        if( now ) { 
     
    547560                         [oldroom release]; 
    548561                } 
     562        } 
     563} 
     564 
     565#pragma mark Users handling 
     566 
     567- (void) _updateKnownUser:(MVChatUser *) user 
     568         withNewNickname:(NSString *) newNickname { 
     569        @synchronized( _knownUsers ) { 
     570                [user retain]; 
     571                [_knownUsers removeObjectForKey:[user uniqueIdentifier]]; 
     572                [user _setUniqueIdentifier:[newNickname lowercaseString]]; 
     573                [user _setNickname:newNickname]; 
     574                [_knownUsers setObject:user forKey:[user uniqueIdentifier]]; 
     575                [user release]; 
    549576        } 
    550577} 
     
    10041031} 
    10051032 
     1033- (void) stcStatusPacketName:(NSArray *) fields { 
     1034        NSString *msg = [fields objectAtIndex:1]; 
     1035 
     1036        NSRange r; 
     1037 
     1038        r = [msg rangeOfString:@" changed nickname to "]; 
     1039        if( r.location != NSNotFound ) { 
     1040                NSString *oldnick = [msg substringToIndex:r.location]; 
     1041                NSString *newnick = [msg substringFromIndex:r.location + r.length]; 
     1042 
     1043                MVChatUser *who = [self chatUserWithUniqueIdentifier:oldnick]; 
     1044                if( [who isLocalUser] ) { 
     1045                        MVSafeCopyAssign( &_nickname, newnick ); 
     1046                        [who _setUniqueIdentifier:[newnick lowercaseString]]; 
     1047 
     1048                        [[NSNotificationCenter defaultCenter] 
     1049                         postNotificationOnMainThreadWithName:MVChatConnectionNicknameAcceptedNotification 
     1050                         object:self userInfo:nil]; 
     1051                } else { 
     1052                        [self _updateKnownUser:who withNewNickname:newnick]; 
     1053 
     1054                        [[NSNotificationCenter defaultCenter] 
     1055                         postNotificationOnMainThreadWithName:MVChatUserNicknameChangedNotification 
     1056                         object:who 
     1057                         userInfo:[NSDictionary dictionaryWithObjectsAndKeys:oldnick, @"oldNickname", nil]]; 
     1058                } 
     1059        } 
     1060} 
     1061 
    10061062- (void) stcStatusPacketNoPass:(NSArray *) fields { 
    10071063}