[Tkabber-dev] r751 - in trunk/tkabber: . plugins/chat plugins/general

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Sun Oct 8 02:19:24 MSD 2006


Author: sergei
Date: 2006-10-08 02:19:08 +0400 (Sun, 08 Oct 2006)
New Revision: 751

Added:
   trunk/tkabber/plugins/chat/log_on_open.tcl
Modified:
   trunk/tkabber/ChangeLog
   trunk/tkabber/custom.tcl
   trunk/tkabber/plugins/chat/logger.tcl
   trunk/tkabber/plugins/general/sound.tcl
Log:
	* custom.tcl: Fixed duplicate parent groups (thanks to Pavel
	  Borzenkov).

	* plugins/chat/log_on_open.tcl, plugins/chat/logger.tcl,
	  plugins/general/sound.tcl: Added new plugin, which shows
	  several last logged messages in newly opened chat (not
	  groupchat) windows. Added jid attribute to log messages,
	  changed timestamps to GMT (so, existing log messages show
	  incorrect timestamps now).


Modified: trunk/tkabber/ChangeLog
===================================================================
--- trunk/tkabber/ChangeLog	2006-10-07 13:37:55 UTC (rev 750)
+++ trunk/tkabber/ChangeLog	2006-10-07 22:19:08 UTC (rev 751)
@@ -1,3 +1,15 @@
+2006-10-08  Sergei Golovan  <sgolovan at nes.ru>
+
+	* custom.tcl: Fixed duplicate parent groups (thanks to Pavel
+	  Borzenkov).
+
+	* plugins/chat/log_on_open.tcl, plugins/chat/logger.tcl,
+	  plugins/general/sound.tcl: Added new plugin, which shows
+	  several last logged messages in newly opened chat (not
+	  groupchat) windows. Added jid attribute to log messages,
+	  changed timestamps to GMT (so, existing log messages show
+	  incorrect timestamps now).
+
 2006-10-07  Sergei Golovan  <sgolovan at nes.ru>
 
 	* custom.tcl: Autosave customized variable if it has been set

Modified: trunk/tkabber/custom.tcl
===================================================================
--- trunk/tkabber/custom.tcl	2006-10-07 13:37:55 UTC (rev 750)
+++ trunk/tkabber/custom.tcl	2006-10-07 22:19:08 UTC (rev 751)
@@ -35,7 +35,7 @@
 		lappend group(subgroups,$val) [list group $id]
 		set group(subgroups,$val) [lrmdups $group(subgroups,$val)]
 		lappend group(parents,$id) $val
-		set group(parents,$val) [lrmdups $group(parents,$val)]
+		set group(parents,$id) [lrmdups $group(parents,$id)]
 		#set group(members,$val) [lrmdups $group(members,$val)]
 	    }
 	    -type {

Added: trunk/tkabber/plugins/chat/log_on_open.tcl
===================================================================
--- trunk/tkabber/plugins/chat/log_on_open.tcl	                        (rev 0)
+++ trunk/tkabber/plugins/chat/log_on_open.tcl	2006-10-07 22:19:08 UTC (rev 751)
@@ -0,0 +1,69 @@
+# $Id$
+
+namespace eval log_on_open {
+    custom::defvar options(max_messages) -1 \
+	[::msgcat::mc "Maximum number of log messages to show in newly\
+		       opened chat window (if set to negative then the\
+		       number is unlimited)."] \
+	-type integer -group Chat
+    custom::defvar options(max_interval) 1 \
+	[::msgcat::mc "Maximum interval length in hours for which log\
+		       messages should be shown in newly opened chat\
+		       window (if set to negative then the interval is\
+		       unlimited)."] \
+	-type integer -group Chat
+}
+
+proc log_on_open::show {chatid type} {
+    variable options
+
+    if {$type != "chat"} return
+
+    set connid [chat::get_connid $chatid]
+    set jid [chat::get_jid $chatid]
+    set bare_jid [node_and_server_from_jid $jid]
+    set gc [chat::is_groupchat [chat::chatid $connid $bare_jid]]
+
+    if {!$gc} {
+	set log_jid $bare_jid
+    } else {
+	set log_jid $jid
+    }
+    
+    set messages [::logger::get_last_messages $log_jid $options(max_messages) \
+					      $options(max_interval)]
+
+    foreach msg $messages {
+	array unset tmp
+	if {[catch {array set tmp $msg}]} continue
+
+	set x {}
+	if {[info exists tmp(timestamp)]} {
+	    set seconds [clock scan $tmp(timestamp) -gmt 1]
+	    set date [clock format $seconds -format "%Y%m%dT%H:%M:%S" -gmt 1]
+	    lappend x [jlib::wrapper:createtag x \
+			   -vars [list xmlns "jabber:x:delay" \
+				       stamp $date]]
+	}
+	if {[info exists tmp(jid)]} {
+	    if {(!$gc && [node_and_server_from_jid $tmp(jid)] != $bare_jid) || \
+		 $gc && $tmp(jid) != $jid} {
+		set from [jlib::connection_jid $connid]
+	    } else {
+		set from $jid
+	    }
+	} else {
+	    set from ""
+	}
+	# Don't log this message. Request this by creating very special 'empty'
+	# tag which can't be received from the peer.
+	# TODO: Create more elegant mechanism
+	lappend x [jlib::wrapper:createtag "" \
+		       -vars [list xmlns "tkabber:x:nolog"]]
+
+	chat::add_message $chatid $from $type $tmp(body) $x
+    }
+}
+
+hook::add open_chat_post_hook [namespace current]::log_on_open::show 100
+


Property changes on: trunk/tkabber/plugins/chat/log_on_open.tcl
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Modified: trunk/tkabber/plugins/chat/logger.tcl
===================================================================
--- trunk/tkabber/plugins/chat/logger.tcl	2006-10-07 13:37:55 UTC (rev 750)
+++ trunk/tkabber/plugins/chat/logger.tcl	2006-10-07 22:19:08 UTC (rev 751)
@@ -73,15 +73,21 @@
     foreach xelem $x {
 	jlib::wrapper:splitxml $xelem tag vars isempty chdata children
 	
+	# Don't log message if this 'empty' tag is present. It indicates
+	# messages history in chat window.
+	if {[cequal $tag ""] && \
+		[cequal [jlib::wrapper:getattr $vars xmlns] tkabber:x:nolog]} {
+	    return
+	}
 	if {[cequal [jlib::wrapper:getattr $vars xmlns] jabber:x:delay]} {
 	    set seconds [clock scan [jlib::wrapper:getattr $vars stamp] -gmt 1]
 	}
     }
-    set ts [clock format $seconds -format "%Y%m%dT%H%M%S"]
+    set ts [clock format $seconds -format "%Y%m%dT%H%M%S" -gmt 1]
 
     set fd [open $logfile a]
     fconfigure $fd -encoding utf-8
-    puts $fd [list [list timestamp $ts nick ${nick} body $body]]
+    puts $fd [list [list timestamp $ts jid $from nick $nick body $body]]
     close $fd
 }
 
@@ -170,7 +176,7 @@
 	    set vars [lindex $hist 0]
 	    array set tmp $vars
 	    if {[info exists tmp(timestamp)]} {
-		set seconds [clock scan $tmp(timestamp) -gmt 0]
+		set seconds [clock scan $tmp(timestamp) -gmt 1]
 		set ym [clock format $seconds -format %Y%m]
 		set curym [clock format [clock seconds] -format %Y%m]
 		if {$ym < $curym} {
@@ -230,7 +236,7 @@
 	array unset tmp
 	array set tmp $vars
 	if {[info exists tmp(timestamp)]} {
-	    set seconds [clock scan $tmp(timestamp) -gmt 0]
+	    set seconds [clock scan $tmp(timestamp) -gmt 1]
 	    $l insert end [clock format $seconds -format {[%Y-%m-%d %X]}]
 	}
 	if {[info exists tmp(nick)] && $tmp(nick) != ""} {
@@ -302,6 +308,50 @@
     return $hist
 }
 
+proc ::logger::get_last_messages {jid max interval} {
+    if {$max == 0 || $interval == 0} {
+	return {}
+    }
+
+    set logfile [log_file $jid]
+    set months [linsert [lsort -decreasing [get_subdirs $logfile]] \
+			0 [::msgcat::mc "Current"]]
+    set messages {}
+    set curseconds [clock seconds]
+    set max1 [expr {$max - 1}]
+    foreach m $months {
+	catch {
+	    set messages [lsort -increasing -index 1 \
+				[concat [read_hist_from_file $logfile $m] \
+					$messages]]
+	}
+	if {$interval > 0} {
+	    set idx 0
+	    foreach msg $messages {
+		set timestamp [lindex $msg 1]
+		set seconds [clock scan $timestamp -gmt 1]
+		if {$seconds + $interval * 3600 < $curseconds} {
+		    incr idx
+		} else {
+		    break
+		}
+	    }
+	    if {$idx > 0} {
+		set messages  [lrange $messages $idx end]
+		if {$max > 0 && [llength $messages] >= $max} {
+		    return [lrange $messages end-$max1 end]
+		} else {
+		    return $messages
+		}
+	    }
+	}
+	if {$max > 0 && [llength $messages] >= $max} {
+	    return [lrange $messages end-$max1 end]
+	}
+    }
+    return $messages
+}
+
 proc ::logger::filter_old_history {logfile hist} {
     set newhist {}
     set curym [clock format [clock seconds] -format %Y-%m]
@@ -309,7 +359,7 @@
 	array unset tmp
 	array set tmp $vars
 	if {[info exists tmp(timestamp)]} {
-	    set seconds [clock scan $tmp(timestamp) -gmt 0]
+	    set seconds [clock scan $tmp(timestamp) -gmt 1]
 	    set ym [clock format $seconds -format %Y-%m]
 	    if {$ym < $curym} {
 		lappend oldhist($ym) $vars
@@ -343,7 +393,6 @@
     return $newhist
 }
 
-
 proc ::logger::export {lw mcombo logfile mynick} {
     set month [$mcombo cget -text]
 
@@ -380,7 +429,7 @@
 	array set tmp $vars
 	set subtags {}
 	if {[info exists tmp(timestamp)]} {
-	    set seconds [clock scan $tmp(timestamp) -gmt 0]
+	    set seconds [clock scan $tmp(timestamp) -gmt 1]
 	    set timestamp [clock format $seconds -format {[%Y-%m-%d %X]}]
 	    lappend subtags [jlib::wrapper:createtag span \
 				 -vars {class timestamp} \

Modified: trunk/tkabber/plugins/general/sound.tcl
===================================================================
--- trunk/tkabber/plugins/general/sound.tcl	2006-10-07 13:37:55 UTC (rev 750)
+++ trunk/tkabber/plugins/general/sound.tcl	2006-10-07 22:19:08 UTC (rev 751)
@@ -231,6 +231,16 @@
 	    if {$delayed && $options(mute_chat_delayed)} {
 		return
 	    }
+	    foreach xelem $extras {
+		jlib::wrapper:splitxml $xelem tag vars isempty chdata children
+		# Don't play sound if this 'empty' tag is present. It indicates
+		# messages history in chat window.
+		if {[cequal $tag ""] && \
+		    [cequal [jlib::wrapper:getattr $vars xmlns] tkabber:x:nolog]} {
+		    return
+		}
+	    }
+
 	    if {[chat::is_our_jid $chatid $from]} {
 		play $sounds(chat_my_message)
 	    } else {



More information about the Tkabber-dev mailing list