Changeset 3597

Show
Ignore:
Timestamp:
03/04/07 12:14:06 (2 years ago)
Author:
jmmv
Message:

Implement support for ICB bricks.

In order to do this, some generic changes are needed. For example, this
adds a 'sendUserCommand' method to the chat connections that allows the
user interface to send a command to the server directly, but permits the
connection to process it first. This is meant to replace sendRawMessage
in almost all cases. This way, ICB can handle the common "/brick" command
and send it to the server as needed, yet other protocols don't have to
handle it in any way.

Unfortunately, this adds ICB-specific features (bricks) to generic
interfaces. But they currently contain stuff such as "modes" and "bans",
which are also specific to some protocols, so it's not a very big deal.

Reviewed by timothy@ and fixed according to his comments.

Files:

Legend:

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

    r3582 r3597  
    5151_MVChatRoomUserBanRemovedNotification 
    5252_MVChatRoomUserBannedNotification 
     53_MVChatRoomUserBrickedNotification 
    5354_MVChatRoomUserJoinedNotification 
    5455_MVChatRoomUserKickedNotification 
  • trunk/Chat Core/MVChatConnection.h

    r3593 r3597  
    4949        MVChatConnectionBannedFromServerError = -13, 
    5050        MVChatConnectionServerPasswordIncorrectError = -14, 
    51         MVChatConnectionProtocolError = -15 
     51        MVChatConnectionProtocolError = -15, 
     52        MVChatConnectionOutOfBricksError = -16 
    5253} MVChatConnectionError; 
    5354 
     
    351352#pragma mark - 
    352353 
     354- (void) sendUserCommand:(NSString *) command withArguments:(NSString *) args; 
     355 
     356#pragma mark - 
     357 
    353358- (void) sendRawMessage:(id) raw; 
    354359- (void) sendRawMessage:(id) raw immediately:(BOOL) now; 
  • trunk/Chat Core/MVChatConnection.m

    r3582 r3597  
    497497#pragma mark - 
    498498 
     499- (void) sendUserCommand:(NSString *) command withArguments:(NSString *) args { 
     500// subclass this method 
     501        [self doesNotRecognizeSelector:_cmd]; 
     502} 
     503 
     504#pragma mark - 
     505 
    499506- (void) sendRawMessage:(id) raw { 
    500507        [self sendRawMessage:raw immediately:NO]; 
  • trunk/Chat Core/MVChatRoom.h

    r3589 r3597  
    4343extern NSString *MVChatRoomUserBanRemovedNotification; 
    4444extern NSString *MVChatRoomUserModeChangedNotification; 
     45extern NSString *MVChatRoomUserBrickedNotification; 
    4546 
    4647extern NSString *MVChatRoomGotMessageNotification; 
  • trunk/Chat Core/MVChatRoom.m

    r3590 r3597  
    3030NSString *MVChatRoomUserBanRemovedNotification = @"MVChatRoomUserBanRemovedNotification"; 
    3131NSString *MVChatRoomUserModeChangedNotification = @"MVChatRoomUserModeChangedNotification"; 
     32NSString *MVChatRoomUserBrickedNotification = @"MVChatRoomUserBrickedNotification"; 
    3233 
    3334NSString *MVChatRoomGotMessageNotification = @"MVChatRoomGotMessageNotification"; 
  • trunk/Chat Core/MVICBChatConnection.m

    r3594 r3597  
    258258} 
    259259 
     260- (void) sendUserCommand:(NSString *) command withArguments:(NSString *) args { 
     261        if( [command compare:@"brick" ] == 0 ) { 
     262                [self ctsCommandPersonal:@"server" withMessage:[NSString stringWithFormat:@"%@ %@", command, args]]; 
     263        } else { 
     264                // XXX Unknown command. 
     265        } 
     266} 
     267 
    260268- (void) sendRawMessage:(id) raw immediately:(BOOL) now { 
    261269        NSParameterAssert( raw ); 
     
    887895                          withObject:nil waitUntilDone:NO]; 
    888896                } 
     897        } else if( [message compare:@"You are out of bricks."] == 0 ) { 
     898                NSError *error = [NSError errorWithDomain:MVChatConnectionErrorDomain 
     899                                                          code:MVChatConnectionOutOfBricksError 
     900                                                                  userInfo:nil]; 
     901                [self performSelectorOnMainThread:@selector( _postError: ) 
     902                      withObject:error waitUntilDone:NO]; 
    889903        } else if( [message compare:@"You aren't the moderator."] == 0 ) { 
    890904                // XXX 
     
    10771091         object:_room 
    10781092         userInfo:[NSDictionary dictionaryWithObjectsAndKeys:sender, @"user", nil]]; 
     1093} 
     1094 
     1095- (void) stcStatusPacketFYI:(NSArray *) fields { 
     1096        NSString *msg = [fields objectAtIndex:1]; 
     1097         
     1098        NSRange r; 
     1099         
     1100        if( [msg compare:@"A brick flies off into the ether."] == 0 ) { 
     1101                [[NSNotificationCenter defaultCenter] 
     1102                 postNotificationOnMainThreadWithName:MVChatRoomUserBrickedNotification 
     1103                 object:_room userInfo:nil]; 
     1104        } else if( hasSubstring(msg, @" has been bricked.", &r) ) { 
     1105                NSString *nick = [msg substringToIndex:r.location]; 
     1106                MVChatUser *who = [self chatUserWithUniqueIdentifier:nick]; 
     1107 
     1108                [[NSNotificationCenter defaultCenter] 
     1109                 postNotificationOnMainThreadWithName:MVChatRoomUserBrickedNotification 
     1110                 object:_room 
     1111                 userInfo:[NSDictionary dictionaryWithObjectsAndKeys:who, @"user", nil]]; 
     1112        } else { 
     1113                MVChatUser *user = [self chatUserWithUniqueIdentifier:@"server"]; 
     1114                NSData *msgdata = [NSData dataWithBytes:[msg cString] length:[msg length]]; 
     1115 
     1116                NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys: 
     1117                                                                  msgdata, @"message", 
     1118                                                                  [NSString locallyUniqueString], @"identifier", 
     1119                                                                  @"yes", @"notice", 
     1120                                                                  nil]; 
     1121                [[NSNotificationCenter defaultCenter] 
     1122                 postNotificationOnMainThreadWithName:MVChatConnectionGotPrivateMessageNotification 
     1123                 object:user userInfo:userInfo]; 
     1124        } 
     1125} 
     1126 
     1127- (void) stcStatusPacketMessage:(NSArray *) fields { 
     1128        NSString *msg = [fields objectAtIndex:1]; 
     1129 
     1130        /* 
     1131         * Known message notifications.  Maybe they should be handled in some 
     1132         * other way, but for now we just report these as notices: 
     1133         * 
     1134         * You owe %d bricks. 
     1135         * You have no bricks remaining. 
     1136         * You have %d bricks remaining. 
     1137         */ 
     1138 
     1139        MVChatUser *user = [self chatUserWithUniqueIdentifier:@"server"]; 
     1140        NSData *msgdata = [NSData dataWithBytes:[msg cString] length:[msg length]]; 
     1141 
     1142        NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys: 
     1143                                  msgdata, @"message", 
     1144                                                          [NSString locallyUniqueString], @"identifier", 
     1145                                                          @"yes", @"notice", 
     1146                                                          nil]; 
     1147        [[NSNotificationCenter defaultCenter] 
     1148         postNotificationOnMainThreadWithName:MVChatConnectionGotPrivateMessageNotification 
     1149         object:user userInfo:userInfo]; 
    10791150} 
    10801151 
  • trunk/Chat Core/MVIRCChatConnection.m

    r3589 r3597  
    329329- (unsigned short) serverPort { 
    330330        return _serverPort; 
     331} 
     332 
     333#pragma mark - 
     334 
     335- (void) sendUserCommand:(NSString *) command withArguments:(NSString *) args { 
     336        if( args && [args length] > 0 ) 
     337                [self sendRawMessage:[NSString stringWithFormat:@"%@ %@", command, args]]; 
     338        else 
     339                [self sendRawMessage:command]; 
    331340} 
    332341 
  • trunk/Chat Core/MVSILCChatConnection.m

    r3530 r3597  
    12251225#pragma mark - 
    12261226 
     1227- (void) sendUserCommand:(NSString *) command withArguments:(NSString *) args { 
     1228        if( args && [args length] > 0 ) 
     1229                [self sendRawMessage:[NSString stringWithFormat:@"%@ %@", command, args]]; 
     1230        else 
     1231                [self sendRawMessage:command]; 
     1232} 
     1233 
     1234#pragma mark - 
     1235 
    12271236- (void) sendRawMessage:(NSString *) raw immediately:(BOOL) now { 
    12281237        NSParameterAssert( raw != nil ); 
  • trunk/Controllers/JVChatController.m

    r3589 r3597  
    655655                        [alert runModal]; 
    656656                } 
     657        } else if( [error code] == MVChatConnectionOutOfBricksError ) { 
     658                NSAlert *alert = [[[NSAlert alloc] init] autorelease]; 
     659                [alert setMessageText:[NSString stringWithFormat:NSLocalizedString( @"Out of bricks", "out of bricks alert dialog title" )]]; 
     660                [alert setInformativeText:[NSString stringWithFormat:NSLocalizedString( @"The user you specified could not be bricked because you are out of bricks. You can regain some more when somebody else bricks you.", "out of bricks alert dialog message" )]]; 
     661                [alert setAlertStyle:NSInformationalAlertStyle]; 
     662                [alert runModal]; 
    657663        } else if( [error code] == MVChatConnectionProtocolError ) { 
    658664                NSString *reason = [[error userInfo] objectForKey:@"reason"]; 
  • trunk/Controllers/MVConnectionsController.m

    r3594 r3597  
    18971897                                NSArray *results = [[MVChatPluginManager defaultManager] makePluginsPerformInvocation:invocation stoppingOnFirstSuccessfulReturn:YES]; 
    18981898                                if( ! [[results lastObject] boolValue] ) 
    1899                                         [connection sendRawMessage:[command stringByAppendingFormat:@" %@", arguments]]; 
     1899                                        [connection sendUserCommand:command withArguments:arguments]; 
    19001900                        } else if( [command length] ) { 
    1901                                 [connection sendRawMessage:command]; 
     1901                                [connection sendUserCommand:command withArguments:nil]; 
    19021902                        } 
    19031903                } 
  • trunk/Panels/JVChatConsolePanel.m

    r3582 r3597  
    360360 
    361361                                if( ! [[results lastObject] boolValue] ) 
    362                                         [[self connection] sendRawMessage:[command stringByAppendingFormat:@" %@", [arguments string]]]; 
     362                                        [[self connection] sendUserCommand:command withArguments:[arguments string]]; 
    363363                        } else { 
    364                                 [[self connection] sendRawMessage:[subMsg string]]; 
     364                                [[self connection] sendUserCommand:[subMsg string] withArguments:nil]; 
    365365                        } 
    366366                } 
  • trunk/Panels/JVChatRoomPanel.h

    r3545 r3597  
    4444- (void) kickedFromRoom:(JVChatRoomPanel *) room by:(JVChatRoomMember *) by forReason:(NSAttributedString *) reason; 
    4545 
     46- (void) userBricked:(MVChatUser *) user inRoom:(JVChatRoomPanel *) room; 
     47 
    4648- (void) topicChangedTo:(NSAttributedString *) topic inRoom:(JVChatRoomPanel *) room by:(JVChatRoomMember *) member; 
    4749@end 
  • trunk/Panels/JVChatRoomPanel.m

    r3589 r3597  
    6262                [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector( _bannedMembersSynced: ) name:MVChatRoomBannedUsersSyncedNotification object:target]; 
    6363                [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector( _memberNicknameChanged: ) name:MVChatUserNicknameChangedNotification object:nil]; 
     64                [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector( _userBricked: ) name:MVChatRoomUserBrickedNotification object:target]; 
    6465        } 
    6566 
     
    10071008        [_nextMessageAlertMembers removeObject:mbr]; 
    10081009        [_windowController reloadListItem:self andChildren:YES]; 
     1010} 
     1011 
     1012- (void) _userBricked:(NSNotification *) notification { 
     1013        MVChatUser *user = [[notification userInfo] objectForKey:@"user"]; 
     1014 
     1015        NSString *message = nil; 
     1016        NSString *ctxmessage = nil; 
     1017        if( user ) { 
     1018                if( [user isLocalUser] ) { 
     1019                        message = [NSString stringWithFormat:NSLocalizedString( @"You have been bricked.", "you have been bricked status message" )]; 
     1020                        ctxmessage = [NSString stringWithFormat:NSLocalizedString( @"You have been bricked.", "bubble message user bricked string" )]; 
     1021                } else { 
     1022                        NSString *name = [user nickname]; 
     1023                        message = [NSString stringWithFormat:NSLocalizedString( @"<span class=\"member\">%@</span> has been bricked.", "a user has been bricked status message" ), name]; 
     1024                        ctxmessage = [NSString stringWithFormat:NSLocalizedString( @"%@ has been bricked.", "bubble message user bricked string" ), name]; 
     1025                } 
     1026 
     1027                [self addEventMessageToDisplay:message withName:@"userBricked" andAttributes:[NSDictionary dictionaryWithObjectsAndKeys:user, @"who", nil]]; 
     1028        } else { 
     1029                message = [NSString stringWithFormat:NSLocalizedString( @"A brick flies off into the ether.", "a brick flies off into the ether status message" )]; 
     1030                ctxmessage = [NSString stringWithFormat:NSLocalizedString( @"A brick flies off into the ether.", "bubble message nobody bricked string" )]; 
     1031 
     1032                [self addEventMessageToDisplay:message withName:@"userBricked" andAttributes:nil]; 
     1033        } 
     1034        NSAssert( message, @"message not initialized in conditional" ); 
     1035        NSAssert( ctxmessage, @"ctxmessage not initialized in conditional" ); 
     1036 
     1037        NSMethodSignature *signature = [NSMethodSignature methodSignatureWithReturnAndArgumentTypes:@encode( void ), @encode( MVChatUser * ), @encode( JVChatRoomPanel * ), nil]; 
     1038        NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature]; 
     1039 
     1040        [invocation setSelector:@selector( userBricked:inRoom: )]; 
     1041        [invocation setArgument:&user atIndex:2]; 
     1042        [invocation setArgument:&self atIndex:3]; 
     1043 
     1044        [[MVChatPluginManager defaultManager] makePluginsPerformInvocation:invocation]; 
     1045 
     1046        NSMutableDictionary *context = [NSMutableDictionary dictionary]; 
     1047        [context setObject:NSLocalizedString( @"Chat User Bricked", "user bricked title" ) forKey:@"title"]; 
     1048        [context setObject:ctxmessage forKey:@"description"]; 
     1049        [context setObject:self forKey:@"target"]; 
     1050        [context setObject:NSStringFromSelector( @selector( activate: ) ) forKey:@"action"]; 
    10091051} 
    10101052 
  • trunk/Panels/JVDirectChatPanel.m

    r3589 r3597  
    10341034 
    10351035                                if( ! ( handled = [self processUserCommand:command withArguments:arguments] ) && [[self connection] isConnected] ) 
    1036                                         [[self connection] sendRawMessage:[command stringByAppendingFormat:@" %@", [arguments string]]]; 
     1036                                        [[self connection] sendUserCommand:command withArguments:[arguments string]]; 
    10371037                        } else { 
    10381038                                if( [[subMsg string] hasPrefix:@"//"] ) [subMsg deleteCharactersInRange:NSMakeRange( 0, 1 )]; 
  • trunk/Resources/info.colloquy.plist

    r3579 r3597  
    203203                <key>showBubbleOnlyIfBackground</key> 
    204204                <true/> 
     205        </dict> 
     206        <key>JVNotificationSettings JVChatUserBricked</key> 
     207        <dict> 
     208                <key>playSound</key> 
     209                <true/> 
     210                <key>soundPath</key> 
     211                <string>Clap.aiff</string> 
    205212        </dict> 
    206213        <key>JVNotificationSettings JVChatMentioned</key> 
  • trunk/Resources/notifications.plist

    r3579 r3597  
    176176        </dict> 
    177177        <dict> 
     178                <key>identifier</key> 
     179                <string>JVChatUserBricked</string> 
     180                <key>title</key> 
     181                <string>User Was Bricked</string> 
     182        </dict> 
     183        <dict> 
    178184                <key>seperator</key> 
    179185                <true />