Skip to content

Commit

Permalink
[ENH]add Cypht-delay-send-later-scheduled-sending
Browse files Browse the repository at this point in the history
  • Loading branch information
amaninyumu1 committed Nov 1, 2024
1 parent 005e301 commit 14a305b
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 192 deletions.
10 changes: 2 additions & 8 deletions modules/core/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -1954,13 +1954,7 @@ $(function() {
if (hm_mailto()) {
try { navigator.registerProtocolHandler("mailto", "?page=compose&compose_to=%s", "Cypht"); } catch(e) {}
}

if (hm_page_name() == 'home') {
$('.pw_update').on("click", function() { update_password($(this).data('id')); });
}
if (hm_page_name() == 'servers') {
$('.edit_server_connection').on('click', imap_smtp_edit_action);
}

if (hm_mobile()) {
swipe_event(document.body, function() { Hm_Folders.open_folder_list(); }, 'right');
swipe_event(document.body, function() { Hm_Folders.hide_folder_list(); }, 'left');
Expand Down Expand Up @@ -2518,7 +2512,7 @@ const observeMessageTextMutationAndHandleExternalResources = (inline) => {
}
};

var setup_nexter_date = function(callback) {
function setupNexterDate(callback) {
$(document).on('click', '.nexter_date_picker', function(e) {
document.querySelector('.nexter_input_date').showPicker();
});
Expand Down
77 changes: 72 additions & 5 deletions modules/imap/js_modules/route_handlers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
function applyImapMessageListPageHandlers(routeParams) {
const setupPageResult = setup_imap_folder_page(routeParams.list_path);
const listPath = routeParams.list_path;

sortHandlerForMessageListAndSearchPage();

Expand All @@ -9,31 +10,97 @@ function applyImapMessageListPageHandlers(routeParams) {

Hm_Message_List.set_row_events();

$('.core_msg_control').on("click", function(e) {
handleNexterDateAction();

$('.core_msg_control').on("click", function (e) {
e.preventDefault();
Hm_Message_List.message_action($(this).data('action'));
Hm_Message_List.message_action($(this).data('action'));
});
$('.toggle_link').on("click", function(e) {

$('.toggle_link').on("click", function (e) {
e.preventDefault();
Hm_Message_List.toggle_rows();
});

if (listPath.substr(0, 4) === 'imap') {
setup_imap_folder_page(listPath);
} else if (listPath === 'combined_inbox') {
setup_imap_message_list_content_page();
}



if (window.githubMessageListPageHandler) githubMessageListPageHandler(routeParams);
if (window.inlineMessageMessageListAndSearchPageHandler) inlineMessageMessageListAndSearchPageHandler(routeParams);
if (window.wpMessageListPageHandler) wpMessageListPageHandler(routeParams);

return async function() {
return async function () {
const [refreshIntervalId, abortController] = await setupPageResult;
abortController.abort();
clearInterval(refreshIntervalId);
}
}

function handleNexterDateAction(e) {
$('.nexter_dropdown').hide();
var ids = [];
$('input[type=checkbox]').each(function () {
if (this.checked && this.id.search('imap') !== -1) {
var parts = this.id.split('_');
ids.push(parts[1] + '_' + parts[2] + '_' + parts[3]);
}
});

if (ids.length === 0) {
return;
}

var reload_and_redirect = function () {
Hm_Folders.reload_folders(true);
var path = hm_list_parent() ? hm_list_parent() : hm_list_path();
window.location.replace('?page=message_list&list_path=' + path);
};

// Gestion des requêtes selon le type d'action
if ($(this).parent().parent().is('.snooze_dropdown')) {
Hm_Ajax.request(
[
{ '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) {
reload_and_redirect();
}
}
);
} else {
Hm_Ajax.request(
[
{ 'name': 'hm_ajax_hook', 'value': 'ajax_re_schedule_message_sending' },
{ 'name': 'scheduled_msg_ids', 'value': ids },
{ 'name': 'schedule_date', 'value': $(this).val() }
],
function (res) {
if (res.scheduled_msg_count > 0) {
reload_and_redirect();
}
}
);
}
}

function applyImapMessageContentPageHandlers(routeParams) {
imap_setup_message_view_page(routeParams.uid, null, routeParams.list_path, handleExternalResources);
imap_setup_snooze();
imap_setup_tags();

if (routeParams && routeParams.uid && routeParams.list_path) {
imap_setup_message_view_page(routeParams.uid, null, routeParams.list_path, handleExternalResources);
} else if (hm_list_path().substr(0, 4) === 'imap') {
imap_setup_message_view_page();
}
const messages = new Hm_MessagesStore(routeParams.list_path, routeParams.list_page);
messages.load(false);
const next = messages.getNextRowForMessage(routeParams.uid);
Expand All @@ -51,4 +118,4 @@ function applyImapMessageContentPageHandlers(routeParams) {
if (window.githubMessageContentPageHandler) githubMessageContentPageHandler(routeParams);
if (window.pgpMessageContentPageHandler) pgpMessageContentPageHandler();
if (window.wpMessageContentPageHandler) wpMessageContentPageHandler(routeParams);
}
}
66 changes: 0 additions & 66 deletions modules/imap/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -1236,72 +1236,6 @@ $(function() {
setTimeout(search_selected_for_imap, 100);
});

if (hm_page_name() === 'message_list' && hm_list_path().substr(0, 4) === 'imap') {
setup_imap_folder_page();
}
else if (hm_page_name() === 'message_list' && hm_list_path() === 'combined_inbox') {
setup_imap_message_list_content_page();
}
else if (hm_page_name() === 'message' && hm_list_path().substr(0, 4) === 'imap') {
imap_setup_message_view_page();
}
else if (hm_page_name() === 'servers') {
imap_setup_server_page();
}
else if (hm_page_name() === 'info') {
setTimeout(imap_status_update, 100);
}

if (hm_page_name() === 'message_list' || hm_page_name() === 'message') {
imap_setup_snooze();
imap_setup_tags();
setup_nexter_date(function(e) {
$('.nexter_dropdown').hide();
var ids = [];
if (hm_page_name() == 'message') {
var list_path = hm_list_path().split('_');
ids.push(list_path[1]+'_'+hm_msg_uid()+'_'+list_path[2]);
} else {
$('input[type=checkbox]').each(function() {
if (this.checked && this.id.search('imap') != -1) {
var parts = this.id.split('_');
ids.push(parts[1]+'_'+parts[2]+'_'+parts[3]);
}
});
if (ids.length == 0) {
return;
};
}
var reload_and_redirect = function() {
Hm_Folders.reload_folders(true);
var path = hm_list_parent()? hm_list_parent(): hm_list_path();
window.location.replace('?page=message_list&list_path='+path);
}
if ($(this).parent().parent().is('.snooze_dropdown')) {
Hm_Ajax.request(
[{'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) {
reload_and_redirect();
}
}
);
} else {
Hm_Ajax.request(
[{'name': 'hm_ajax_hook', 'value': 'ajax_re_schedule_message_sending'},
{'name': 'scheduled_msg_ids', 'value': ids},
{'name': 'schedule_date', 'value': $(this).val()}],
function(res) {
if (res.scheduled_msg_count > 0) {
reload_and_redirect();
}
}
);
}
});
}

if (hm_is_logged()) {
imap_unsnooze_messages();
Expand Down
Loading

0 comments on commit 14a305b

Please sign in to comment.