changeset 25:4b2bc456ce42

threaded dates sort working
author Charlie Root
date Thu, 18 Jan 2018 07:54:45 -0500
parents 4869fae20b88
children b2b6c0af2383
files plugins/thunderbird_labels/thunderbird_labels.php
diffstat 1 files changed, 42 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/thunderbird_labels/thunderbird_labels.php	Wed Jan 17 17:40:51 2018 -0500
+++ b/plugins/thunderbird_labels/thunderbird_labels.php	Thu Jan 18 07:54:45 2018 -0500
@@ -408,11 +408,51 @@
 		    // The threading information is contained in three fields:
 		    //  depth, parent_uid and uid
 		    // I _think_ if you gave every depth0 message its dates as key
-		    //                       every depth>0        its date as key
+		    //                       every depth>0        [already sorted by date, see list.inc:71]
 		    // Then first sort all the depth0 messages into a new array
-		    //  then iterate over them, pull all depth1 with shared parent and sort _them,
+		    //  then iterate over them, pull all depth1 with shared parent
 		    //                          insert after parent
 		    //  repeat at depth 1, etc.
+		    $sm = array(); // sorted result accumulates here
+		    $rm = array(); // unprocessed remnant
+		    foreach ($args['messages'] as $m) {
+		      if ($m->depth===0) {
+			$sm[]=$m;
+			  }
+		      else {
+			$rm[]=$m;
+		      }
+		    }
+		    rcube::write_log($this->name,"ts0: |".$rm[0]->depth."| |".($rm[0]->depth===0)."|");
+		    usort($sm,$datesSort);
+		    $depth=0;
+		    $foundSome=true;
+		    while ($foundSome) {
+		      rcube::write_log($this->name,"ts: $depth ".count($sm).' '.count($rm));
+		      $foundSome=false;
+		      $tsm = array();
+		      $trm = array();
+		      foreach ($sm as $m) {
+			$tsm[]=$m;
+			if ($m->depth===$depth) {
+			  $puid = $m->uid;
+			  foreach ($rm as $c) {
+			    if ($c->parent_uid===$puid) {
+			      $tsm[]=$c;
+			      $foundSome=true;
+			    }
+			    else {
+			      $trm[]=$c;
+			    }
+			  }
+			  $rm = $trm;
+			  $trm = array();
+			}
+		      }
+		      $sm = $tsm;
+		      $depth+=1;
+		    }
+		    $args['messages']=$sm;
 		  }
 		  else {
 		    usort($args['messages'],$datesSort);