]> id.pley.net Git - textual_plugins.git/commitdiff
Retain existing nickname suffixes when adding idle suffix. master
authorJer Noble <jer.noble@apple.com>
Tue, 26 Mar 2013 18:35:07 +0000 (11:35 -0700)
committerJer Noble <jer.noble@apple.com>
Tue, 26 Mar 2013 18:35:07 +0000 (11:35 -0700)
BetterAway/BetterAway/TPIBetterAway.m

index e9c1b8ef3d0be636441b8a8f55e2caab9d451aaf..b33f610042cd4585624cdf54fa536a37ff8511b7 100644 (file)
@@ -44,20 +44,38 @@ static NSString* kBetterAwayIdleCommand = @"betteraway";
     [_idleSuffix release];
     _idleSuffix = idleSuffix;
     [[NSUserDefaults standardUserDefaults] setObject:idleSuffix forKey:kBetterAwayIdleSuffix];
     [_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
 {
 }
 
 #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
 {
 }
 
 - (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 --
 }
 
 #pragma mark -- Plugin API --
@@ -70,13 +88,13 @@ static NSString* kBetterAwayIdleCommand = @"betteraway";
                                  message:(NSString *)messageString
                                  command:(NSString *)commandString
 {
                                  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])
         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];
         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]];
         }
     }
 }
         }
     }
 }