 
 GENERIC: handle-inbox ( tab message -- )
 
-: filter-participants ( assoc val -- alist )
-    [ >alist ] dip
-   '[ second , = ] filter ;
+: filter-participants ( pack alist val color -- )
+   '[ , = [ <label> , >>color add-gadget ] [ drop ] if ] assoc-each ;
 
 : update-participants ( tab -- )
-    [ listmodel>> ] [ listener>> participants>> ] bi
-    [ +operator+ filter-participants ]
-    [ +voice+ filter-participants ]
-    [ +normal+ filter-participants ] tri
-    append append swap set-model ;
+    [ userlist>> [ clear-gadget ] keep ]
+    [ listener>> participants>> ] bi
+    [ +operator+ green filter-participants ]
+    [ +voice+ blue filter-participants ]
+    [ +normal+ black filter-participants ] 2tri ;
 
 M: participant-changed handle-inbox
     drop update-participants ;


: <irc-channel-tab> ( listener client -- irc-tab )
    <irc-tab>
    <irc-list> [ <scroller> @right grid-add ] dip >>listmodel
    [ update-participants ] keep ;

: <irc-server-tab> ( listener client -- irc-tab )
    <irc-tab> ;

M: irc-tab graft*
    [ listener>> ] [ client>> ] bi
    add-listener ;

M: irc-tab ungraft*
    [ listener>> ] [ client>> ] bi
    remove-listener ;

: join-channel ( name ui-window -- )
    [ dup <irc-channel-listener> ] dip


TUPLE: ui-window client tabs ;

TUPLE: irc-tab < frame listener client userlist ;

: write-color ( str color -- )
    foreground associate format ;
