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 Dec 10, 2024
1 parent 87e4eb9 commit 693fca3
Show file tree
Hide file tree
Showing 10 changed files with 230 additions and 507 deletions.
24 changes: 21 additions & 3 deletions modules/core/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -619,8 +619,26 @@ function check_file_upload($request, $key) {
return true;
}}

if (!hm_exists('get_nexter_date')) {
function get_nexter_date($format, $only_label = false) {
function privacy_setting_callback($val, $key, $mod) {
$setting = Hm_Output_privacy_settings::$settings[$key];
$key .= '_setting';
$user_setting = $mod->user_config->get($key);
$update = $mod->request->post['update'];

if ($update) {
$val = implode($setting['separator'], array_filter(array_merge(explode($setting['separator'], $user_setting), [$val])));
$mod->user_config->set($key, $val);

$user_data = $mod->session->get('user_data', array());
$user_data[$key] = $val;
$mod->session->set('user_data', $user_data);
$mod->session->record_unsaved('Privacy settings updated');
}
return $val;
}

if (!hm_exists('get_scheduled_date')) {
function get_scheduled_date($format, $only_label = false) {
if ($format == 'later_in_day') {
$date_string = 'today 18:00';
$label = 'Later in the day';
Expand Down Expand Up @@ -675,7 +693,7 @@ function schedule_dropdown($output, $send_now = false) {
}
$txt .= '<ul class="dropdown-menu nexter_dropdown schedule_dropdown" aria-labelledby="dropdownMenuNexterDate">';
foreach ($values as $format) {
$labels = get_nexter_date($format, true);
$labels = get_scheduled_date($format, true);
$txt .= '<li><a href="#" class="nexter_date_helper dropdown-item d-flex justify-content-between gap-5" data-value="'.$format.'"><span>'.$output->trans($labels[0]).'</span> <span class="text-end">'.$labels[1].'</span></a></li>';
}
$txt .= '<li><hr class="dropdown-divider"></li>';
Expand Down
22 changes: 2 additions & 20 deletions modules/core/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -1789,18 +1789,6 @@ var hasLeadingOrTrailingSpaces = function(str) {
return str !== str.trim();
};

var sprintf = function(format, ...args) {
let i = 0;
return format.replace(/%([sd])/g, (match, type) => {
let arg = args[i++];
switch (type) {
case 's': return String(arg);
case 'd': return Number(arg);
default: return match;
}
});
}

/* create a default message list object */
var Hm_Message_List = new Message_List();

Expand Down Expand Up @@ -1847,13 +1835,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 @@ -2411,7 +2393,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
2 changes: 1 addition & 1 deletion modules/imap/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1470,7 +1470,7 @@ function snooze_dropdown($output, $unsnooze = false) {
<button type="button" class="btn btn-light btn-sm dropdown-toggle" id="dropdownMenuNexterDate" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="true">'.$output->trans('Snooze').'</button>
<ul class="dropdown-menu nexter_dropdown snooze_dropdown" aria-labelledby="dropdownMenuNexterDate">';
foreach ($values as $format) {
$labels = get_nexter_date($format, true);
$labels = get_scheduled_date($format, true);
$txt .= '<li><a href="#" class="nexter_date_helper dropdown-item d-flex justify-content-between gap-5" data-value="'.$format.'"><span>'.$output->trans($labels[0]).'</span> <span class="text-end">'.$labels[1].'</span></a></li>';
}
$txt .= '<li><hr class="dropdown-divider"></li>';
Expand Down
2 changes: 1 addition & 1 deletion modules/imap/handler_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ public function process() {
$snooze_tag = null;
if ($form['imap_snooze_until'] != 'unsnooze') {
$at = date('D, d M Y H:i:s O');
$until = get_nexter_date($form['imap_snooze_until']);
$until = get_scheduled_date($form['imap_snooze_until']);
$snooze_tag = "X-Snoozed: at $at; until $until";
}
$ids = explode(',', $form['imap_snooze_ids']);
Expand Down
19 changes: 17 additions & 2 deletions modules/imap/js_modules/route_handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,25 @@ function applyImapMessageListPageHandlers(routeParams) {
imap_setup_snooze();
imap_setup_tags();

Hm_Message_List.set_row_events();

handleNexterDateAction();

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

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

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);
Expand All @@ -33,4 +48,4 @@ function applyImapMessageContentPageHandlers(routeParams) {

if (window.pgpMessageContentPageHandler) pgpMessageContentPageHandler();
if (window.wpMessageContentPageHandler) wpMessageContentPageHandler(routeParams);
}
}
50 changes: 50 additions & 0 deletions modules/imap/js_modules/utils/handleNexterDateAction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
function handleNexterDateAction(e) {
let reload_and_redirect = function () {
Hm_Folders.reload_folders(true);
let path = hm_list_parent() ? hm_list_parent() : hm_list_path();
window.location.replace('?page=message_list&list_path=' + path);
};

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

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

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();
}
}
);
}
if ($(this).parent().parent().is('.schedule_dropdown')) {
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();
}
}
);
}
});
}
66 changes: 0 additions & 66 deletions modules/imap/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -1200,72 +1200,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 693fca3

Please sign in to comment.