[Tkabber-dev] r1366 - branches/xml-import-export/plugins/roster

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Sat Feb 2 05:08:12 MSK 2008


Author: kostix
Date: 2008-02-02 05:08:11 +0300 (Sat, 02 Feb 2008)
New Revision: 1366

Modified:
   branches/xml-import-export/plugins/roster/TODO
   branches/xml-import-export/plugins/roster/backup.tcl
Log:
roster/backup.tcl: Implemented synchronous sending of roster contacts
 to the server (in one piece). This ensures that the roster is populated
 with contacts before sending out annotations.

roster/TODO: Tasks updated.


Modified: branches/xml-import-export/plugins/roster/TODO
===================================================================
--- branches/xml-import-export/plugins/roster/TODO	2008-02-01 00:23:51 UTC (rev 1365)
+++ branches/xml-import-export/plugins/roster/TODO	2008-02-02 02:08:11 UTC (rev 1366)
@@ -1,10 +1,14 @@
-* Roster notes aren't added because they are fetched and matched
-  against the roster items before the latter are pushed back
-  from the server (race condition).
+* Reimplement restore logic so that roster contacts are always
+  sent first.
 
-  Probably we should send all the things fetched from a backup
-  file at once, after the parsing.
+* Probably rething the logic once more: in theory, it could be
+  possible to populate roster with restored contacts w/o
+  sending them to the server (which could be done independently,
+  at any time). In this case we don't have to synchronize
+  with restoring annotations.
 
-  Or we should make certain all roster contacts are sent to the
-  server and pushed back, then manipulate roster notes.
+* Gateways and "gated" contacts doesn't appear to have correct
+  category/subtype -- investigate whether it's possible to
+  use that heuristic mechs to get them on the fly as they're
+  pushed from the server during the restoration process.
 

Modified: branches/xml-import-export/plugins/roster/backup.tcl
===================================================================
--- branches/xml-import-export/plugins/roster/backup.tcl	2008-02-01 00:23:51 UTC (rev 1365)
+++ branches/xml-import-export/plugins/roster/backup.tcl	2008-02-02 02:08:11 UTC (rev 1366)
@@ -21,6 +21,9 @@
 	[namespace current]::serialize_roster_contacts
     hook::add deserialize_roster_hook \
 	[namespace current]::deserialize_roster_contacts
+
+    hook::add roster_push_hook \
+	[namespace current]::process_roster_push
 }
 
 ###############################################################################
@@ -173,6 +176,7 @@
 
 proc rosterbackup::deserialize_roster_contacts {connid data} {
     global NS
+    variable sent
 
     jlib::wrapper:splitxml $data tag vars isempty cdata children
 
@@ -183,21 +187,33 @@
 	    must be \"$NS(roster)\""
     }
 
-    array set jids {}
+    array set existing {}
     foreach jid [::roster::get_jids $connid] {
-	set jids($jid) {}
+	set existing($jid) {}
     }
 
+    upvar 0 sent($connid,jids) jids
+    set jids [list]
+    set subtags [list]
+
     foreach child $children {
 	set jid [get_item_jid $child]
-	if {![info exists jids($jid)]} {
-	    jlib::send_iq set \
-		[jlib::wrapper:createtag query \
-		     -vars [list xmlns $NS(roster)] \
-		     -subtags [list $child]] \
-		-connection $connid
+	if {![info exists existing($jid)]} {
+	    lappend jids $jid
+	    lappend subtags $child
 	}
     }
+
+    if {[llength $subtags] > 0} {
+	set sync [namespace current]::sent($connid,status)
+	set $sync WAITING
+	jlib::send_iq set \
+	    [jlib::wrapper:createtag query \
+		 -vars [list xmlns $NS(roster)] \
+		 -subtags $subtags] \
+	    -connection $connid
+	vwait $sync
+    }
 }
 
 ###############################################################################
@@ -207,4 +223,24 @@
     jlib::wrapper:getattr $vars jid
 }
 
+###############################################################################
+
+proc rosterbackup::process_roster_push {connid jid name groups subsc ask} {
+    variable sent
+    upvar 0 sent($connid,status) status
+    upvar 0 sent($connid,jids) jids
+
+    if {[string equal $status WAITING]} {
+	set ix [lsearch -exact $jids $jid]
+	if {$ix >= 0} {
+	    if {[llength $jids] == 1} {
+		unset jids
+		set status COMPLETE
+	    } else {
+		set jids [lreplace $jids $ix $ix]
+	    }
+	}
+    }
+}
+
 # vim:ts=8:sw=4:sts=4:noet



More information about the Tkabber-dev mailing list