[Tkabber-dev] r538 - branches/plugins-0.11.1/juick

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Wed Sep 18 21:04:06 MSK 2013


Author: Totktonada
Date: 2013-09-18 21:04:06 +0400 (Wed, 18 Sep 2013)
New Revision: 538

Modified:
   branches/plugins-0.11.1/juick/juick.tcl
   branches/plugins-0.11.1/juick/tkabber-0.11.1-compatibility.tcl
Log:
Juick plugin (tkabber-0.11.1 branch):

More simple way to determine personal message.
    
Support of new juick feature (XMPP-API replytoyou attribute), remove
deprecated feature (XMPP-API iq).


Modified: branches/plugins-0.11.1/juick/juick.tcl
===================================================================
--- branches/plugins-0.11.1/juick/juick.tcl	2013-09-18 17:02:58 UTC (rev 537)
+++ branches/plugins-0.11.1/juick/juick.tcl	2013-09-18 17:04:06 UTC (rev 538)
@@ -18,7 +18,6 @@
 
 namespace eval juick {
 variable options
-variable juick_nicknames
 variable chat_things
 
 ::msgcat::mcload [file join [file dirname [info script]] msgs]
@@ -87,9 +86,6 @@
     hook::remove draw_message_hook \
         ::::ifacetk::add_number_of_messages_to_title 18
 
-    hook::add roster_push_hook \
-        [namespace current]::request_juick_nick 99
-
     hook::add generate_completions_hook \
         [namespace current]::juick_commands_comps 99
 }
@@ -125,9 +121,6 @@
     hook::add draw_message_hook \
         ::::ifacetk::add_number_of_messages_to_title 18
 
-    hook::remove roster_push_hook \
-        [namespace current]::request_juick_nick 99
-
     hook::remove generate_completions_hook \
         [namespace current]::juick_commands_comps 99
 
@@ -158,45 +151,7 @@
     return [is_juick_jid $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 {![string equal $xmlns "http://juick.com/query#users"]} return
-
-    set ch [lindex $subels 0]
-    ::xmpp::xml::split $ch stag sxmlns sattrs scdata ssubels
-
-    if {![string equal $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} {
-    variable juick_nicknames
-
     if {![is_juick $chatid]} return
 
     ::richtext::property_add {JUICK} {}
@@ -213,33 +168,31 @@
     return stop
 }
 
-proc get_juick_nickname {jid} {
-    variable juick_nicknames
+proc is_reply_to_you {x} {
+    foreach xe $x {
+        ::xmpp::xml::split $xe tag xmlns attrs cdata subels
 
-    set uname ""
-    set jid [::xmpp::jid::removeResource $jid]
-
-    if {[info exists juick_nicknames($jid)]} {
-        set uname $juick_nicknames($jid)
+        if {[string equal $tag "juick"] && \
+            [string equal $xmlns "http://juick.com/message"]} \
+        {
+            set replytoyou [::xmpp::xml::getAttr $attrs replytoyou false]
+            if {[string equal $replytoyou true]} {
+                return 1
+            }
+        }
     }
 
-    return $uname
+    return 0
 }
 
-proc is_personal_juick_message {from body} {
-    variable juick_nicknames
-    set reply_to_my_comment 0
+proc is_personal_juick_message {from body x} {
+    set private_msg [regexp {^Private message from @.+:\n} $body]
 
-    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 [string equal \
-            [get_juick_nickname $from] $reply_to_nick]
-    }
-
+    set reply_to_my_comment [expr {$reply_to_comment && [is_reply_to_you $x]}]
     return [expr {$private_msg || $reply_to_my_comment}]
 }
 
@@ -264,7 +217,7 @@
 
     set cw [chat::winid $chatid]
 
-    if {[is_personal_juick_message $from $body]} {
+    if {[is_personal_juick_message $from $body $x]} {
         tab_set_updated $cw 1 mesg_to_user
     } else {
         tab_set_updated $cw 1 message
@@ -305,7 +258,7 @@
 
     incr number_msg($chatid)
 
-    if {[is_personal_juick_message $from $body]} {
+    if {[is_personal_juick_message $from $body $x]} {
         incr personal_msg($chatid)
     }
 

Modified: branches/plugins-0.11.1/juick/tkabber-0.11.1-compatibility.tcl
===================================================================
--- branches/plugins-0.11.1/juick/tkabber-0.11.1-compatibility.tcl	2013-09-18 17:02:58 UTC (rev 537)
+++ branches/plugins-0.11.1/juick/tkabber-0.11.1-compatibility.tcl	2013-09-18 17:04:06 UTC (rev 538)
@@ -183,8 +183,16 @@
     uplevel #0 $cmd [list $res $child]
 }
 
-proc ::xmpp::xml::getAttr {attrList attrName} {
-    ::jlib::wrapper:getattr $attrList $attrName
+proc ::xmpp::xml::getAttr {attrList attrName {fallback ""}} {
+    set res $fallback
+
+    foreach {attr val} $attrList {
+        if {[string equal $attr $attrName]} {
+            set res $val
+        }
+    }
+
+    return $res
 }
 
 proc ::chat::activate {chatid} {



More information about the Tkabber-dev mailing list