Skip to content

Commit ba74555

Browse files
authored
Merge pull request #1676 from mercihabam/fix-junk
fix(frontend/backend): remove junked messages from list after successful action and exclude irrelevant msg controls per list to prevent double actions
2 parents c2928d4 + 032f14d commit ba74555

File tree

3 files changed

+26
-21
lines changed

3 files changed

+26
-21
lines changed

modules/core/message_list_functions.php

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -415,27 +415,31 @@ function icon_callback($vals, $style, $output_mod) {
415415
if (!hm_exists('message_controls')) {
416416
function message_controls($output_mod) {
417417
$txt = '';
418+
$controls = ['read', 'unread', 'flag', 'unflag', 'delete', 'archive', 'junk'];
419+
$controls = array_filter($controls, function($val) use ($output_mod) {
420+
if (in_array($val, [$output_mod->get('list_path', ''), strtolower($output_mod->get('core_msg_control_folder', ''))])) {
421+
return false;
422+
}
423+
if ($val == 'flag' && $output_mod->get('list_path', '') == 'flagged') {
424+
return false;
425+
}
426+
return true;
427+
});
428+
418429
$res = '<a class="toggle_link" href="#"><i class="bi bi-check-square-fill"></i></a>'.
419430
'<div class="msg_controls fs-6 d-none gap-1 align-items-center">'.
420431
'<div class="dropdown on_mobile">'.
421432
'<button type="button" class="btn btn-outline-success btn-sm dropdown-toggle" id="coreMsgControlDropdown" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="true">Actions</button>'.
422-
'<ul class="dropdown-menu" aria-labelledby="coreMsgControlDropdown">'.
423-
'<li><a class="dropdown-item msg_read core_msg_control btn btn-sm btn-light text-black-50" href="#" data-action="read">'.$output_mod->trans('Read').'</a></li>'.
424-
'<li><a class="dropdown-item msg_unread core_msg_control btn btn-sm btn-light text-black-50" href="#" data-action="unread">'.$output_mod->trans('Unread').'</a></li>'.
425-
'<li><a class="dropdown-item msg_flag core_msg_control btn btn-sm btn-light text-black-50" href="#" data-action="flag">'.$output_mod->trans('Flag').'</a></li>'.
426-
'<li><a class="dropdown-item msg_unflag core_msg_control btn btn-sm btn-light text-black-50" href="#" data-action="unflag">'.$output_mod->trans('Unflag').'</a></li>'.
427-
'<li><a class="dropdown-item msg_delete core_msg_control btn btn-sm btn-light text-black-50" href="#" data-action="delete">'.$output_mod->trans('Delete').'</a></li>'.
428-
'<li><a class="dropdown-item msg_archive core_msg_control btn btn-sm btn-light text-black-50" href="#" data-action="archive">'.$output_mod->trans('Archive').'</a></li>'.
429-
'<li><a class="dropdown-item msg_junk core_msg_control btn btn-sm btn-light text-black-50" href="#" data-action="junk">'.$output_mod->trans('Junk').'</a></li>'.
430-
'</ul>'.
431-
'</div>'.
432-
'<a class="msg_read core_msg_control btn btn-sm btn-light no_mobile border text-black-50" href="#" data-action="read">'.$output_mod->trans('Read').'</a>'.
433-
'<a class="msg_unread core_msg_control btn btn-sm btn-light no_mobile border text-black-50" href="#" data-action="unread">'.$output_mod->trans('Unread').'</a>'.
434-
'<a class="msg_flag core_msg_control btn btn-sm btn-light no_mobile border text-black-50" href="#" data-action="flag">'.$output_mod->trans('Flag').'</a>'.
435-
'<a class="msg_unflag core_msg_control btn btn-sm btn-light no_mobile border text-black-50" href="#" data-action="unflag">'.$output_mod->trans('Unflag').'</a>'.
436-
'<a class="msg_delete core_msg_control btn btn-sm btn-light no_mobile border text-black-50" href="#" data-action="delete">'.$output_mod->trans('Delete').'</a>'.
437-
'<a class="msg_archive core_msg_control btn btn-sm btn-light no_mobile border text-black-50" href="#" data-action="archive">'.$output_mod->trans('Archive').'</a>'.
438-
'<a class="msg_junk core_msg_control btn btn-sm btn-light no_mobile border text-black-50" href="#" data-action="junk">'.$output_mod->trans('Junk').'</a>';
433+
'<ul class="dropdown-menu" aria-labelledby="coreMsgControlDropdown">';
434+
foreach ($controls as $control) {
435+
$res .= '<li><a class="dropdown-item msg_'.$control.' core_msg_control btn btn-sm btn-light text-black-50" href="#" data-action="'.$control.'">'.$output_mod->trans(ucfirst($control)).'</a></li>';
436+
}
437+
$res .= '</ul>'.
438+
'</div>';
439+
440+
foreach ($controls as $control) {
441+
$res .= '<a class="msg_'.$control.' core_msg_control btn btn-sm btn-light no_mobile border text-black-50" href="#" data-action="'.$control.'">'.$output_mod->trans(ucfirst($control)).'</a>';
442+
}
439443

440444
if ($output_mod->get('msg_controls_extra')) {
441445
$res .= $output_mod->get('msg_controls_extra');

modules/core/site.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ function Message_List() {
736736
if (action_type == 'unsnooze' && getListPathParam() == 'snoozed') {
737737
remove = true;
738738
}
739-
else if (action_type == 'delete' || action_type == 'archive') {
739+
else if (action_type == 'delete' || ['archive', 'junk'].includes(action_type)) {
740740
remove = true;
741741
}
742742
if (remove) {

modules/imap/handler_modules.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -551,14 +551,15 @@ public function process() {
551551
}
552552
}
553553
$folder = hex2bin($parts[2]);
554+
$spcial_folders = get_special_folders($this, $parts[1]);
555+
if (array_key_exists(strtolower($folder), $spcial_folders)) {
556+
$this->out('core_msg_control_folder', $spcial_folders[strtolower($folder)]);
557+
}
554558
if (!empty($details)) {
555559
if (array_key_exists('folder_label', $this->request->get)) {
556560
$folder = $this->request->get['folder_label'];
557561
$this->out('folder_label', $folder);
558562
}
559-
else {
560-
$folder = hex2bin($parts[2]);
561-
}
562563
$mailbox = Hm_IMAP_List::get_mailbox_without_connection($details);
563564
$label = $mailbox->get_folder_name($folder);
564565
$title = array(strtoupper($details['type'] ?? 'IMAP'), $details['name'], $label);

0 commit comments

Comments
 (0)