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

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Sun Jan 26 11:25:24 MSK 2014


Author: sergei
Date: 2014-01-26 11:25:23 +0400 (Sun, 26 Jan 2014)
New Revision: 2094

Modified:
   trunk/tkabber/ChangeLog
   trunk/tkabber/messages.tcl
   trunk/tkabber/plugins/chat/logger.tcl
   trunk/tkabber/plugins/general/message_archive.tcl
Log:
	* plugins/chat/logger.tcl, plugins/general/message_archive.tcl:
	  Removed fake tkabber:x:dontlog namespace processing. Implemented
	  omitting the logs using flags in an appropriate hook.

	* messages.tcl: Introduced send_normal_message_hook which executes
	  when message is to be sent from a send message dialog. Moved
	  logging of incoming messages to process_message_hook, and logging
	  of outgoing messages to send_normal_message_hook. Use log flag
	  in this hooks to disable logging. Use send flag in
	  rewrite_outgoing_message_hook to disable actual sending.


Modified: trunk/tkabber/ChangeLog
===================================================================
--- trunk/tkabber/ChangeLog	2014-01-25 19:29:10 UTC (rev 2093)
+++ trunk/tkabber/ChangeLog	2014-01-26 07:25:23 UTC (rev 2094)
@@ -1,3 +1,16 @@
+2014-01-26  Sergei Golovan  <sgolovan at nes.ru>
+
+	* plugins/chat/logger.tcl, plugins/general/message_archive.tcl:
+	  Removed fake tkabber:x:dontlog namespace processing. Implemented
+	  omitting the logs using flags in an appropriate hook.
+
+	* messages.tcl: Introduced send_normal_message_hook which executes
+	  when message is to be sent from a send message dialog. Moved
+	  logging of incoming messages to process_message_hook, and logging
+	  of outgoing messages to send_normal_message_hook. Use log flag
+	  in this hooks to disable logging. Use send flag in
+	  rewrite_outgoing_message_hook to disable actual sending.
+
 2014-01-22  Sergei Golovan  <sgolovan at nes.ru>
 
 	* gpgme.tcl, chats.tcl: Adjusted priority of rewrite_message_hook

Modified: trunk/tkabber/messages.tcl
===================================================================
--- trunk/tkabber/messages.tcl	2014-01-25 19:29:10 UTC (rev 2093)
+++ trunk/tkabber/messages.tcl	2014-01-26 07:25:23 UTC (rev 2094)
@@ -27,17 +27,22 @@
 }
 
 hook::add process_message_hook \
-    [namespace current]::message::process_message 98
+	  [namespace current]::message::process_message 98
 
+proc message::log_message {xlib from id type is_subject subject body err thread priority x} {
+    if {$type != "normal" || $body == ""} return
+    if {![hook::is_flag process_message_hook log]} return
+
+    ::message_archive::log_message $from [connection_jid $xlib] $subject $body $x
+
+    return
+}
+hook::add process_message_hook \
+	  [namespace current]::message::log_message 97
+
 proc message::show_dialog {xlib from id type subject body thread priority x {replyP 1}} {
     variable msgid
 
-    if {$type == "normal" && $body != ""} {
-        ::message_archive::log_message \
-	    $from [connection_jid $xlib] \
-            $subject $body $x
-    }
-
     set mw .msgshow[incr msgid]
     toplevel $mw -class Message
     wm group $mw .
@@ -484,6 +489,7 @@
 
     foreach jid $jids {
 	if {!$group || [::roster::itemconfig $xlib $jid -isuser]} {
+	    hook::run send_normal_message_hook $xlib $jid $subj $body $thread
 	    send_msg $xlib $jid -type normal \
 		-subject $subj -body $body -thread $thread
 	}
@@ -492,6 +498,18 @@
     destroy $mw
 }
 
+proc message::log_outgoing {xlib to subj body thread} {
+    if {$body == ""} return
+    if {![hook::is_flag send_normal_message_hook log]} return
+
+    ::message_archive::log_message [connection_jid $xlib] $to $subj $body {}
+
+    return
+}
+
+hook::add send_normal_message_hook \
+	  [namespace current]::message::log_outgoing 50
+
 proc message::send_msg {xlib to args} {
     set x {}
     foreach {key val} $args {
@@ -507,23 +525,10 @@
 	}
     }
 
-    if {[info exists body]} {
-        set log_body $body
-    } else {
-        set log_body ""
-    }
-    if {[info exists subject]} {
-        set log_subject $subject
-    } else {
-        set log_subject ""
-    }
-
     hook::run rewrite_outgoing_message_hook \
 	      xlib to id type subject body err thread x
 
-    if {![string equal $to ""]} {
-	# To abort sending the hook has to rewrite to jid to empty string
-
+    if {[hook::is_flag rewrite_outgoing_message_hook send]} {
 	set command [list ::xmpp::sendMessage $xlib $to]
 
 	if {[info exists from]}    { lappend command -from $from }
@@ -536,11 +541,6 @@
 	if {[info exists x]}       { lappend command -xlist $x }
 
 	eval $command
-
-	if {(![info exists type] || $type == "normal") && $log_body != ""} {
-	    ::message_archive::log_message [connection_jid $xlib] \
-					   $to $log_subject $log_body $x
-	}
     }
 
     return [list success $x]

Modified: trunk/tkabber/plugins/chat/logger.tcl
===================================================================
--- trunk/tkabber/plugins/chat/logger.tcl	2014-01-25 19:29:10 UTC (rev 2093)
+++ trunk/tkabber/plugins/chat/logger.tcl	2014-01-26 07:25:23 UTC (rev 2094)
@@ -203,6 +203,8 @@
     if {$type == "chat" && !$options(log_chat)} return
     if {$type == "groupchat" && !$options(log_groupchat)} return
 
+    if {![hook::is_flag draw_message_hook log]} return
+
     set xlib [chat::get_xlib $chatid]
     set jid [chat::get_jid $chatid]
     set nas [::xmpp::jid::stripResource $jid]
@@ -218,8 +220,7 @@
 	
 	# Don't log message if this 'empty' tag is present. It indicates
 	# messages history in chat window.
-	if {[string equal $tag ""] && \
-		([string equal $xmlns tkabber:x:nolog] || [string equal $xmlns tkabber:x:dontlog])} {
+	if {[string equal $tag ""] && [string equal $xmlns tkabber:x:nolog]} {
 	    return
 	}
     }

Modified: trunk/tkabber/plugins/general/message_archive.tcl
===================================================================
--- trunk/tkabber/plugins/general/message_archive.tcl	2014-01-25 19:29:10 UTC (rev 2093)
+++ trunk/tkabber/plugins/general/message_archive.tcl	2014-01-26 07:25:23 UTC (rev 2094)
@@ -33,14 +33,6 @@
 proc ::message_archive::log_message {from to subject body x} {
     variable archive_file
 
-    foreach el $x {
-	::xmpp::xml::split $el tag xmlns attrs cdata subels
-
-	if {[string equal $tag ""] && [string equal $xmlns tkabber:x:dontlog]} {
-	    return
-	}
-    }
-
     set seconds [::xmpp::xml::getAttr [::xmpp::delay::parse $x] seconds]
     set ts [clock format $seconds -format "%Y%m%dT%H%M%S"]
 



More information about the Tkabber-dev mailing list