Mercurial > hg > rc1
changeset 24:4869fae20b88
do better at flag deletion, unthreaded dates sort working, preparing for threaded
author | Charlie Root |
---|---|
date | Wed, 17 Jan 2018 17:40:51 -0500 |
parents | 5a851d965bc1 |
children | 4b2bc456ce42 |
files | plugins/thunderbird_labels/tb_label.js plugins/thunderbird_labels/thunderbird_labels.php |
diffstat | 2 files changed, 80 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/thunderbird_labels/tb_label.js Wed Jan 17 09:13:17 2018 -0500 +++ b/plugins/thunderbird_labels/tb_label.js Wed Jan 17 17:40:51 2018 -0500 @@ -160,6 +160,7 @@ var rowobj = $(row.obj); if (rcmail.env.tb_label_style=='bullets') { rowobj.find("td.subject span.tb_label_dots span.label"+toggle_label_no).remove(); + rowobj.find("td.dates span").remove(); } else { rowobj.removeClass('label'+toggle_label_no); } @@ -222,7 +223,7 @@ var toggle_label = $(this).parent().attr('class'); var toggle_label_no = parseInt(toggle_label.replace('label', '')); var label_name = rcmail.env.tb_label_custom_labels[toggle_label_no]; - var hasParm = label_name[label_name.length-1]=='1'; + var hasParm = rcmail.env.tb_label_parm_labels[toggle_label_no]; var selection = rcm_tb_label_get_selection(); if (!selection.length) @@ -266,7 +267,13 @@ first_toggle_mode = 'off'; } if (hasParm && first_toggle_mode == 'on') { - toggle_label+='_21/7-11/8'; + var dates=prompt("Booking dates in form d/m-d/m : ","25/7-1/8"); + if (dates!=null){ + toggle_label+='_'+dates; + } + else { + return; + } } var flag_uids = []; var unflag_uids = [];
--- a/plugins/thunderbird_labels/thunderbird_labels.php Wed Jan 17 09:13:17 2018 -0500 +++ b/plugins/thunderbird_labels/thunderbird_labels.php Wed Jan 17 17:40:51 2018 -0500 @@ -332,18 +332,18 @@ public function read_flags($args) { - rcube::write_log($this->name, "read: ".$_SESSION['sort_col']); // add color information for all messages // dont loop over all messages if we dont have any highlights or no msgs if (!isset($args['messages']) or !is_array($args['messages'])) { return $args; } // loop over all messages and add $LabelX info to the extra_flags + $mbox = $this->rc->output->get_env('mailbox') ?: $this->rc->storage->get_folder(); + rcube::write_log($this->name, "mbox: $mbox"); foreach($args['messages'] as $message) { - #rcube::write_log($this->name, print_r($message->flags, true)); $message->list_flags['extra_flags']['tb_labels'] = array(); # always set extra_flags, needed for javascript later! - $message->list_flags['extra_flags']['tb_parms'] = array(); + $message->list_flags['extra_flags']['tb_lparms'] = array(); $keyPos = array_search($_SESSION['sort_col'],$this->rc->config->get('tb_label_parm_labels')); rcube::write_log($this->name,"sort? $keyPos ".$_SESSION['sort_order']." ".print_r($this->rc->config->get('tb_label_parm_labels'),true)); if (is_array($message->flags)) @@ -362,8 +362,8 @@ $message->list_flags['extra_flags']['tb_lparms'][]=array( 'number' => $pn, 'parm' => $pv); - if ($keyPos) { - $message->sortKey=array_map('intval',preg_split('/[/-]/',$pv)); + if ($keyPos && $message->depth==0) { + $message->sortKey=array_map('intval',preg_split('#[/-]#',$pv)); } } else { @@ -374,36 +374,49 @@ } if ($keyPos) { $rev = $_SESSION['sort_order']=='DESC'; - usort($args['messages'], - function($a, $b) use ($rev) { - if ($ak=$a->sortKey) { - if ($bk=$b->sortKey) { - // each key is sd sm ed em - if ($ak[1]<$bk[1]) return $rev?1:-1; - if ($ak[1]>$bk[1]) return $rev?-1:1; - // start month is the same - if ($ak[0]<$bk[0]) return $rev?1:-1; - if ($ak[0]>$bk[0]) return $rev?-1:1; - // start date is the same - if ($ak[3]<$bk[3]) return $rev?1:-1; - if ($ak[3]>$bk[3]) return $rev?-1:1; - // end month is the same - if ($ak[2]<$bk[2]) return $rev?1:-1; - if ($ak[2]>$bk[2]) return $rev?-1:1; - // both dates are the same + $datesSort = + function($a, $b) use ($rev) { + if ($ak=$a->sortKey) { + if ($bk=$b->sortKey) { + // each key is sd sm ed em + if ($ak[1]<$bk[1]) return $rev?1:-1; + if ($ak[1]>$bk[1]) return $rev?-1:1; + // start month is the same + if ($ak[0]<$bk[0]) return $rev?1:-1; + if ($ak[0]>$bk[0]) return $rev?-1:1; + // start date is the same + if ($ak[3]<$bk[3]) return $rev?1:-1; + if ($ak[3]>$bk[3]) return $rev?-1:1; + // end month is the same + if ($ak[2]<$bk[2]) return $rev?1:-1; + if ($ak[2]>$bk[2]) return $rev?-1:1; + // both dates are the same + return 0; + } + else { + return $rev?1:-1; + } + } + else if ($b->sortKey) { + return $rev?-1:1; + } + else { return 0; } - else { - return $rev?1:-1; - } - } - else if ($b->sortKey) { - return $rev?-1:1; - } - else { - return 0; - } - }); + }; + if ($this->rc->config->get('message_threading')[$mbox]) { + // 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 + // Then first sort all the depth0 messages into a new array + // then iterate over them, pull all depth1 with shared parent and sort _them, + // insert after parent + // repeat at depth 1, etc. + } + else { + usort($args['messages'],$datesSort); + } } return($args); } @@ -432,8 +445,31 @@ return false; $imap->set_flag($flag_uids, $toggle_label, $mbox); - $imap->set_flag($unflag_uids, "UN$toggle_label", $mbox); - + // belt and braces + if (count($unflag_uids)>0) { + $flaggedMsgs = $imap->list_flags($mbox,$unflag_uids); + rcube::write_log($this->name,'oldFlags: '.print_r($flaggedMsgs,true)); + $fullFlags=array(); + foreach ($flaggedMsgs as $uid => $flags) { + foreach ($flags as $flag => $x) { + $pos=strpos(strtolower($flag),$toggle_label); + rcube::write_log($this->name,"flag?: $flag $toggle_label $pos"); + if ($pos>-1 && $pos<2 && !in_array($flag,$fullFlags)) { + $fullFlags[]=$flag; + } + } + } + if (count($fullFlags)==0) { + rcube::write_log('errors',"no full flags for $toggle_label in ".print_r($flaggedMsgs,true)); + $imap->set_flag($unflag_uids, "UN$toggle_label", $mbox); + } + else { + foreach ($fullFlags as $flag) { + rcube::write_log($this->name,"UNsetting $flag in $mbox for ".join(',',$unflag_uids)); + $imap->set_flag($unflag_uids, "UN$flag", $mbox); + } + } + } $this->api->output->send(); }