[Tkabber-dev] r2130 - trunk/tkabber

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Sun Feb 2 21:46:37 MSK 2014


Author: sergei
Date: 2014-02-02 21:46:37 +0400 (Sun, 02 Feb 2014)
New Revision: 2130

Modified:
   trunk/tkabber/ChangeLog
   trunk/tkabber/roster.tcl
Log:
	* roster.tcl: Optionally cache roster offline and use roster
	  versioning as in XEP-0237 and later in RFC-6121 (thanks to Jan
	  Zachorowski).


Modified: trunk/tkabber/ChangeLog
===================================================================
--- trunk/tkabber/ChangeLog	2014-02-02 16:26:29 UTC (rev 2129)
+++ trunk/tkabber/ChangeLog	2014-02-02 17:46:37 UTC (rev 2130)
@@ -3,6 +3,10 @@
 	* plugins/general/sigh.tcl, plugins/chat/shuffle.tcl: Disabled
 	  prank plugins.
 
+	* roster.tcl: Optionally cache roster offline and use roster
+	  versioning as in XEP-0237 and later in RFC-6121 (thanks to Jan
+	  Zachorowski).
+
 2014-01-30  Sergei Golovan  <sgolovan at nes.ru>
 
 	* plugins/chat/logger.tcl: Store 'me' attribute in log files and

Modified: trunk/tkabber/roster.tcl
===================================================================
--- trunk/tkabber/roster.tcl	2014-02-02 16:26:29 UTC (rev 2129)
+++ trunk/tkabber/roster.tcl	2014-02-02 17:46:37 UTC (rev 2130)
@@ -7,6 +7,16 @@
     variable undef_group_name [::msgcat::mc "Undefined"]
     variable chats_group_name [::msgcat::mc "Active Chats"]
     variable own_resources_group_name [::msgcat::mc "My Resources"]
+
+    custom::defgroup Roster [::msgcat::mc "Roster options."] -group Tkabber
+
+    custom::defvar cache_roster_offline 0 \
+	[::msgcat::mc "Cache roster items offline and use roster versioning\
+		       if supported by a server."] \
+	-type boolean -group Roster \
+
+    custom::defvar offline_roster_cache {} "Offline cache for XEP-0237" \
+	-group Hidden
 }
 
 proc roster::process_item {xlib jid name groups subsc ask} {
@@ -80,21 +90,46 @@
 }
 
 proc roster::request_roster {xlib} {
+    variable cache_roster_offline
+    variable offline_roster_cache
     variable roster
 
+    set args {}
+    if {$cache_roster_offline} {
+	debugmsg roster "We use the roster cache now..."
+
+	array set tmp $offline_roster_cache
+	set bjid [::xmpp::jid::normalize [connection_bare_jid $xlib]]
+	if {[info exists tmp($bjid)]} {
+	    lassign $tmp($bjid) version cache
+	    set args [list -version $version -cache $cache]
+	}
+    }
+
     set roster(jids,$xlib) {}
     set roster(token,$xlib) \
-	[::xmpp::roster::new $xlib -itemcommand [list client:roster_push $xlib]]
+	[eval [list ::xmpp::roster::new $xlib -itemcommand [list client:roster_push $xlib]] $args]
     ::xmpp::roster::get $roster(token,$xlib) -command [list client:roster_cmd $xlib]
 }
 
 hook::add connected_hook [namespace current]::roster::request_roster 10
 
 proc roster::clean {xlib} {
+    variable cache_roster_offline
+    variable offline_roster_cache
     variable roster
 
     if {[info exists roster(token,$xlib)]} {
-	::xmpp::roster::free $roster(token,$xlib)
+	lassign [::xmpp::roster::free $roster(token,$xlib)] version cache
+
+	if {$cache_roster_offline} {
+	    debugmsg roster "We caching the roster now..."
+
+	    array set tmp $offline_roster_cache
+	    set bjid [::xmpp::jid::normalize [connection_bare_jid $xlib]]
+	    set tmp($bjid) [list $version $cache]
+	    set offline_roster_cache [array get tmp]
+	}
     }
 
     array unset roster token,$xlib



More information about the Tkabber-dev mailing list