[Tkabber-dev] r463 - in trunk/plugins/juick: . msgs

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Sat Jan 22 23:13:07 MSK 2011


Author: Totktonada
Date: 2011-01-22 23:13:07 +0300 (Sat, 22 Jan 2011)
New Revision: 463

Modified:
   trunk/plugins/juick/BUGS
   trunk/plugins/juick/juick.tcl
   trunk/plugins/juick/msgs/ru.msg
Log:
Some changes:

* Remove juick_jids and juick_bots settings.
* Clickable #dddddd in all chats.
* Reply to your comment is personal message
* Check for Juick JIDs without resources.
* Revert \S to \d in juick numbers
  (juick clones not supported).


Modified: trunk/plugins/juick/BUGS
===================================================================
--- trunk/plugins/juick/BUGS	2011-01-22 03:31:09 UTC (rev 462)
+++ trunk/plugins/juick/BUGS	2011-01-22 20:13:07 UTC (rev 463)
@@ -2,4 +2,5 @@
 # Mathed: "-". Fixed: "+".
 
 - Citate with smile in middle.
-- Random order of sending cached messages and PM.
+- Iq with your nick received after offline messages => personal messages indicated as common.
+- On opening chat plugin send several iq-requests to Juick JID.

Modified: trunk/plugins/juick/juick.tcl
===================================================================
--- trunk/plugins/juick/juick.tcl	2011-01-22 03:31:09 UTC (rev 462)
+++ trunk/plugins/juick/juick.tcl	2011-01-22 20:13:07 UTC (rev 463)
@@ -10,6 +10,8 @@
 
 namespace eval juick {
 variable options
+variable juick_nicknames
+
 ::msgcat::mcload [file join [file dirname [info script]] msgs]
 
 if {![::plugins::is_registered juick]} {
@@ -25,24 +27,16 @@
         custom::defgroup Plugins [::msgcat::mc "Plugins options."] -group Tkabber
 
         set group "Juick"
-
         custom::defgroup $group \
                 [::msgcat::mc "Juick settings."] \
                 -group Plugins
-        custom::defvar options(juick_jids) "juick at juick.com/Juick" \
-                [::msgcat::mc "List of JIDs we treated as Juick JIDs."] \
-                -group $group \
-                -type string
+
         custom::defvar options(main_jid) "juick at juick.com/Juick" \
-                [::msgcat::mc "Main Juick JID used for forwarding things from supplementary bots."] \
+                [::msgcat::mc "Main Juick JID. This used for forwarding things from other chats."] \
                 -group $group \
                 -type string
-        custom::defvar options(juick_bots) "jubo at nologin.ru/jubo" \
-                [::msgcat::mc "Forward things from this list of JIDs to Main Juick JID."] \
-                -group $group \
-                -type string
         custom::defvar options(special_update_juick_tab) 1 \
-                [::msgcat::mc "Only PM and reply to your comments is personal message."] \
+                [::msgcat::mc "Only private messages and replies to your comments is personal message."] \
                 -group $group \
                 -type boolean
 
@@ -64,6 +58,8 @@
 
     hook::add draw_message_hook [namespace current]::add_number_of_messages_from_juick_to_title 18
     hook::remove draw_message_hook ::::ifacetk::add_number_of_messages_to_title 18
+
+    hook::add roster_push_hook [namespace current]::request_juick_nick 99
 }
 
 proc unload {} {
@@ -80,6 +76,8 @@
     hook::remove draw_message_hook [namespace current]::add_number_of_messages_from_juick_to_title 18
     hook::add draw_message_hook ::::ifacetk::add_number_of_messages_to_title 18
 
+    hook::remove roster_push_hook [namespace current]::request_juick_nick 99
+
     ::richtext::entity_state juick_numbers 0
     ::richtext::entity_state citing 0
     ::richtext::entity_state juick 0
@@ -87,37 +85,108 @@
 }
 
 proc is_juick_jid {jid} {
-    variable options
-    set accept_list [split $options(juick_jids) " "]
-    return [expr [lsearch -exact $accept_list $jid] >= 0]
+    set jid [::xmpp::jid::removeResource $jid]
+    set node [::xmpp::jid::node $jid]
+    return [expr [cequal $jid "juick at juick.com"] || [cequal $node "juick%juick.com"]]
+
+#    if {$without_resource} { \
+#        return [expr [cequal $jid "juick at juick.com"] || [regexp "juick%juick.com at .+" $jid]] \
+#    } else { \
+#       return [expr [cequal $jid "juick at juick.com/Juick"] || [regexp "juick%juick.com at .+/Juick" $jid]] \
+#    }
 }
 
 # Determines whether given chatid correspond to Juick
 proc is_juick {chatid} {
     set jid [chat::get_jid $chatid]
     return [is_juick_jid $jid]
-#    return [expr [cequal $jid "juick at juick.com/Juick"] || [regexp "juick%juick.com at .+/Juick" $jid]]
 }
 
+proc request_juick_nick {xlib jid name groups subsc ask} {
+    variable juick_nicknames
+
+    if {![is_juick_jid $jid] || [info exists juick_nicknames($jid)]} {
+        return
+    }
+
+    ::xmpp::sendIQ $xlib get \
+        -query [::xmpp::xml::create query \
+            -xmlns "http://juick.com/query#users"] \
+        -to $jid \
+        -command [list [namespace current]::receive_juick_nick $jid]
+}
+
+proc receive_juick_nick {jid res child} {
+    variable juick_nicknames
+
+    if {![string equal $res ok]} return
+
+    ::xmpp::xml::split $child tag xmlns attrs cdata subels
+
+    if {![cequal $xmlns "http://juick.com/query#users"]} return
+
+    set ch [lindex $subels 0]
+    ::xmpp::xml::split $ch stag sxmlns sattrs scdata ssubels
+
+    if {![cequal $sxmlns "http://juick.com/user"]} return
+
+    set uname [::xmpp::xml::getAttr $sattrs uname]
+    set juick_nicknames($jid) $uname
+
+#    puts "For $jid: uname is \"$uname\""
+
+    return
+}
+
 proc handle_message {chatid from type body x} {
-    if {[is_juick $chatid]} {
-        ::richtext::property_add {JUICK} {}
-        set chatw [chat::chat_win $chatid]
-        set jid [chat::get_jid $chatid]
+    variable juick_nicknames
 
-        set tags {}
-        if {![cequal $jid $from]} {
-            lappend tags JMY
-        }
+    if {![is_juick $chatid]} return
 
-        ::richtext::render_message $chatw $body $tags
-        return stop
+    ::richtext::property_add {JUICK} {}
+
+    set chatw [chat::chat_win $chatid]
+    set jid [chat::get_jid $chatid]
+
+    set tags {}
+    if {![cequal $jid $from]} {
+        lappend tags JMY
     }
+
+    ::richtext::render_message $chatw $body $tags
+    return stop
 }
 
+proc get_juick_nickname {jid} {
+    variable juick_nicknames
+
+    set uname ""
+    set jid [::xmpp::jid::removeResource $jid]
+
+    if {[info exists juick_nicknames($jid)]} {
+        set uname $juick_nicknames($jid)
+    }
+
+    return $uname
+}
+
+proc is_personal_juick_message {from body} {
+    variable juick_nicknames
+    set reply_to_my_comment 0
+
+    set private_msg [regexp {^Private message from @.+:\n} $body]
+    set reply_to_comment [regexp {Reply by @[^\n ]+:\n>.+\n\n@([^\n ]+) .+\n\n#\d+/\d+ http://juick.com/\d+#\d+$} $body -> reply_to_nick]
+
+    if {$reply_to_comment} {
+        set reply_to_my_comment [cequal [get_juick_nickname $from] $reply_to_nick]
+    }
+
+    return [expr $private_msg || $reply_to_my_comment]
+}
+
 proc update_juick_tab {chatid from type body x} {
     variable options
-    if {![expr [is_juick $chatid] && [cequal $type "chat"] && $options(special_update_juick_tab)]} {
+    if {![expr [is_juick_jid $from] && [cequal $type "chat"] && $options(special_update_juick_tab)]} {
         ::plugins::update_tab::update $chatid $from $type $body $x
         return
     }
@@ -132,7 +201,7 @@
 
     set cw [chat::winid $chatid]
 
-    if {[regexp {^Private message from @.+:\n} $body]} {
+    if {[is_personal_juick_message $from $body]} {
         tab_set_updated $cw 1 mesg_to_user
     } else {
         tab_set_updated $cw 1 message
@@ -147,7 +216,7 @@
 
 proc add_number_of_messages_from_juick_to_title {chatid from type body x} {
     variable options
-    if {![expr [is_juick $chatid] && [cequal $type "chat"] && $options(special_update_juick_tab)]} {
+    if {![expr [is_juick_jid $from] && [cequal $type "chat"] && $options(special_update_juick_tab)]} {
         ::ifacetk::add_number_of_messages_to_title $chatid $from $type $body $x
         return
     }
@@ -168,7 +237,7 @@
 
     incr number_msg($chatid)
 
-    if {[regexp {^Private message from @.+:\n} $body]} {
+    if {[is_personal_juick_message $from $body]} {
         incr personal_msg($chatid)
     }
 
@@ -222,8 +291,7 @@
         return
     }
 
-#    if {[regexp {^S (#\d+)\+\s*$} $body -> thing]} { }
-    if {[regexp {^S (#\S+)\+\s*$} $body -> thing]} {
+    if {[regexp {^S (#\d+)\+\s*$} $body -> thing]} {
         set xlib [chat::get_xlib $chatid]
         set jid [chat::get_jid $chatid]
 
@@ -239,17 +307,10 @@
     variable options
     set thing ""
     set cw [chat::chat_win $chatid]
-#    set ci [chat::input_win $chatid]
+    set ci [chat::input_win $chatid]
+    set jid [::xmpp::jid::removeResource [chat::get_jid $chatid]]
 
-    set jid [chat::get_jid $chatid]
-    set forward_list [split $options(juick_bots) " "]
-    if {[lsearch -exact $forward_list $jid] >= 0} {
-        set mainchat [list [chat::get_xlib $chatid] $options(main_jid)]
-        chat::activate $mainchat
-        set ci [chat::input_win $mainchat]
-    } else {
-        set ci [chat::input_win $chatid]
-    }
+
     set tags [$cw tag names "@$x,$y"]
 
     if {[set idx [lsearch -glob $tags JUICK-*]] >= 0} {
@@ -258,6 +319,13 @@
 
     if {$thing == ""} return
 
+    if {![is_juick_jid $jid]} {
+        #set mainchat_jid [::xmpp::jid::removeResource $options(main_jid)]
+        set mainchat [list [chat::get_xlib $chatid] $options(main_jid)]
+        chat::activate $mainchat
+        set ci [chat::input_win $mainchat]
+    }
+
     $ci insert insert "$thing "
     focus -force $ci
     return stop
@@ -385,8 +453,7 @@
 
 proc spot_juick_numbers {what at startVar endVar} {
     set matched [regexp -indices -start $at -- \
-    {(?:\s|\n|\A|\(|\>)(#\S+(/\d+)?)(?:(\.(\s|\n))?)} $what -> bounds]
-#    {(?:\s|\n|\A|\(|\>)(#\d+(/\d+)?)(?:(\.(\s|\n))?)} $what -> bounds]
+    {(?:\s|\n|\A|\(|\>)(#\d+(/\d+)?)(?:(\.(\s|\n))?)} $what -> bounds]
 
     if {!$matched} { return false }
 
@@ -396,25 +463,30 @@
 }
 
 proc process_juick {atLevel accName} {
-return [process $atLevel $accName juick]
+    if {[::richtext::property_exists {JUICK}]} {
+        return [process $atLevel $accName juick]
+    }
 }
 
 proc process_juick_numbers {atLevel accName} {
-return [process $atLevel $accName juick_numbers]
+    return [process $atLevel $accName juick_numbers]
 }
 
 proc process_citing {atLevel accName} {
-return [process $atLevel $accName citing]
+    if {[::richtext::property_exists {JUICK}]} {
+        return [process $atLevel $accName citing]
+    }
 }
 
 proc process_juick_ligth {atLevel accName} {
-return [process $atLevel $accName juick_ligth]
+    if {[::richtext::property_exists {JUICK}]} {
+       return [process $atLevel $accName juick_ligth]
+    }
 }
 
 proc process {atLevel accName what} {
     upvar #$atLevel $accName chunks
 
-    if {![::richtext::property_exists {JUICK}]} {return}
     set out {}
 
     foreach {s type tags} $chunks {

Modified: trunk/plugins/juick/msgs/ru.msg
===================================================================
--- trunk/plugins/juick/msgs/ru.msg	2011-01-22 03:31:09 UTC (rev 462)
+++ trunk/plugins/juick/msgs/ru.msg	2011-01-22 20:13:07 UTC (rev 463)
@@ -1,3 +1,6 @@
 ::msgcat::mcset ru "\[J\] Copy thing to clipboard." "\[J\] Скопировать сущность в буфер обмена."
 ::msgcat::mcset ru "Whether the Juick plugin is loaded." "Загружено ли расширение для удобной работы с Juick."
-::msgcat::mcset ru "\[J\] Open thing in browser." "\[J\] Открыть сущность в браузере."
\ No newline at end of file
+::msgcat::mcset ru "\[J\] Open thing in browser." "\[J\] Открыть сущность в браузере."
+::msgcat::mcset ru "Juick settings." "Параметры расширения для удобной работы с Juick"
+::msgcat::mcset ru "Main Juick JID. This used for forwarding things from other chats." "Главный JID Juick'а. Используется для перенаправления сущностей из других чатов."
+::msgcat::mcset ru "Only private messages and replies to your comments is personal message." "Только приватные сообщения и ответы на ваши комментарии являются персональными сообщениями."



More information about the Tkabber-dev mailing list