[Tkabber-dev] r1645 - in trunk/tkabber: . plugins/roster

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Wed Feb 11 20:34:59 MSK 2009


Author: sergei
Date: 2009-02-11 20:34:59 +0300 (Wed, 11 Feb 2009)
New Revision: 1645

Removed:
   trunk/tkabber/plugins/roster/roster_delimiter.tcl
   trunk/tkabber/private.tcl
Modified:
   trunk/tkabber/ChangeLog
   trunk/tkabber/plugins/roster/annotations.tcl
   trunk/tkabber/plugins/roster/conferences.tcl
Log:
	* private.tcl: Removed in favour of private XML storage interface in
	  TclXMPP.

	* plugins/roster/annotations.tcl: Use storing/retrieving notes from
	  TclXMPP.

	* plugins/roster/conferences.tcl: Use private XML storage interface in
	  TclXMPP.

	* plugins/roster/roster_delimiter.tcl: Removed as the same
	  functionality appeared in TclXMPP.


Modified: trunk/tkabber/ChangeLog
===================================================================
--- trunk/tkabber/ChangeLog	2009-02-11 17:30:06 UTC (rev 1644)
+++ trunk/tkabber/ChangeLog	2009-02-11 17:34:59 UTC (rev 1645)
@@ -1,3 +1,17 @@
+2009-02-11  Sergei Golovan  <sgolovan at nes.ru>
+
+	* private.tcl: Removed in favour of private XML storage interface in
+	  TclXMPP.
+
+	* plugins/roster/annotations.tcl: Use storing/retrieving notes from
+	  TclXMPP.
+
+	* plugins/roster/conferences.tcl: Use private XML storage interface in
+	  TclXMPP.
+
+	* plugins/roster/roster_delimiter.tcl: Removed as the same
+	  functionality appeared in TclXMPP.
+
 2009-02-09  Sergei Golovan  <sgolovan at nes.ru>
 
 	* utils.tcl: Made [rand $n] procedure to produce numbers uniformly

Modified: trunk/tkabber/plugins/roster/annotations.tcl
===================================================================
--- trunk/tkabber/plugins/roster/annotations.tcl	2009-02-11 17:30:06 UTC (rev 1644)
+++ trunk/tkabber/plugins/roster/annotations.tcl	2009-02-11 17:34:59 UTC (rev 1645)
@@ -3,11 +3,11 @@
 # Annotations (XEP-0145) support
 #
 
+package require xmpp::roster::annotations
+
 namespace eval annotations {
     # variable to store roster notes
     array set notes {}
-
-    set ::NS(rosternotes) "storage:rosternotes"
 }
 
 proc annotations::free_notes {xlib} {
@@ -19,35 +19,25 @@
 hook::add disconnected_hook [namespace current]::annotations::free_notes
 
 proc annotations::request_notes {xlib} {
-    variable NS
-    variable notes
-
-    private::retrieve $xlib [list [::xmpp::xml::create storage \
-					    -xmlns $::NS(rosternotes)]] \
-	-command [list [namespace current]::process_notes $xlib]
+    ::xmpp::roster::annotations::retrieve $xlib \
+		-command [list [namespace current]::process_notes $xlib]
 }
 
 hook::add connected_hook [namespace current]::annotations::request_notes
 
-proc annotations::process_notes {xlib status xml} {
+proc annotations::process_notes {xlib status notes} {
     variable notes
 
     if {$status != "ok"} return
 
     free_notes $xlib
 
-    foreach xmldata $xml {
-	::xmpp::xml::split $xmldata tag xmlns attrs cdata subels
-
-	if {$xmlns == $::NS(rosternotes)} {
-	    foreach note $subels {
-		create_note $xlib $note
-	    }
-	}
+    foreach note $notes {
+	create_note $xlib $note
     }
 }
 
-proc annotations::create_note {xlib xmldata args} {
+proc annotations::create_note {xlib note args} {
     variable notes
 
     set merge 0
@@ -61,38 +51,19 @@
 	}
     }
 
-    ::xmpp::xml::split $xmldata tag xmlns attrs cdata subels
+    array set n $note
 
-    set jid   [::xmpp::xml::getAttr $attrs jid]
-    set cdate [::xmpp::xml::getAttr $attrs cdate]
-    set mdate [::xmpp::xml::getAttr $attrs mdate]
-
-    if {![catch { scan_time $cdate } cdate]} {
-	set cdate [clock seconds]
-    }
-    if {![catch { scan_time $mdate } mdate]} {
-	set cdate [clock seconds]
-    }
-
-    if {!$merge || [more_recent $xlib $jid $cdate $mdate]} {
-	set notes($xlib,jid,$jid)   $jid
-	set notes($xlib,cdate,$jid) $cdate
-	set notes($xlib,mdate,$jid) $mdate
-	set notes($xlib,note,$jid)  $cdata
+    if {!$merge || [more_recent $xlib $n(jid) $n(cdate) $n(mdate)]} {
+	set notes($xlib,jid,$jid)   $n(jid)
+	set notes($xlib,cdate,$jid) $n(cdate)
+	set notes($xlib,mdate,$jid) $n(mdate)
+	set notes($xlib,note,$jid)  $n(note)
 	return 1
     } else {
 	return 0
     }
 }
 
-proc annotations::scan_time {timestamp} {
-    if {[regexp {(.*)T(.*)Z} $timestamp -> date time]} {
-	return [clock scan "$date $time" -gmt true]
-    } else {
-	return [clock scan $timestamp -gmt true]
-    }
-}
-
 proc annotations::more_recent {xlib jid cdate mdate} {
     variable notes
 
@@ -135,31 +106,18 @@
 
     set notelist {}
     foreach idx [array names notes $xlib,jid,*] {
+	if {![info exists notes($xlib,note,$jid)] || \
+		$notes($xlib,note,$jid) == ""} continue
+
 	set jid $notes($idx)
 
-	set vars [list jid $jid]
-	if {[info exists notes($xlib,cdate,$jid)]} {
-	    set cdate [clock format $notes($xlib,cdate,$jid) \
-			     -format "%Y-%m-%dT%TZ" -gmt true]
-	}
-	lappend vars cdate $cdate
-	if {[info exists notes($xlib,mdate,$jid)]} {
-	    set mdate [clock format $notes($xlib,mdate,$jid) \
-			     -format "%Y-%m-%dT%TZ" -gmt true]
-	}
-	lappend vars mdate $mdate
-	if {[info exists notes($xlib,note,$jid)] && \
-		$notes($xlib,note,$jid) != ""} {
-	    lappend notelist \
-		[::xmpp::xml::create note \
-			    -attrs $vars \
-			    -cdata $notes($xlib,note,$jid)]
-	}
+	lappend notelist [list jid $jid \
+			       cdate $notes($xlib,cdate,$jid) \
+			       mdate $notes($xlib,mdate,$jid) \
+			       note $notes($xlib,note,$jid)]
     }
 
-    ::xmpp::xml::create storage \
-		-xmlns $::NS(rosternotes) \
-		-subelements $notelist
+    return $notelist
 }
 
 proc annotations::store_notes {xlib args} {
@@ -174,8 +132,8 @@
 	}
     }
 
-    private::store $xlib [list [serialize_notes $xlib]] \
-	-command $command
+    ::xmpp::roster::annotations::store $xlib [serialize_notes $xlib] \
+		-command $command
 }
 
 proc annotations::store_notes_result {xlib res child} {

Modified: trunk/tkabber/plugins/roster/conferences.tcl
===================================================================
--- trunk/tkabber/plugins/roster/conferences.tcl	2009-02-11 17:30:06 UTC (rev 1644)
+++ trunk/tkabber/plugins/roster/conferences.tcl	2009-02-11 17:34:59 UTC (rev 1645)
@@ -28,6 +28,8 @@
 #   </iq>
 #
 
+package require xmpp::private
+
 namespace eval conferences {
     # variable to store roster conference bookmarks
     array set bookmarks {}
@@ -61,13 +63,13 @@
     set responds($xlib) 0
     array unset bookmarks $xlib,*
 
-    private::retrieve $xlib [list [::xmpp::xml::create storage \
-					    -xmlns $::NS(bookmarks)]] \
-	-command [list [namespace current]::process_bookmarks $xlib]
+    ::xmpp::private::retrieve $xlib [list [::xmpp::xml::create storage \
+						-xmlns $::NS(bookmarks)]] \
+	    -command [list [namespace current]::process_bookmarks $xlib]
 
-    private::retrieve $xlib [list [::xmpp::xml::create storage \
-					    -xmlns $::NS(tkabber:groups)]] \
-	-command [list [namespace current]::process_bookmarks $xlib]
+    ::xmpp::private::retrieve $xlib [list [::xmpp::xml::create storage \
+						-xmlns $::NS(tkabber:groups)]] \
+	    -command [list [namespace current]::process_bookmarks $xlib]
 }
 
 hook::add connected_hook [namespace current]::conferences::request_bookmarks 20
@@ -266,8 +268,8 @@
     }
 
     foreach item [serialize_bookmarks $xlib] {
-	private::store $xlib [list $item] \
-	    -command $command
+	::xmpp::private::store $xlib [list $item] \
+		-command $command
     }
 }
 

Deleted: trunk/tkabber/plugins/roster/roster_delimiter.tcl
===================================================================
--- trunk/tkabber/plugins/roster/roster_delimiter.tcl	2009-02-11 17:30:06 UTC (rev 1644)
+++ trunk/tkabber/plugins/roster/roster_delimiter.tcl	2009-02-11 17:34:59 UTC (rev 1645)
@@ -1,79 +0,0 @@
-# $Id$
-#
-# Nested roster groups server-side delimiter storing (XEP-0083).
-#
-
-###############################################################################
-
-namespace eval delimiter {}
-
-###############################################################################
-#
-# Retrieving nested groups delimiter
-#
-
-proc delimiter::request {xlib fallback args} {
-    debugmsg plugins "delimiter::request $xlib $fallback $args"
-    
-    set command ""
-    foreach {key val} $args {
-	switch -- $key {
-	    -command { set command $val }
-	}
-    }
-
-    private::retrieve $xlib [list [::xmpp::xml::create roster \
-					    -xmlns $::NS(delimiter)]] \
-	-command [list [namespace current]::request_result \
-		       $xlib $fallback $command]
-}
-
-proc delimiter::request_result {xlib fallback command status xml} {
-    debugmsg plugins "delimiter::request_result $xlib $status"
-
-    set delimiter $fallback
-
-    if {$status == "ok"} {
-	foreach item $xml {
-	    ::xmpp::xml::split $item tag xmlns attrs cdata subels
-
-	    if {$xmlns == $NS(delimiter)} {
-		set delimiter $cdata
-	    }
-	}
-    }
-
-    if {$command != ""} {
-	eval $command [list $xlib $delimiter]
-    }
-}
-
-###############################################################################
-#
-# Storing nested groups delimiter
-#
-
-proc delimiter::store {xlib delimiter args} {
-    debugmsg plugins "delimiter::store $xlib $delimiter $args"
-
-    set command ""
-    foreach {key val} $args {
-	switch -- $key {
-	    -command { set command $val }
-	}
-    }
-
-    private::store $xlib [list [::xmpp::xml::create roster \
-					-xmlns $::NS(delimiter) \
-					-cdata $delimiter]] \
-	-command [list [namespace current]::store_result $xlib $command]
-}
-
-proc delimiter::store_result {xlib command status xml} {
-    debugmsg plugins "delimiter::store_result $xlib $status"
-    
-    if {$command != ""} {
-	eval $command [list $status $xml]
-    }
-}
-

Deleted: trunk/tkabber/private.tcl
===================================================================
--- trunk/tkabber/private.tcl	2009-02-11 17:30:06 UTC (rev 1644)
+++ trunk/tkabber/private.tcl	2009-02-11 17:34:59 UTC (rev 1645)
@@ -1,56 +0,0 @@
-# $Id$
-#
-# Private XML Storage (XEP-0049) support
-#
-
-namespace eval private {}
-
-proc private::store {xlib query args} {
-    set command ""
-    foreach {key val} $args {
-	switch -- $key {
-	    -command { set command $val }
-	}
-    }
-
-    ::xmpp::sendIQ $xlib set \
-	-query [::xmpp::xml::create query \
-			-xmlns $::NS(private) \
-			-subelements $query] \
-	-command [list [namespace current]::store_result $command]
-}
-
-proc private::store_result {command status xml} {
-    if {$command != ""} {
-	uplevel #0 $command [list $status $xml]
-    }
-}
-
-proc private::retrieve {xlib query args} {
-    set command ""
-    foreach {key val} $args {
-	switch -- $key {
-	    -command { set command $val }
-	}
-    }
-
-    ::xmpp::sendIQ $xlib get \
-	-query [::xmpp::xml::create query \
-			-xmlns $::NS(private) \
-			-subelements $query] \
-	-command [list [namespace current]::retrieve_result $command]
-}
-
-proc private::retrieve_result {command status xml} {
-    if {$command == ""} return
-
-    if {$status != "ok"} {
-	uplevel #0 $command [list $status $xml]
-	return
-    }
-
-    ::xmpp::xml::split $xml tag xmlns attrs cdata subels
-
-    uplevel #0 $command [list ok $subels]
-}
-



More information about the Tkabber-dev mailing list