From 7e4063f5c5df8635d64dd34ca30c0c24ea076ed0 Mon Sep 17 00:00:00 2001 From: Merci Jacob Date: Tue, 17 Dec 2024 17:15:25 +0200 Subject: [PATCH] Fix the prev & next links to properly work for the combined view --- modules/core/output_modules.php | 2 +- modules/core/site.js | 21 +++++++++++-------- modules/imap/js_modules/route_handlers.js | 2 +- modules/imap/js_modules/utils/messageParts.js | 2 +- modules/imap/site.js | 20 +++++++++--------- modules/inline_message/site.js | 4 ++-- 6 files changed, 27 insertions(+), 24 deletions(-) diff --git a/modules/core/output_modules.php b/modules/core/output_modules.php index 4e0f68520..496cdeb99 100644 --- a/modules/core/output_modules.php +++ b/modules/core/output_modules.php @@ -2438,7 +2438,7 @@ protected function output() { $messageList = []; $style = $this->get('news_list_style') || $this->get('is_mobile') ? 'news' : 'email'; if ($this->get('imap_combined_inbox_data')) { - $messageList = array_merge($messageList, format_imap_message_list($this->get('imap_combined_inbox_data'), $this, false, $style)); + $messageList = array_merge($messageList, format_imap_message_list($this->get('imap_combined_inbox_data'), $this, 'combined_inbox', $style)); } if ($this->get('feed_list_data')) { $messageList = array_merge($messageList, $this->get('feed_list_data'), Hm_Output_filter_feed_list_data::formatMessageList($this)); diff --git a/modules/core/site.js b/modules/core/site.js index ce4ea483d..9914635a3 100644 --- a/modules/core/site.js +++ b/modules/core/site.js @@ -840,8 +840,9 @@ function Message_List() { }; this.prev_next_links = function(msgUid, lisPath = getListPathParam()) { - let phref; - let nhref; + let prevUrl; + let nextUrl; + const target = $('.msg_headers tr').last(); const messages = new Hm_MessagesStore(lisPath, Hm_Utils.get_url_page_number()); messages.load(false, true); @@ -849,21 +850,23 @@ function Message_List() { const prev = messages.getPreviousRowForMessage(msgUid); if (prev) { const prevSubject = $(prev['0']).find('.subject a'); - phref = prevSubject.prop('href'); + prevUrl = new URL(prevSubject.prop('href')); + prevUrl.searchParams.set('list_parent', lisPath); const subject = prevSubject.text(); - const plink = ' '+subject+''; + const plink = ' '+subject+''; $(''+plink+'').insertBefore(target); } if (next) { const nextSubject = $(next['0']).find('.subject a'); - nhref = nextSubject.prop('href'); + nextUrl = new URL(nextSubject.prop('href')); + nextUrl.searchParams.set('list_parent', lisPath); const subject = nextSubject.text(); - const nlink = ' '+subject+''; + const nlink = ' '+subject+''; $(''+nlink+'').insertBefore(target); } - return [phref, nhref]; + return [prevUrl?.href, nextUrl?.href]; }; this.check_empty_list = function() { @@ -2273,7 +2276,7 @@ function handleAllowResource(element, messagePart, inline = false) { if (inline) { return inline_imap_msg(window.inline_msg_details, window.inline_msg_uid); } - return get_message_content(getParam('part'), getMessageUidParam(), getListPathParam(), false, false, false); + return get_message_content(getParam('part'), getMessageUidParam(), getListPathParam(), getParam('list_parent'), false, false, false); }); } @@ -2360,7 +2363,7 @@ const handleExternalResources = (inline) => { if (inline) { inline_imap_msg(window.inline_msg_details, window.inline_msg_uid); } else { - get_message_content(getParam('part'), getMessageUidParam(), getListPathParam(), false, false, false) + get_message_content(getParam('part'), getMessageUidParam(), getListPathParam(), getParam('list_parent'), false, false, false) } }).finally(() => { popover.dispose(); diff --git a/modules/imap/js_modules/route_handlers.js b/modules/imap/js_modules/route_handlers.js index 6b9860391..41c768a00 100644 --- a/modules/imap/js_modules/route_handlers.js +++ b/modules/imap/js_modules/route_handlers.js @@ -15,7 +15,7 @@ function applyImapMessageListPageHandlers(routeParams) { } function applyImapMessageContentPageHandlers(routeParams) { - imap_setup_message_view_page(routeParams.uid, null, routeParams.list_path, imap_setup_tags); + imap_setup_message_view_page(routeParams.uid, null, routeParams.list_path, routeParams.list_parent, imap_setup_tags); imap_setup_snooze(); const messages = new Hm_MessagesStore(routeParams.list_path, routeParams.list_page); diff --git a/modules/imap/js_modules/utils/messageParts.js b/modules/imap/js_modules/utils/messageParts.js index 8475f2c7c..35f2df0a7 100644 --- a/modules/imap/js_modules/utils/messageParts.js +++ b/modules/imap/js_modules/utils/messageParts.js @@ -7,6 +7,6 @@ function handleViewMessagePart() { const url = new URL(window.location.href); url.searchParams.set('part', messagePart); history.replaceState(history.state, "", url.toString()); - get_message_content(messagePart, getMessageUidParam() ?? inline_msg_uid, getListPathParam()); + get_message_content(messagePart, getMessageUidParam() ?? inline_msg_uid, getListPathParam(), getParam('list_parent') ?? getListPathParam()); }); } \ No newline at end of file diff --git a/modules/imap/site.js b/modules/imap/site.js index 4dbfb7817..cc109f0bc 100644 --- a/modules/imap/site.js +++ b/modules/imap/site.js @@ -210,7 +210,7 @@ var imap_flag_message = function(state, supplied_uid, supplied_detail) { $('#unflag_msg').show(); } set_message_content(); - imap_message_view_finished(false, false, true); + imap_message_view_finished(false, false, getParam('list_parent'), true); } ); } @@ -586,7 +586,7 @@ var expand_imap_folders = function(element) { return false; }; -var get_message_content = function(msg_part, uid, list_path, detail, callback, noupdate) { +var get_message_content = function(msg_part, uid, list_path, listParent, detail, callback, noupdate) { if (!uid) { uid = $('.msg_uid').val(); } @@ -604,7 +604,7 @@ var get_message_content = function(msg_part, uid, list_path, detail, callback, n $('.msg_text').append(res.msg_text); $('.msg_text').append(res.msg_parts); document.title = $('.header_subject th').text(); - imap_message_view_finished(uid, detail); + imap_message_view_finished(uid, detail, listParent); } else { $('.reply_link, .reply_all_link, .forward_link').each(function() { @@ -706,7 +706,7 @@ var block_unblock_sender = function(msg_uid, detail, scope, action, sender = '', ); } -var imap_message_view_finished = function(msg_uid, detail, skip_links) { +var imap_message_view_finished = function(msg_uid, detail, listParent, skip_links) { var class_name = false; if (!detail) { detail = Hm_Utils.parse_folder_path(getListPathParam(), 'imap'); @@ -715,10 +715,10 @@ var imap_message_view_finished = function(msg_uid, detail, skip_links) { msg_uid = getMessageUidParam(); } if (detail && !skip_links) { - Hm_Message_List.prev_next_links(msg_uid); + Hm_Message_List.prev_next_links(msg_uid, listParent); } if (Hm_Message_List.track_read_messages(class_name)) { - if (hm_list_parent() == 'unread') { + if (listParent == 'unread') { Hm_Message_List.adjust_unread_total(-1); } } @@ -782,7 +782,7 @@ var get_local_message_content = function(msg_uid, path) { return Hm_Utils.get_from_local_storage(getMessageStorageKey(msg_uid)); }; -var imap_setup_message_view_page = function(uid, details, list_path, callback) { +var imap_setup_message_view_page = function(uid, details, list_path, listParent, callback) { if (!uid) { uid = getMessageUidParam(); } @@ -795,7 +795,7 @@ var imap_setup_message_view_page = function(uid, details, list_path, callback) { const msg_content = get_local_message_content(uid, list_path); if (!msg_content) { - get_message_content(false, uid, list_path, details, callbackFn); + get_message_content(false, uid, list_path, listParent, details, callbackFn); } else { const msgResponse = JSON.parse(msg_content); @@ -812,8 +812,8 @@ var imap_setup_message_view_page = function(uid, details, list_path, callback) { $(this).data("href", $(this).attr("href")).removeAttr("href"); $(this).addClass('disabled_link'); }); - imap_message_view_finished(uid, details); - get_message_content(false, uid, list_path, details, callback, true); + imap_message_view_finished(uid, details, listParent); + get_message_content(false, uid, list_path, listParent, details, callback, true); } }; diff --git a/modules/inline_message/site.js b/modules/inline_message/site.js index 5ae3ce51a..6e89cc1af 100644 --- a/modules/inline_message/site.js +++ b/modules/inline_message/site.js @@ -42,7 +42,7 @@ var inline_imap_msg = function(details, uid, list_path, inline_msg_loaded_callba clear_open_msg(inline_msg_style()); msg_container(inline_msg_style(), path); - imap_setup_message_view_page(uid, details, list_path, inline_msg_loaded_callback); + imap_setup_message_view_page(uid, details, list_path, list_path, inline_msg_loaded_callback); $('.part_encoding').hide(); $('.part_charset').hide(); $('div', $(path)).removeClass('unseen'); @@ -131,7 +131,7 @@ var capture_subject_click = function() { if ($('.header_subject th').find('i.bi.bi-x-lg.close_inline_msg').length === 0) { $('.header_subject th').append(''); $('.close_inline_msg').on("click", function() { msg_inline_close(); }); - $('.msg_part_link').on("click", function() { return get_message_content($(this).data('messagePart'), uid, list_path, details, inline_msg_loaded_callback); }); + $('.msg_part_link').on("click", function() { return get_message_content($(this).data('messagePart'), uid, list_path, list_path, details, inline_msg_loaded_callback); }); } update_imap_links(uid, details); };