From: Jer Noble Date: Tue, 26 Mar 2013 18:35:07 +0000 (-0700) Subject: Retain existing nickname suffixes when adding idle suffix. X-Git-Url: http://105106.c2e0p.group/textual_plugins.git/commitdiff_plain/HEAD?ds=sidebyside Retain existing nickname suffixes when adding idle suffix. --- diff --git a/BetterAway/BetterAway/TPIBetterAway.m b/BetterAway/BetterAway/TPIBetterAway.m index e9c1b8e..b33f610 100644 --- a/BetterAway/BetterAway/TPIBetterAway.m +++ b/BetterAway/BetterAway/TPIBetterAway.m @@ -44,20 +44,38 @@ static NSString* kBetterAwayIdleCommand = @"betteraway"; [_idleSuffix release]; _idleSuffix = idleSuffix; [[NSUserDefaults standardUserDefaults] setObject:idleSuffix forKey:kBetterAwayIdleSuffix]; + + for (IRCClient* client in _world.clients) { + NSMutableString* nick = [NSMutableString stringWithString:client.localNickname]; + NSString* suffix = [@"|" stringByAppendingString:[self idleSuffix]]; + [nick replaceOccurrencesOfString:suffix withString:@"" options:0 range:NSMakeRange(0, [nick length])]; + [client changeNick:nick]; + } } #pragma mark -- NSWorkspace Notifications -- - (void)onDisplaySleep:(id)sender { - for (IRCClient* client in _world.clients) - [client changeNick:[NSString stringWithFormat:@"%@|%@", client.config.nick, [self idleSuffix]]]; + for (IRCClient* client in _world.clients) { + NSMutableString* nick = [NSMutableString stringWithString:client.localNickname]; + NSString* suffix = [@"|" stringByAppendingString:[self idleSuffix]]; + [nick replaceOccurrencesOfString:suffix withString:@"" options:0 range:NSMakeRange(0, [nick length])]; + [nick appendString:suffix]; + [client printDebugInformation:[@"BetterAway setting nickname to " stringByAppendingString:nick]]; + [client changeNick:nick]; + } } - (void)onDisplayWake:(id)sender { - for (IRCClient* client in _world.clients) - [client changeNick:client.config.nick]; + for (IRCClient* client in _world.clients) { + NSMutableString* nick = [NSMutableString stringWithString:client.localNickname]; + NSString* suffix = [@"|" stringByAppendingString:[self idleSuffix]]; + [nick replaceOccurrencesOfString:suffix withString:@"" options:0 range:NSMakeRange(0, [nick length])]; + [client printDebugInformation:[@"BetterAway setting nickname to " stringByAppendingString:nick]]; + [client changeNick:nick]; + } } #pragma mark -- Plugin API -- @@ -70,13 +88,13 @@ static NSString* kBetterAwayIdleCommand = @"betteraway"; message:(NSString *)messageString command:(NSString *)commandString { - if ([[commandString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] isEqualTo:kBetterAwayIdleCommand]) { + if ([[commandString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] compare:kBetterAwayIdleCommand options:NSCaseInsensitiveSearch] == NSOrderedSame) { NSString* idleSuffix = [messageString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; if (![idleSuffix length]) - [client printBoth:client.world.selectedChannel type:TVCLogLineSystemType text:[@"Idle suffix is currently " stringByAppendingString:[self idleSuffix]]]; + [client printDebugInformation:[@"Idle suffix is currently " stringByAppendingString:[self idleSuffix]]]; else { [self setIdleSuffix:idleSuffix]; - [client printBoth:client.world.selectedChannel type:TVCLogLineSystemType text:[@"Set idle suffix to " stringByAppendingString:idleSuffix]]; + [client printDebugInformation:[@"Set idle suffix to " stringByAppendingString:idleSuffix]]; } } }