From ee22964c4952c435a290002e2f0aab327eaa2ebc Mon Sep 17 00:00:00 2001 From: Bruno Deferrari Date: Wed, 12 Nov 2008 00:56:01 -0200 Subject: [PATCH] irc.client: correctly handle multiple name-replys --- extra/irc/client/client-tests.factor | 14 ++++++++++++++ extra/irc/client/client.factor | 20 ++++++++++++++++---- extra/irc/messages/messages.factor | 5 +++++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/extra/irc/client/client-tests.factor b/extra/irc/client/client-tests.factor index 3cf51ecc42..327bfc6292 100644 --- a/extra/irc/client/client-tests.factor +++ b/extra/irc/client/client-tests.factor @@ -169,6 +169,20 @@ M: mb-writer dispose drop ; ] unit-test ] with-irc +[ { H{ { "factorbot" +operator+ } { "ircuser" +normal+ } } } [ + "#factortest" + H{ { "ircuser" +normal+ } } clone >>participants + [ %add-named-chat ] keep + ":ircserver.net 353 factorbot @ #factortest :@factorbot " %push-line + ":ircserver.net 353 factorbot @ #factortest :ircuser2 " %push-line + ":ircserver.net 366 factorbot #factortest :End of /NAMES list." %push-line + ":ircserver.net 353 factorbot @ #factortest :@factorbot " %push-line + ":ircserver.net 353 factorbot @ #factortest :ircuser " %push-line + ":ircserver.net 366 factorbot #factortest :End of /NAMES list." %push-line + participants>> + ] unit-test +] with-irc + ! Namelist change notification [ { T{ participant-changed f f f f } } [ "#factortest" [ %add-named-chat ] keep diff --git a/extra/irc/client/client.factor b/extra/irc/client/client.factor index d24d0c615f..be600133b7 100755 --- a/extra/irc/client/client.factor +++ b/extra/irc/client/client.factor @@ -32,7 +32,7 @@ TUPLE: irc-client profile stream in-messages out-messages TUPLE: irc-chat in-messages client ; TUPLE: irc-server-chat < irc-chat ; -TUPLE: irc-channel-chat < irc-chat name password timeout participants ; +TUPLE: irc-channel-chat < irc-chat name password timeout participants clean-participants ; TUPLE: irc-nick-chat < irc-chat name ; SYMBOL: +server-chat+ @@ -55,7 +55,7 @@ SYMBOL: +nick+ f irc-server-chat boa ; : ( name -- irc-channel-chat ) - [ f ] dip f 60 seconds H{ } clone + [ f ] dip f 60 seconds H{ } clone t irc-channel-chat boa ; : ( name -- irc-nick-chat ) @@ -246,12 +246,24 @@ M: mode process-message ( mode -- ) trailing>> [ blank? ] trim " " split [ >nick/mode 2array ] map >hashtable ; +: maybe-clean-participants ( channel-chat -- ) + dup clean-participants>> [ + H{ } clone >>participants f >>clean-participants + ] when drop ; + M: names-reply process-message [ names-reply>participants ] [ channel>> chat> ] bi [ - [ (>>participants) ] - [ [ f f f ] dip name>> to-chat ] bi + [ maybe-clean-participants ] + [ participants>> 2array assoc-combine ] + [ (>>participants) ] tri ] [ drop ] if* ; +M: end-of-names process-message + channel>> chat> [ + t >>clean-participants + [ f f f ] dip name>> to-chat + ] when* ; + ! ====================================== ! Client message handling ! ====================================== diff --git a/extra/irc/messages/messages.factor b/extra/irc/messages/messages.factor index 32533c102a..bea9bf37b1 100755 --- a/extra/irc/messages/messages.factor +++ b/extra/irc/messages/messages.factor @@ -20,6 +20,7 @@ TUPLE: nick-in-use < irc-message name ; TUPLE: notice < irc-message type ; TUPLE: mode < irc-message name mode parameter ; TUPLE: names-reply < irc-message who channel ; +TUPLE: end-of-names < irc-message who channel ; TUPLE: unhandled < irc-message ; : ( command parameters trailing -- irc-message ) @@ -85,6 +86,9 @@ M: nick-in-use >>command-parameters ( nick-in-use params -- nick-in-use ) M: names-reply >>command-parameters ( names-reply params -- names-reply ) first3 nip [ >>who ] [ >>channel ] bi* ; +M: end-of-names >>command-parameters ( names-reply params -- names-reply ) + first2 [ >>who ] [ >>channel ] bi* ; + M: mode >>command-parameters ( mode params -- mode ) dup length 3 = [ first3 [ >>name ] [ >>mode ] [ >>parameter ] tri* @@ -159,6 +163,7 @@ M: sender-in-prefix irc-message-sender ( sender-in-prefix -- sender ) { "001" [ logged-in ] } { "433" [ nick-in-use ] } { "353" [ names-reply ] } + { "366" [ end-of-names ] } { "JOIN" [ join ] } { "PART" [ part ] } { "NICK" [ nick ] } -- 2.34.1