Tk Library Source Code

Artifact [1a47d3f24c]
Login

Artifact 1a47d3f24c9e5b15add4136582af4fbca86910cd:

Attachment "tkchat.NickListv3.diff" to ticket [1196567fff] added by wildcard_25 2005-05-09 14:04:34.
Index: tkchat.tcl
===================================================================
RCS file: /cvsroot/tcllib/tclapps/apps/tkchat/tkchat.tcl,v
retrieving revision 1.287
diff -u -d -r1.287 tkchat.tcl
--- tkchat.tcl	7 May 2005 20:19:06 -0000	1.287
+++ tkchat.tcl	9 May 2005 06:26:32 -0000
@@ -914,8 +914,17 @@
             set clr [getColor MainFG]
         }
     }
-    if {[lsearch -exact $Options(NickList) $nick] < 0} {
-        lappend Options(NickList) $nick
+    set match 0
+    foreach nk $Options(NickList) {
+	if { [lindex $nk 0] eq $nick } {
+	    lset Options(NickList) $match [lset nk 1 [clock seconds]]
+	    break
+	} else {
+	    incr match
+	}
+    }
+    if { $match == [llength $Options(NickList)] } {
+	lappend Options(NickList) [list $nick [clock seconds]]
         set Options(Color,$nick,Web) $clr
         set Options(Color,$nick,Inv) [::tkchat::invClr $clr]
         set Options(Color,$nick,Mine) $clr
@@ -1335,14 +1344,16 @@
 
 proc ::tkchat::addAction {w clr nick str {mark end} {timestamp 0} {extraOpts ""}} {
     global Options
-    checkNick $w $nick $clr
-    checkAlert ACTION $nick $str
     array set opts $extraOpts
-    $w config -state normal
+
     #for colors, it is better to extract the displayed nick from the one used for
     #tags.
     set displayNick $nick
     regexp {^<(.+)>$} $nick displayNick nick
+
+    checkNick $w $nick $clr
+    checkAlert ACTION $nick $str
+    $w config -state normal
     ::tkchat::InsertTimestamp $w $nick $mark $timestamp
     $w insert $mark "   * $displayNick " [list NICK NICK-$nick]
     if {[string equal $nick clock]} {
@@ -1484,14 +1495,17 @@
 proc ::tkchat::addHelp {w clr name str} {
     global Options
 
-    if {[lsearch -exact $Options(NickList) $name] >= 0} {
-	if { [string equal $name "ircbridge"] } {
-	    doIrcBridgeWhisper $clr $name $str
-	} else {
-	    # this is an incoming private message
-	    addAction $w $clr $name " whispers: $str"
+    foreach nk $Options(NickList) {
+	set nk [lindex $nk 0]
+	if { $name == $nk } {
+	    if { $name eq "ircbridge"] } {
+		doIrcBridgeWhisper $clr $name $str
+	    } else {
+		# this is an incoming private message
+		addAction $w $clr $name " whispers: $str"
+	    }
+	    return
 	}
-	return
     }
     if {[string match "->*" $name]} {
 	if { [string equal $name "->ircbridge"] } {
@@ -2286,7 +2300,8 @@
     set m .mbar.vis.nicks
     $m delete 0 end
     set cnt 0
-    foreach n [lsort -dict $::Options(NickList)] {
+    foreach n [lsort -dict -index 0 $::Options(NickList)] {
+	set n [lindex $n 0]
 	set tag NICK-$n
 	$m add checkbutton -label $n \
 	    -onval 1 -offval 0 \
@@ -3535,7 +3550,8 @@
         }
     }
     grid [label $f.offline -text "Offline Users" -font SYS] - - -
-    foreach nick [lsort -dict $Options(NickList)] {
+    foreach nick [lsort -dict -index 0 $Options(NickList)] {
+	set nick [lindex $nick 0]
         if {[lsearch -exact $Options(OnLineUsers) $nick] < 0} {
             buildRow $f $nick $nick
         }
@@ -3589,6 +3605,7 @@
     .names config -bg "#[getColor MainBG]" -fg "#[getColor MainFG]"
     $txt tag configure found -background "#[getColor SearchBG]"
     foreach nk $Options(NickList) {
+	set nk [lindex $nk 0]
         set clr [getColor $nk]
         if {$clr == ""} {
             set clr [getColor MainFG]
@@ -4271,7 +4288,7 @@
 	AutoConnect	0
 	DisplayUsers	1
 	Refresh		30
-	NickList	{}
+	NickList	{{} {}}
 	History		{}
 	AutoScroll	0
 	Geometry	600x500
@@ -4344,6 +4361,25 @@
             eval $d
         }
     }
+    # Convert old nick list to new and remove old nicks
+    set newNicks [list]
+    foreach nk $Options(NickList) {
+	if { ![string is integer -strict [lindex $nk 1]] } {
+	    set nk [list $nk]
+	}
+	if { [lindex $nk 1] eq "" } { lappend nk [clock seconds] }
+	if { [lindex $nk 1] > [clock scan "-30 day"]
+		|| [lindex $nk 0] eq $Options(Username) } {
+	    lappend newNicks $nk
+	} else {
+	    unset "Options(Color,[lindex $nk 0],Inv)"
+	    unset "Options(Color,[lindex $nk 0],Mine)"
+	    unset "Options(Color,[lindex $nk 0],Web)"
+	    unset "Options(Color,[lindex $nk 0],Which)"
+	    unset "Options(Visibility,NICK-[lindex $nk 0])"
+	}
+    }
+    set Options(NickList) $newNicks
 
     # Compatability issues...
     if {[string is integer $Options(UseJabberSSL)]} {