[Tkabber-dev] r943 - in trunk/tkabber-plugins: . tclchat

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Wed Feb 14 23:19:14 MSK 2007


Author: sergei
Date: 2007-02-14 23:19:11 +0300 (Wed, 14 Feb 2007)
New Revision: 943

Modified:
   trunk/tkabber-plugins/ChangeLog
   trunk/tkabber-plugins/tclchat/tclchat.tcl
   trunk/tkabber-plugins/tclchat/tclchat_messages.tcl
Log:
	* tclchat/tclchat.tcl: Added customize group Tclchat.

	* tclchat/tclchat_messages.tcl: Made bridge nick and JID, and Tclers'
	  chat room JID customizable. Added processing of nickname changes on
	  the IRC side.


Modified: trunk/tkabber-plugins/ChangeLog
===================================================================
--- trunk/tkabber-plugins/ChangeLog	2007-02-14 17:53:48 UTC (rev 942)
+++ trunk/tkabber-plugins/ChangeLog	2007-02-14 20:19:11 UTC (rev 943)
@@ -1,3 +1,11 @@
+2006-02-14  Sergei Golovan <sgolovan at nes.ru>
+
+	* tclchat/tclchat.tcl: Added customize group Tclchat.
+
+	* tclchat/tclchat_messages.tcl: Made bridge nick and JID, and Tclers'
+	  chat room JID customizable. Added processing of nickname changes on
+	  the IRC side.
+
 2006-02-13  Sergei Golovan <sgolovan at nes.ru>
 
 	* debug/msgs/es.msg, spy/msgs/es.msg, whiteboard/msgs/es.msg: Updated

Modified: trunk/tkabber-plugins/tclchat/tclchat.tcl
===================================================================
--- trunk/tkabber-plugins/tclchat/tclchat.tcl	2007-02-14 17:53:48 UTC (rev 942)
+++ trunk/tkabber-plugins/tclchat/tclchat.tcl	2007-02-14 20:19:11 UTC (rev 943)
@@ -7,10 +7,13 @@
 # $Id$
 
 namespace eval tclchat {
+    custom::defgroup Plugins [::msgcat::mc "Plugins options."] -group Tkabber
 
+    custom::defgroup Tclchat [::msgcat::mc "Tclchat plugin options."] -group Plugins
+
     custom::defvar options(use_tkchat_colors) 1 \
-        [msgcat::mc "Use TkChat embedded colors."] \
-        -group Chat -type boolean
+        [::msgcat::mc "Use TkChat embedded colors."] \
+        -group Chat -group Tclchat -type boolean
 
     hook::add finload_hook [namespace current]::on_init
     hook::add open_chat_post_hook [namespace current]::on_open_chat

Modified: trunk/tkabber-plugins/tclchat/tclchat_messages.tcl
===================================================================
--- trunk/tkabber-plugins/tclchat/tclchat_messages.tcl	2007-02-14 17:53:48 UTC (rev 942)
+++ trunk/tkabber-plugins/tclchat/tclchat_messages.tcl	2007-02-14 20:19:11 UTC (rev 943)
@@ -15,7 +15,23 @@
 # Rewritten by Sergei Golovan
 
 namespace eval tclchat {
+    custom::defvar options(tclers_chat_jid) "tcl at tach.tclers.tk" \
+        [::msgcat::mc "JID of Tclers' chat."] \
+        -group Tclchat -type string
     
+    custom::defvar options(bridge_jid) "ijchain at all.tclers.tk/ijbridge" \
+        [::msgcat::mc "Real JID of Tclers' chat bridge to IRC channel.\
+		       If set to nonempty string, the list of IRC users\
+		       will be requested before entering the conference room."] \
+        -group Tclchat -type string
+    
+    custom::defvar options(bridge_nickname) "ijchain" \
+        [::msgcat::mc "Nickname of Tclers' chat bridge to IRC channel.\
+		       Groupchat messages from this participant\
+		       are treated specially, replacing his nickname by\
+		       corresponding IRC user nickname."] \
+        -group Tclchat -type string
+    
     hook::add presence_xlist_hook [namespace current]::request_users_list
     hook::add process_message_hook [namespace current]::fill_irc_users 30
     hook::add process_message_hook [namespace current]::process_ijchain_message 30
@@ -25,21 +41,32 @@
 proc tclchat::request_users_list {vxlist connid stat} {
     upvar 2 newargs args
     variable irc_users
+    variable options
 
+    # Don't request IRC users list if bridge JID is empty
+    if {[cequal $options(bridge_jid) ""]} return
+
+    # HACK: Extract conference name from directed presence. If it isn't
+    # a directed presence then do nothing
     array set tmp $args
     if {![info exists tmp(-to)]} return
 
     set to $tmp(-to)
     set group [node_and_server_from_jid $to]
 
-    if {![cequal $group "tcl at tach.tclers.tk"]} return
+    # If the presence doesn't go to Tclers' chat, do nothing
+    if {![cequal $group $options(tclers_chat_jid)]} return
 
     set chatid [chat::chatid $connid $group]
 
+    # If the chat is disconnected then we're trying to connect. Then it's
+    # time to request IRC users list
     if {[chat::is_opened $chatid] && [chat::is_groupchat $chatid] && \
 	    $chat::chats(status,$chatid) == "disconnected"} {
+	# Setting the flag to show that the answer is to be processed
+	# programmatically
 	set irc_users($connid) {}
-	message::send_msg "ijchain at all.tclers.tk/ijbridge" \
+	message::send_msg $options(bridge_jid) \
 			  -type chat \
 			  -body names \
 			  -connection $connid
@@ -49,9 +76,12 @@
 proc tclchat::fill_irc_users \
      {connid from id type is_subject subject body err thread priority x} {
     variable irc_users
+    variable options
 
+    # Don't process message if we didn't ask the list or this message isn't
+    # from bridge JID
     if {![info exists irc_users($connid)]} return
-    if {![cequal $from "ijchain at all.tclers.tk/ijbridge"]} return
+    if {![cequal $from $options(bridge_jid)]} return
 
     unset irc_users($connid)
     after idle [list [namespace current]::inject_irc_users $connid $body]
@@ -59,8 +89,10 @@
 }
 
 proc tclchat::inject_irc_users {connid users args} {
-    set group "tcl at tach.tclers.tk"
+    variable options
 
+    set group $options(tclers_chat_jid)
+
     set chatid [chat::chatid $connid $group]
 
     trace vdelete chat::chats(status,$chatid) w \
@@ -68,6 +100,8 @@
 
     if {![chat::is_opened $chatid]} return
 
+    # If we're still disconnected, schedule the IRC users injection after
+    # a change in chat status
     if {$chat::chats(status,$chatid) == "disconnected"} {
 	trace variable chat::chats(status,$chatid) w \
 	      [list [namespace current]::inject_irc_users $connid $users]
@@ -77,11 +111,11 @@
     set px [jlib::wrapper:createtag x \
 		-vars [list xmlns $::NS(muc#user)] \
 		-subtags [list [jlib::wrapper:createtag item \
-				    -vars [list jid $group/ijchain \
-						affiliation none]]]]
+				    -vars [list affiliation none]]]]
     foreach nick $users {
 	set nickid $group/$nick
-	if {[lsearch -exact $::grouproster(users,$chatid) $nickid] < 0} {
+	if {[lsearch -exact $::grouproster(users,$chatid) $nickid] < 0 || \
+		[cequal $::muc::users(role,$connid,$nickid) ""]} {
 	    client:presence $connid $nickid available [list $px]
 	} else {
 	    client:message $connid $group "" groupchat 0 "" \
@@ -94,8 +128,15 @@
 
 ###############################################################################
 
+proc tclchat::jid_in_chat {chatid jid} {
+    set connid [chat::get_connid $chatid]
+    return [expr {[lsearch -exact $::grouproster(users,$chatid) $jid] >= 0 && \
+		  ![cequal $::muc::users(role,$connid,$jid) ""]}]
+}
+
 proc tclchat::process_ijchain_message \
      {connid from id type is_subject subject body err thread priority x} {
+    variable options
 
     # Filter groupchat messages only
     if {![cequal $type groupchat]} return
@@ -105,12 +146,12 @@
     set chatid [chat::chatid $connid $group]
 
     # Filter messages from tcl at tach.tclers.tk only
-    if {![cequal $group tcl at tach.tclers.tk]} return
+    if {![cequal $group $options(tclers_chat_jid)]} return
 
     set nick [chat::get_nick $connid $from $type]
 
-    # Filter messages frim ijchain and *bridge only
-    if {$nick != "ijchain" && ![string match "*bridge" $nick]} return
+    # Filter messages from ijchain only
+    if {$nick != $options(bridge_nickname)} return
 
     set lbody [split $body " "]
     # Update userlist on "*** nick leaves" and "*** nick joins" messages
@@ -127,35 +168,92 @@
 		set px [jlib::wrapper:createtag x \
 			    -vars [list xmlns $::NS(muc#user)] \
 			    -subtags [list [jlib::wrapper:createtag item \
-						-vars [list jid $from \
-							    affiliation none]]]]
+						-vars [list affiliation none]]]]
 
-		if {[lsearch -exact $::grouproster(users,$chatid) $nickid] < 0} {
+		if {![jid_in_chat $chatid $nickid]} {
 		    client:presence $connid $nickid available [list $px]
 		} else {
 		    client:message $connid $group $id $type 0 "" \
 				   [::msgcat::mc "%s has joined IRC channel,\
-						  but he/she is already in Jabber room" \
-						 $nick] \
+						  but %s is already in Jabber room" \
+						 $nick $nick] \
 				   $err $thread $priority $x
 		}
-		return stop
 	    }
 	    leaves {
 		debugmsg chat "Handle \"$nick\" left message."
 
-		if {[lsearch -exact $::grouproster(users,$chatid) $nickid] >= 0 && \
-			[muc::get_real_jid $connid $nickid] != $from} {
+		if {![jid_in_chat $chatid $nickid]} {
+		    client:presence $connid $nickid unavailable {}
+		} else {
 		    client:message $connid $group $id $type 0 "" \
 				   [::msgcat::mc "%s has left IRC channel,\
-						  but he/she is still in Jabber room" \
-						 $nick] \
+						  but %s is still in Jabber room" \
+						 $nick $nick] \
 				   $err $thread $priority $x
+		}
+	    }
+	    default {
+		return
+	    }
+	}
+
+	return stop
+    }
+
+    if {[llength $lbody] == 7 && [cequal [lindex $lbody 0] "***"]} {
+
+	set from_nick [lindex $lbody 1]
+	set to_nick [lindex $lbody 6]
+
+	if {[cequal [join [lrange $lbody 2 5] " "] "is now known as"]} {
+	    
+	    set ux [jlib::wrapper:createtag x \
+			-vars [list xmlns $::NS(muc#user)] \
+			-subtags [list [jlib::wrapper:createtag item \
+					    -vars [list affiliation none \
+							nick $to_nick]] \
+				       [jlib::wrapper:createtag status \
+					    -vars [list code 303]]]]
+
+	    set px [jlib::wrapper:createtag x \
+			-vars [list xmlns $::NS(muc#user)] \
+			-subtags [list [jlib::wrapper:createtag item \
+					    -vars [list affiliation none]]]]
+
+	    set from_nickid $group/$from_nick
+	    set to_nickid $group/$to_nick
+
+	    if {![jid_in_chat $chatid $from_nickid]} {
+		if {![jid_in_chat $chatid $to_nickid]} {
+		    client:presence $connid $from_nickid unavailable [list $ux]
+		    client:presence $connid $to_nickid available [list $px]
 		} else {
-		    client:presence $connid $nickid unavailable {}
+		    client:presence $connid $from_nickid unavailable {}
+		    client:message $connid $group $id $type 0 "" \
+				   [::msgcat::mc "%s has changed nick to %s in the IRC channel,\
+						  but %s is already in Jabber room" \
+						 $from_nick $to_nick $to_nick] \
+				   $err $thread $priority $x
 		}
-		return stop
+	    } else {
+		if {![jid_in_chat $chatid $to_nickid]} {
+		    client:message $connid $group $id $type 0 "" \
+				   [::msgcat::mc "%s has changed nick to %s in the IRC channel,\
+						  but %s is still in Jabber room" \
+						 $from_nick $to_nick $from_nick] \
+				   $err $thread $priority $x
+		    client:presence $connid $to_nickid available [list $px]
+		} else {
+		    client:message $connid $group $id $type 0 "" \
+				   [::msgcat::mc "%s has changed nick to %s in the IRC channel,\
+						  but %s is still in Jabber room and\
+						  %s is already in Jabber room" \
+						 $from_nick $to_nick $from_nick $to_nick] \
+				   $err $thread $priority $x
+		}
 	    }
+	    return stop
 	}
 
 	return



More information about the Tkabber-dev mailing list