Skip to content

Commit

Permalink
fix(frontend/backend): make various fixes (cypht-org#1399)
Browse files Browse the repository at this point in the history
* fix(frontend/backend): make various fixes, including: the snooze action, background message list refresh clearing checked checkboxes, settings sections not expanding correctly, & strange error message when copying messages

* fix load_compose_page test
  • Loading branch information
mercihabam authored Dec 5, 2024
1 parent 116b8a5 commit e7e4299
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 78 deletions.
10 changes: 5 additions & 5 deletions modules/core/js_modules/Hm_MessagesStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Hm_MessagesStore {
*/
markRowAsRead(uid) {
const rows = Object.entries(this.rows);
const row = this.#getRowByUid(uid)?.value;
const row = this.getRowByUid(uid)?.value;

if (row) {
const htmlRow = $(row[1]['0']);
Expand All @@ -96,7 +96,7 @@ class Hm_MessagesStore {
*/
getNextRowForMessage(uid) {
const rows = Object.entries(this.rows);
const row = this.#getRowByUid(uid)?.index;
const row = this.getRowByUid(uid)?.index;

if (row !== false) {
const nextRow = rows[row + 1];
Expand All @@ -114,7 +114,7 @@ class Hm_MessagesStore {
*/
getPreviousRowForMessage(uid) {
const rows = Object.entries(this.rows);
const row = this.#getRowByUid(uid)?.index;
const row = this.getRowByUid(uid)?.index;
if (row) {
const previousRow = rows[row - 1];
if (previousRow) {
Expand All @@ -126,7 +126,7 @@ class Hm_MessagesStore {

removeRow(uid) {
const rows = Object.entries(this.rows);
const row = this.#getRowByUid(uid);
const row = this.getRowByUid(uid);
if (row) {
const newRows = rows.filter((_, i) => i !== row.index);
this.rows = Object.fromEntries(newRows);
Expand Down Expand Up @@ -226,7 +226,7 @@ class Hm_MessagesStore {
* @param {String} uid
* @returns {RowOutput|false} row - The row object if found, false otherwise
*/
#getRowByUid(uid) {
getRowByUid(uid) {
const rows = Object.entries(this.rows);
const row = rows.find(([key, value]) => $(value['0']).attr('data-uid') == uid);

Expand Down
14 changes: 10 additions & 4 deletions modules/core/js_modules/route_handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ function applyServersPageHandlers() {
if (window.wpServersPageHandler) wpServersPageHandler();
}

function applySettingsPageHandlers() {
Hm_Utils.expand_core_settings();
function applySettingsPageHandlers(routeParams, hash) {
if (hash) {
Hm_Utils.toggle_page_section(`.${hash}`);
}

$('.settings_subtitle').on("click", function() { return Hm_Utils.toggle_page_section($(this).data('target')); });
$('.reset_default_value_checkbox').on("click", reset_default_value_checkbox);
$('.reset_default_value_select').on("click", reset_default_value_select);
$('.reset_default_value_input').on("click", reset_default_value_input);
$('.reset_default_timezone').on("click", reset_default_timezone);

if (window.expand_feed_settings) expand_feed_settings();
if (window.smtpSettingsPageHandler) smtpSettingsPageHandler();
}

Expand All @@ -53,6 +54,11 @@ function applyInfoPageHandlers() {
if (window.github_repo_update) github_repo_update();
}, 100);

$('.config_map_page').on("click", function() {
var target = $(this).data('target');
$('.'+target).toggle();
});

return () => {
clearTimeout(timer);
}
Expand Down
5 changes: 3 additions & 2 deletions modules/core/navigation/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,15 @@ async function navigate(url) {
function renderPage(href) {
window.dispatchEvent(new CustomEvent('page-change'));

const searchParams = new URL(href, window.location.origin).searchParams;
const url = new URL(href, window.location.origin);
const searchParams = url.searchParams;
const page = searchParams.get('page');

if (page) {
const route = ROUTES.find(route => route.page === page);
const routeParams = Object.fromEntries(searchParams.entries());
if (route) {
const unMountCallback = route.handler(routeParams);
const unMountCallback = route.handler(routeParams, url.hash?.substring(1));
return unMountCallback;
}
}
Expand Down
36 changes: 0 additions & 36 deletions modules/core/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,6 @@ var Hm_Folders = {
Hm_Folders.update_folder_list();
sessionStorage.clear();
Hm_Utils.restore_local_settings(ui_state);
Hm_Utils.expand_core_settings();
return true;
}
return false;
Expand Down Expand Up @@ -1429,41 +1428,6 @@ var Hm_Utils = {
return false;
},

expand_core_settings: function() {
var sections = Hm_Utils.get_core_settings();
var key;
var dsp;
for (key in sections) {
dsp = sections[key];
if (!dsp) {
dsp = 'none';
}
$(key).css('display', dsp);
Hm_Utils.save_to_local_storage(key, dsp);
}
},

get_core_settings: function() {
var dsp;
var results = {}
var i;
var hash = window.location.hash;
var sections = ['.wp_notifications_setting', '.github_all_setting', '.tfa_setting', '.sent_setting', '.general_setting', '.unread_setting', '.flagged_setting', '.all_setting', '.email_setting', '.junk_setting', '.trash_setting', '.drafts_setting','.tag_setting'];
for (i=0;i<sections.length;i++) {
dsp = Hm_Utils.get_from_local_storage(sections[i]);
if (hash) {
if (hash.replace('#', '.') != sections[i]) {
dsp = 'none';
}
else {
dsp = 'table-row';
}
}
results[sections[i]] = dsp;
}
return results;
},

get_from_local_storage: function(key) {
var prefix = window.location.pathname;
key = prefix+key;
Expand Down
5 changes: 0 additions & 5 deletions modules/developer/site.js
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
'use strict';

$('.config_map_page').on("click", function() {
var target = $(this).data('target');
$('.'+target).toggle();
});
8 changes: 4 additions & 4 deletions modules/imap/handler_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,7 @@ public function process() {
if (!$success) {
return;
}
$snoozed_messages = 0;
$snoozed_messages = [];
$snooze_tag = null;
if ($form['imap_snooze_until'] != 'unsnooze') {
$at = date('D, d M Y H:i:s O');
Expand All @@ -1162,14 +1162,14 @@ public function process() {
if (imap_authed($imap)) {
$folder = hex2bin($folder);
if (snooze_message($imap, $msg_id, $folder, $snooze_tag)) {
$snoozed_messages++;
$snoozed_messages[] = $msg_id;
}
}
}
$this->out('snoozed_messages', $snoozed_messages);
if ($snoozed_messages == count($ids)) {
if (count($snoozed_messages) == count($ids)) {
$msg = 'Messages snoozed';
} elseif ($snoozed_messages > 0) {
} elseif (count($snoozed_messages) > 0) {
$msg = 'Some messages have been snoozed';
} else {
$msg = 'ERRFailed to snooze selected messages';
Expand Down
9 changes: 6 additions & 3 deletions modules/imap/hm-imap.php
Original file line number Diff line number Diff line change
Expand Up @@ -1892,11 +1892,14 @@ public function append_feed($string) {
*/
public function append_end() {
$result = $this->get_response(false, true);
$uid = $result[0][5];
if ($this->check_response($result, true)) {
return $uid;
$res = preg_grep('/APPENDUID/', array_map('json_encode', $result));
if ($res) {
$line = json_decode(reset($res), true);
return $line[5];
}
}
return false;
return $result;
}

/* ------------------ HELPERS ------------------------------------------ */
Expand Down
2 changes: 1 addition & 1 deletion modules/imap/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@
'imap_delete_error' => array(FILTER_VALIDATE_BOOLEAN, false),
'move_count' => array(FILTER_DEFAULT, FILTER_REQUIRE_ARRAY),
'show_pagination_links' => array(FILTER_VALIDATE_BOOLEAN, false),
'snoozed_messages' => array(FILTER_VALIDATE_INT, false),
'snoozed_messages' => array(FILTER_DEFAULT, FILTER_REQUIRE_ARRAY),
'auto_advance_email_enabled' => array(FILTER_VALIDATE_BOOLEAN, false),
'do_not_flag_as_read_on_open' => array(FILTER_VALIDATE_BOOLEAN, false),
'ajax_imap_folders_permissions' => array(FILTER_UNSAFE_RAW, FILTER_REQUIRE_ARRAY),
Expand Down
57 changes: 39 additions & 18 deletions modules/imap/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,24 @@ var remove_from_cached_imap_pages = function(msg_cache_key) {

async function select_imap_folder(path, reload, processInTheBackground = false, abortController = null) {
const messages = new Hm_MessagesStore(path, Hm_Utils.get_url_page_number(), null, abortController);
await messages.load(reload, processInTheBackground).then(() => {
display_imap_mailbox(messages.rows, messages.links, path);
await messages.load(reload, processInTheBackground).then(() => {
if (processInTheBackground) {
for (const index in messages.rows) {
const row = messages.rows[index][0];
const rowUid = $(row).data('uid');
const rowExist = Hm_Utils.tbody().find(`tr[data-uid="${rowUid}"]`).length;
if (!rowExist) {
Hm_Utils.rows().eq(index).before(row);
};
}
Hm_Utils.rows().each(function() {
if (!messages.getRowByUid($(this).data('uid'))) {
$(this).remove();
}
});
} else {
display_imap_mailbox(messages.rows, messages.links);
}
});

if (path === 'unread') {
Expand Down Expand Up @@ -397,7 +413,6 @@ var setup_imap_folder_page = async function(listPath) {
$('.imap_keyword').on('search', function() {
$('#imap_filter_form').trigger('submit');
});
Hm_Ajax.add_callback_hook('ajax_message_action', function() { select_imap_folder(listPath, true); });

const hadLocalData = new Hm_MessagesStore(listPath, Hm_Utils.get_url_page_number()).hasLocalData();
await select_imap_folder(listPath);
Expand Down Expand Up @@ -433,7 +448,8 @@ $('#imap_filter_form').on('submit', async function(event) {
}
});

var display_imap_mailbox = function(rows, links, path = getListPathParam()) {
var display_imap_mailbox = function(rows, links) {
Hm_Message_List.toggle_msg_controls();
if (rows) {
Hm_Message_List.update(rows);
Hm_Message_List.check_empty_list();
Expand Down Expand Up @@ -844,16 +860,11 @@ var search_selected_for_imap = function() {
};

var unselect_non_imap_messages = function() {
var unselected = 0;
$('input[type=checkbox]').each(function() {
$('.message_table_body .checkbox_cell input[type=checkbox]').each(function() {
if (this.checked && this.id.search('imap') == -1) {
this.checked = false;
unselected++;
}
});
if (unselected > 0) {
Hm_Notices.show({0: 'ERR'+$('.move_to_string3').val()});
}
};

var imap_move_copy = function(e, action, context) {
Expand Down Expand Up @@ -1081,11 +1092,11 @@ var imap_setup_snooze = function() {
$(document).on('click', '.snooze_date_picker', function(e) {
document.querySelector('.snooze_input_date').showPicker();
});
$(document).on('click', '.snooze_helper', function(e) {
$('.snooze_helper').on('click', function(e) {
e.preventDefault();
$('.snooze_input').val($(this).attr('data-value')).trigger('change');
});
$(document).on('input', '.snooze_input_date', function(e) {
$('.snooze_input_date').on('input', function(e) {
var now = new Date();
now.setMinutes(now.getMinutes() + 1);
$(this).attr('min', now.toJSON().slice(0, 16));
Expand All @@ -1095,12 +1106,12 @@ var imap_setup_snooze = function() {
$('.snooze_date_picker').css({'border': 'unset', 'border-top': '1px solid #ddd'});
}
});
$(document).on('change', '.snooze_input_date', function(e) {
$('.snooze_input_date').on('change', function(e) {
if ($(this).val() && new Date().getTime() < new Date($(this).val()).getTime()) {
$('.snooze_input').val($(this).val()).trigger('change');
}
});
$(document).on('change', '.snooze_input', function(e) {
$('.snooze_input').on('change', function(e) {
$('.snooze_dropdown').hide();
var ids = [];
if (getPageNameParam() == 'message') {
Expand All @@ -1121,11 +1132,21 @@ var imap_setup_snooze = function() {
[{'name': 'hm_ajax_hook', 'value': 'ajax_imap_snooze'},
{'name': 'imap_snooze_ids', 'value': ids},
{'name': 'imap_snooze_until', 'value': $(this).val()}],
function(res) {
if (res.snoozed_messages > 0) {
async function(res) {
const snoozedMessages = Object.values(res['snoozed_messages']);
if (snoozedMessages.length) {
const path = getParam("list_parent") || getListPathParam();
const store = new Hm_MessagesStore(path, Hm_Utils.get_url_page_number());
await store.load(false, true, true);

snoozedMessages.forEach((msg) => {
store.removeRow(msg);
});
if (getPageNameParam() == 'message_list') {
display_imap_mailbox(store.rows, store.links, getListPathParam());
}

Hm_Folders.reload_folders(true);
var path = hm_list_parent()? hm_list_parent(): getListPathParam();
window.location.replace('?page=message_list&list_path='+path);
}
}
);
Expand Down
1 change: 1 addition & 0 deletions tests/selenium/send.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def __init__(self):

def load_compose_page(self):
self.load()
self.wait_on_class('menu_compose')
list_item = self.by_class('menu_compose')
link = list_item.find_element(By.TAG_NAME, 'a').click()
self.wait_with_folder_list()
Expand Down

0 comments on commit e7e4299

Please sign in to comment.