 : irc-message-origin ( irc-message -- name )
     dup name>> me? [ prefix>> parse-name ] [ name>> ] if ;
 
+: broadcast-message-to-listeners ( message -- )
+    irc-client> listeners>> values [ in-messages>> mailbox-put ] with each ;
+
 GENERIC: handle-incoming-irc ( irc-message -- )
 
 M: irc-message handle-incoming-irc ( irc-message -- )

    [ <inet> latin1 <client> ] irc-client boa ;

TUPLE: irc-listener in-messages out-messages ;
: <irc-listener> ( -- irc-listener )
    <mailbox> <mailbox> irc-listener boa ;

! ======================================
! Message objects
! ======================================

SINGLETON: irc-end ! Message used when the client isn't running anymore

TUPLE: irc-message line prefix command parameters trailing timestamp ;
TUPLE: logged-in < irc-message name ;

        spawn-irc
    ] with-variable ;

GENERIC: add-listener ( irc-client irc-listener -- )
M: irc-listener add-listener ( irc-client irc-listener -- )
    current-irc-client swap [ (add-listener) ] curry with-variable ;
