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

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Sat Jan 30 15:58:05 MSK 2010


Author: sergei
Date: 2010-01-30 15:58:05 +0300 (Sat, 30 Jan 2010)
New Revision: 1899

Modified:
   trunk/tkabber-plugins/ChangeLog
   trunk/tkabber-plugins/tclchat/tclchat_messages.tcl
Log:
	* tclchat_messages.tcl: Adapted to changes in Tkabber's MUC.


Modified: trunk/tkabber-plugins/ChangeLog
===================================================================
--- trunk/tkabber-plugins/ChangeLog	2010-01-30 12:46:13 UTC (rev 1898)
+++ trunk/tkabber-plugins/ChangeLog	2010-01-30 12:58:05 UTC (rev 1899)
@@ -1,3 +1,7 @@
+2010-01-30  Sergei Golovan <sgolovan at nes.ru>
+
+	* tclchat_messages.tcl: Adapted to changes in Tkabber's MUC.
+
 2010-01-24  Sergei Golovan <sgolovan at nes.ru>
 
 	* jidlink/jidlink.tcl, jidlink/trans/ru.msg: Added translations to

Modified: trunk/tkabber-plugins/tclchat/tclchat_messages.tcl
===================================================================
--- trunk/tkabber-plugins/tclchat/tclchat_messages.tcl	2010-01-30 12:46:13 UTC (rev 1898)
+++ trunk/tkabber-plugins/tclchat/tclchat_messages.tcl	2010-01-30 12:58:05 UTC (rev 1899)
@@ -38,6 +38,7 @@
     hook::add process_message_hook [namespace current]::fill_irc_users 30
     hook::add process_message_hook [namespace current]::process_ijchain_message 30
     hook::add draw_message_hook    [namespace current]::check_color 62
+    hook::add join_group_hook      [namespace current]::touch_connect
 }
 
 proc tclchat::unload_messages {} {
@@ -45,25 +46,22 @@
     hook::remove process_message_hook [namespace current]::fill_irc_users 30
     hook::remove process_message_hook [namespace current]::process_ijchain_message 30
     hook::remove draw_message_hook    [namespace current]::check_color 62
+    hook::remove join_group_hook      [namespace current]::touch_connect
 }
 
 # VERY DIRTY HACK. Tkabber doesn't have appropriate hook, so using inappropriate
 proc tclchat::request_users_list {vxlist xlib stat} {
-    upvar 2 newargs args
+    upvar 3 group group
     variable irc_users
     variable options
 
+    # HACK: Use the fact that joining groupchat calls presence_args
+    # which in turn runs presence_xlist_hook
+    if {![info exists group]} return
+
     # 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 [::xmpp::jid::stripResource $to]
-
     # If the presence doesn't go to Tclers' chat, do nothing
     if {![cequal $group $options(tclers_chat_jid)]} return
 
@@ -71,8 +69,7 @@
 
     # 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"} {
+    if {[chat::is_opened $chatid] && [chat::is_disconnected $chatid]} {
 	# Setting the flag to show that the answer is to be processed
 	# programmatically
 	set irc_users($xlib) {}
@@ -97,35 +94,52 @@
     return stop
 }
 
+proc tclchat::touch_connect {chatid nick} {
+    variable connect
+
+    set connect($chatid) {}
+}
+
+proc tclchat::update_presence {xlib jid type xmlElements} {
+    client:presence $xlib $jid $type $xmlElements
+    ::xmpp::presence::process $xlib $jid $type $xmlElements
+}
+
 proc tclchat::inject_irc_users {xlib users args} {
+    variable irc_users
+    variable connect
     variable options
 
     set group $options(tclers_chat_jid)
 
     set chatid [chat::chatid $xlib $group]
 
-    trace vdelete chat::chats(status,$chatid) w \
+    trace vdelete [namespace current]::connect($chatid) w \
 	  [list [namespace current]::inject_irc_users $xlib $users]
 
-    if {![chat::is_opened $chatid]} return
+    if {![chat::is_opened $chatid]} {
+	catch {unset connect($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 \
+    if {![info exists connect($chatid)]} {
+	trace variable [namespace curent]::connect($chatid) w \
 	      [list [namespace current]::inject_irc_users $xlib $users]
 	return
     }
 
+    unset connect($chatid)
+
     set px [::xmpp::xml::create x \
 		-xmlns $::NS(muc#user) \
 		-subelement [::xmpp::xml::create item \
 				    -attrs [list affiliation none]]]
     foreach nick $users {
 	set nickid $group/$nick
-	if {[lsearch -exact $::grouproster(users,$chatid) $nickid] < 0 || \
-		[cequal $::muc::users(role,$xlib,$nickid) ""]} {
-	    client:presence $xlib $nickid available [list $px]
+	if {![jid_in_chat $chatid $nickid]} {
+	    update_presence $xlib $nickid available [list $px]
 	} else {
 	    client:message $xlib $group groupchat {} \
 			   -body [::msgcat::mc "%s has joined IRC channel,\
@@ -139,8 +153,9 @@
 
 proc tclchat::jid_in_chat {chatid jid} {
     set xlib [chat::get_xlib $chatid]
-    return [expr {[lsearch -exact $::grouproster(users,$chatid) $jid] >= 0 && \
-		  ![cequal $::muc::users(role,$xlib,$jid) ""]}]
+    set nick [::xmpp::jid::resource $jid]
+    expr {[lsearch -exact [muc::roster $chatid] $nick] >= 0 && \
+		![cequal [muc::get_role $xlib $jid] ""]}
 }
 
 proc tclchat::process_ijchain_message \
@@ -180,7 +195,7 @@
 						-attrs [list affiliation none]]]
 
 		if {![jid_in_chat $chatid $nickid]} {
-		    client:presence $xlib $nickid available [list $px]
+		    update_presence $xlib $nickid available [list $px]
 		} else {
 		    client:message $xlib $group $type {} \
 				   -body [::msgcat::mc "%s has joined IRC\
@@ -193,7 +208,7 @@
 		debugmsg chat "Handle \"$nick\" left message."
 
 		if {![jid_in_chat $chatid $nickid]} {
-		    client:presence $xlib $nickid unavailable {}
+		    update_presence $xlib $nickid unavailable {}
 		} else {
 		    client:message $xlib $group $type {} \
 				   -body [::msgcat::mc "%s has left IRC\
@@ -235,10 +250,10 @@
 
 	    if {![jid_in_chat $chatid $from_nickid]} {
 		if {![jid_in_chat $chatid $to_nickid]} {
-		    client:presence $xlib $from_nickid unavailable [list $ux]
-		    client:presence $xlib $to_nickid available [list $px]
+		    update_presence $xlib $from_nickid unavailable [list $ux]
+		    update_presence $xlib $to_nickid available [list $px]
 		} else {
-		    client:presence $xlib $from_nickid unavailable {}
+		    update_presence $xlib $from_nickid unavailable {}
 		    client:message $xlib $group $type {} \
 				   -body [::msgcat::mc "%s has changed nick\
 							to %s in the IRC channel,\
@@ -254,7 +269,7 @@
 							but %s is still in Jabber\
 							room" \
 						 $from_nick $to_nick $from_nick]
-		    client:presence $xlib $to_nickid available [list $px]
+		    update_presence $xlib $to_nickid available [list $px]
 		} else {
 		    client:message $xlib $group $type {} \
 				   -body [::msgcat::mc "%s has changed nick to %s\



More information about the Tkabber-dev mailing list