From 182774ba6ced12ce95be5981dfe88549d3d5ce39 Mon Sep 17 00:00:00 2001 From: Jonathan Schleifer Date: Fri, 9 Sep 2011 21:24:18 +0000 Subject: [PATCH] Handle nickname changes. FossilOrigin-Name: 7b1c2b91a430c3744d650d3305e867008bc8173de9ed6fdc208b4d7b1f736da9 --- src/IRCConnection.h | 3 +++ src/IRCConnection.m | 20 ++++++++++++++++++++ tests/test.m | 7 +++++++ 3 files changed, 30 insertions(+) diff --git a/src/IRCConnection.h b/src/IRCConnection.h index e5351a0..85c9343 100644 --- a/src/IRCConnection.h +++ b/src/IRCConnection.h @@ -43,6 +43,9 @@ didSeeUser: (IRCUser*)user leaveChannel: (IRCChannel*)channel withReason: (OFString*)reason; +- (void)connection: (IRCConnection*)connection + didSeeUser: (IRCUser*)user + changeNicknameTo: (OFString*)nickname; - (void)connection: (IRCConnection*)connection didSeeUserQuit: (IRCUser*)user withReason: (OFString*)reason; diff --git a/src/IRCConnection.m b/src/IRCConnection.m index 2c16495..50405b6 100644 --- a/src/IRCConnection.m +++ b/src/IRCConnection.m @@ -272,6 +272,26 @@ continue; } + /* NICK */ + if ([action isEqual: @"NICK"] && split.count == 3) { + OFString *who = [split objectAtIndex: 0]; + OFString *newNickname = [split objectAtIndex: 2]; + IRCUser *user; + + who = [who substringWithRange: + of_range(1, who.length - 1)]; + newNickname = [newNickname substringWithRange: + of_range(1, newNickname.length - 1)]; + + user = [IRCUser IRCUserWithString: who]; + + if ([delegate respondsToSelector: + @selector(connection:didSeeUser:changeNicknameTo:)]) + [delegate connection: self + didSeeUser: user + changeNicknameTo: newNickname]; + } + /* PRIVMSG */ if ([action isEqual: @"PRIVMSG"] && split.count >= 4) { OFString *from = [split objectAtIndex: 0]; diff --git a/tests/test.m b/tests/test.m index 2e75ad3..617a292 100644 --- a/tests/test.m +++ b/tests/test.m @@ -87,6 +87,13 @@ OF_APPLICATION_DELEGATE(TestApp) of_log(@"%@ quit (%@).", user, reason); } +- (void)connection: (IRCConnection*)connection + didSeeUser: (IRCUser*)user + changeNicknameTo: (OFString *)nickname +{ + of_log(@"%@ changed nick to %@.", user, nickname); +} + - (void)connection: (IRCConnection*)connection didReceiveMessage: (OFString*)msg fromUser: (IRCUser*)user