Changeset 3570

Show
Ignore:
Timestamp:
01/26/07 21:45:40 (2 years ago)
Author:
timothy
Message:

Allows a user to enable/disable all notifications on a per-channel basis. At the moment, the only access is through the channel context menu. Details at http://tim.littlebluefrog.com/?p=561. Patch by tpokorny. #977

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Panels/JVChatRoomPanel.m

    r3534 r3570  
    242242        } 
    243243 
     244        [menu addItem:[NSMenuItem separatorItem]]; 
     245 
     246        item = [[NSMenuItem alloc] initWithTitle:NSLocalizedString( @"Ignore Notifications", "lists whether or not notifications are enabled") action:@selector( toggleNotifications: ) keyEquivalent:@""]; 
     247        [item setEnabled:YES]; 
     248        [item setTarget:self]; 
     249        [menu addItem:item]; 
     250        [item release]; 
     251         
    244252        return [menu autorelease]; 
    245253} 
     
    267275        } 
    268276         
    269         return YES
     277        return [super validateMenuItem: menuItem]
    270278} 
    271279 
     
    332340                [context setObject:self forKey:@"target"]; 
    333341                [context setObject:NSStringFromSelector( @selector( activate: ) ) forKey:@"action"]; 
    334                 [[JVNotificationController defaultController] performNotification:@"JVChatRoomActivity" withContextInfo:context]; 
     342                [self performNotification:@"JVChatRoomActivity" withContextInfo:context]; 
    335343        } 
    336344 
     
    342350                [context setObject:self forKey:@"target"]; 
    343351                [context setObject:NSStringFromSelector( @selector( activate: ) ) forKey:@"action"]; 
    344                 [[JVNotificationController defaultController] performNotification:@"JVChatReplyAfterAddressing" withContextInfo:context]; 
     352                [self performNotification:@"JVChatReplyAfterAddressing" withContextInfo:context]; 
    345353 
    346354                [_nextMessageAlertMembers removeObject:[message sender]]; 
     
    958966        [context setObject:self forKey:@"target"]; 
    959967        [context setObject:NSStringFromSelector( @selector( activate: ) ) forKey:@"action"]; 
    960         [[JVNotificationController defaultController] performNotification:@"JVChatMemberJoinedRoom" withContextInfo:context]; 
     968        [self performNotification:@"JVChatMemberJoinedRoom" withContextInfo:context]; 
    961969 
    962970        [listItem release]; 
     
    9931001        [context setObject:self forKey:@"target"]; 
    9941002        [context setObject:NSStringFromSelector( @selector( activate: ) ) forKey:@"action"]; 
    995         [[JVNotificationController defaultController] performNotification:@"JVChatMemberLeftRoom" withContextInfo:context]; 
     1003        [self performNotification:@"JVChatMemberLeftRoom" withContextInfo:context]; 
    9961004 
    9971005        [_preferredTabCompleteNicknames removeObject:[mbr nickname]]; 
     
    10361044        [context setObject:self forKey:@"target"]; 
    10371045        [context setObject:NSStringFromSelector( @selector( activate: ) ) forKey:@"action"]; 
    1038         [[JVNotificationController defaultController] performNotification:@"JVChatMemberKicked" withContextInfo:context]; 
     1046        [self performNotification:@"JVChatMemberKicked" withContextInfo:context]; 
    10391047 
    10401048        // auto-rejoin on kick 
     
    10901098        [context setObject:self forKey:@"target"]; 
    10911099        [context setObject:NSStringFromSelector( @selector( activate: ) ) forKey:@"action"]; 
    1092         [[JVNotificationController defaultController] performNotification:@"JVChatMemberKicked" withContextInfo:context]; 
     1100        [self performNotification:@"JVChatMemberKicked" withContextInfo:context]; 
    10931101 
    10941102        [mbr release]; 
     
    13141322                [context setObject:self forKey:@"target"]; 
    13151323                [context setObject:NSStringFromSelector( @selector( activate: ) ) forKey:@"action"]; 
    1316                 [[JVNotificationController defaultController] performNotification:notificationKey withContextInfo:context]; 
     1324                [self performNotification:notificationKey withContextInfo:context]; 
    13171325        } 
    13181326} 
  • trunk/Panels/JVDirectChatPanel.h

    r3561 r3570  
    6363- (JVMutableChatMessage *) currentMessage; 
    6464 
     65- (void) performNotification:(NSString *) identifier withContextInfo:(NSDictionary *) context; 
     66 
    6567- (unsigned int) newMessagesWaiting; 
    6668- (unsigned int) newHighlightMessagesWaiting; 
  • trunk/Panels/JVDirectChatPanel.m

    r3561 r3570  
    462462        [menu addItem:[NSMenuItem separatorItem]]; 
    463463 
     464        item = [[NSMenuItem alloc] initWithTitle:NSLocalizedString( @"Ignore Notifications", "lists whether or not notifications are enabled for this conversation") action:@selector( toggleNotifications: ) keyEquivalent:@""]; 
     465        [item setTarget:self]; 
     466        [menu addItem:item]; 
     467        [item release]; 
     468         
     469        [menu addItem:[NSMenuItem separatorItem]]; 
     470 
    464471        if( [[[self windowController] allChatViewControllers] count] > 1 ) { 
    465472                item = [[NSMenuItem alloc] initWithTitle:NSLocalizedString( @"Detach From Window", "detach from window contextual menu item title" ) action:@selector( detachView: ) keyEquivalent:@""]; 
     
    483490 
    484491        return [menu autorelease]; 
     492} 
     493 
     494- (BOOL) validateMenuItem:(NSMenuItem *) menuItem { 
     495        if( [menuItem action] == @selector( toggleNotifications: ) ) { 
     496                if( [[self preferenceForKey:@"muted"] boolValue] ) 
     497                        [menuItem setState:NSOnState]; 
     498                else [menuItem setState:NSOffState]; 
     499        } 
     500         
     501        return YES; 
    485502} 
    486503 
     
    830847                [context setObject:self forKey:@"target"]; 
    831848                [context setObject:NSStringFromSelector( @selector( activate: ) ) forKey:@"action"]; 
    832                 [[JVNotificationController defaultController] performNotification:@"JVChatMentioned" withContextInfo:context]; 
     849                [self performNotification:@"JVChatMentioned" withContextInfo:context]; 
    833850        } 
    834851 
     
    839856                else [context setObject:[NSString stringWithFormat:NSLocalizedString( @"%@'s message was ignored.", "direct chat user ignored bubble text" ), user] forKey:@"description"]; 
    840857                [context setObject:[NSImage imageNamed:@"activity"] forKey:@"image"]; 
    841                 [[JVNotificationController defaultController] performNotification:( ( [cmessage ignoreStatus] == JVUserIgnored ) ? @"JVUserIgnored" : @"JVMessageIgnored" ) withContextInfo:context]; 
     858                [self performNotification:( ( [cmessage ignoreStatus] == JVUserIgnored ) ? @"JVUserIgnored" : @"JVMessageIgnored" ) withContextInfo:context]; 
    842859        } 
    843860 
     
    889906                        [context setObject:self forKey:@"target"]; 
    890907                        [context setObject:NSStringFromSelector( @selector( activate: ) ) forKey:@"action"]; 
    891                         [[JVNotificationController defaultController] performNotification:@"JVChatFirstMessage" withContextInfo:context]; 
     908                        [self performNotification:@"JVChatFirstMessage" withContextInfo:context]; 
    892909                } else if( [message ignoreStatus] == JVNotIgnored ) { 
    893910                        NSMutableDictionary *context = [NSMutableDictionary dictionary]; 
     
    899916                        [context setObject:self forKey:@"target"]; 
    900917                        [context setObject:NSStringFromSelector( @selector( activate: ) ) forKey:@"action"]; 
    901                         [[JVNotificationController defaultController] performNotification:@"JVChatAdditionalMessages" withContextInfo:context]; 
     918                        [self performNotification:@"JVChatAdditionalMessages" withContextInfo:context]; 
    902919                } 
    903920        } 
     
    944961- (JVMutableChatMessage *) currentMessage { 
    945962        return _currentMessage; 
     963} 
     964 
     965#pragma mark - 
     966#pragma mark Notifications Handling 
     967 
     968/** 
     969 * This method should be used to handle all notification processing. It will check to see if 
     970 * notifications have been muted for the given chat room, and if they have, it will not pass 
     971 * the notification request on to the JVNotificationController. 
     972 */ 
     973- (void) performNotification:(NSString *) identifier withContextInfo:(NSDictionary *) context { 
     974        if( ![[self preferenceForKey:@"muted"] boolValue] ) 
     975                [[JVNotificationController defaultController] performNotification:identifier withContextInfo:context]; 
     976} 
     977 
     978/** 
     979 * Toggles notifications (this is for private, direct user-user chats) 
     980 */ 
     981- (IBAction) toggleNotifications:(id) sender { 
     982        if( [self preferenceForKey:@"muted"] == [NSNumber numberWithBool:YES] ) 
     983                [self setPreference:[NSNumber numberWithBool:NO] forKey:@"muted"]; 
     984        else [self setPreference:[NSNumber numberWithBool:YES] forKey:@"muted"]; 
    946985} 
    947986