# HG changeset patch # User Charlie Root # Date 1516280085 18000 # Node ID 4b2bc456ce42d77048846916585cd51cab1d8e9c # Parent 4869fae20b88ffd94dd7873bda7f8fec3937e473 threaded dates sort working diff -r 4869fae20b88 -r 4b2bc456ce42 plugins/thunderbird_labels/thunderbird_labels.php --- 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);