Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the frequency at which messages are prefetched #1297

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions modules/core/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -986,14 +986,14 @@ function Message_List() {
}
};

this.prev_next_links = function() {
this.prev_next_links = function(msgUid) {
let phref;
let nhref;
const target = $('.msg_headers tr').last();
const messages = new Hm_MessagesStore(getListPathParam(), Hm_Utils.get_url_page_number());
messages.load(false, true);
const next = messages.getNextRowForMessage(getMessageUidParam());
const prev = messages.getPreviousRowForMessage(getMessageUidParam());
const next = messages.getNextRowForMessage(msgUid);
const prev = messages.getPreviousRowForMessage(msgUid);
if (prev) {
const prevSubject = $(prev['0']).find('.subject');
phref = prevSubject.find('a').prop('href');
Expand Down
13 changes: 13 additions & 0 deletions modules/imap/js_modules/route_handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ function applyImapMessageContentPageHandlers(routeParams) {
imap_setup_snooze();
imap_setup_tags();

const messages = new Hm_MessagesStore(routeParams.list_path, routeParams.list_page);
messages.load(false);
const next = messages.getNextRowForMessage(routeParams.uid);
const prev = messages.getPreviousRowForMessage(routeParams.uid);
if (next) {
const nextMessageUid = $(next['0']).data('uid');
preFetchMessageContent(false, nextMessageUid, routeParams.list_path);
}
if (prev) {
const prevMessageUid = $(prev['0']).data('uid');
preFetchMessageContent(false, prevMessageUid, routeParams.list_path);
}

if (window.feedMessageContentPageHandler) feedMessageContentPageHandler(routeParams);
if (window.githubMessageContentPageHandler) githubMessageContentPageHandler(routeParams);
if (window.pgpMessageContentPageHandler) pgpMessageContentPageHandler();
Expand Down
55 changes: 6 additions & 49 deletions modules/imap/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,23 +504,14 @@ var display_imap_mailbox = function(rows, links, path = getListPathParam()) {
$('.page_links').html(links);
$('input[type=checkbox]').on("click", function(e) {
Hm_Message_List.toggle_msg_controls();
});

const messages = Object.values(rows);
messages.forEach(function(item) {
const tr = $(item['0']);
const path = item['1'];
const uid = tr.data('uid');

if (Hm_Utils.get_from_local_storage(getMessageStorageKey(uid))) {
return;
}
preFetchMessageContent(false, uid, path);
});
}
};

function preFetchMessageContent(msgPart, uid, path) {
if (Hm_Utils.get_from_local_storage(getMessageStorageKey(uid))) {
return;
}
const detail = Hm_Utils.parse_folder_path(path, 'imap');
Hm_Ajax.request([
{'name': 'hm_ajax_hook', 'value': 'ajax_imap_message_content'},
Expand Down Expand Up @@ -654,7 +645,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();
imap_message_view_finished(uid, detail);
}
else {
$('.reply_link, .reply_all_link, .forward_link').each(function() {
Expand Down Expand Up @@ -765,41 +756,7 @@ var imap_message_view_finished = function(msg_uid, detail, skip_links) {
msg_uid = getMessageUidParam();
}
if (detail && !skip_links) {
class_name = 'imap_'+detail.server_id+'_'+msg_uid+'_'+detail.folder;
if (hm_list_parent() === 'combined_inbox') {
Hm_Message_List.prev_next_links('formatted_combined_inbox', class_name);
}
else if (hm_list_parent() === 'unread') {
Hm_Message_List.prev_next_links('formatted_unread_data', class_name);
}
else if (hm_list_parent() === 'flagged') {
Hm_Message_List.prev_next_links('formatted_flagged_data', class_name);
}
else if (hm_list_parent() === 'advanced_search') {
Hm_Message_List.prev_next_links('formatted_advanced_search_data', class_name);
}
else if (hm_list_parent() === 'search') {
Hm_Message_List.prev_next_links('formatted_search_data', class_name);
}
else if (hm_list_parent() === 'sent') {
Hm_Message_List.prev_next_links('formatted_sent_data', class_name);
}
else if (hm_list_parent() === 'junk') {
Hm_Message_List.prev_next_links('formatted_junk_data', class_name);
}
else if (hm_list_parent() === 'trash') {
Hm_Message_List.prev_next_links('formatted_trash_data', class_name);
}
else if (hm_list_parent() === 'drafts') {
Hm_Message_List.prev_next_links('formatted_drafts_data', class_name);
}
else if (hm_list_parent() === 'tag') {
Hm_Message_List.prev_next_links('formatted_tag_data', class_name);
}
else {
var key = 'imap_'+Hm_Utils.get_url_page_number()+'_'+getListPathParam();
Hm_Message_List.prev_next_links(key, class_name);
}
Hm_Message_List.prev_next_links(msg_uid);
}
if (Hm_Message_List.track_read_messages(class_name)) {
if (hm_list_parent() == 'unread') {
Expand Down Expand Up @@ -894,7 +851,7 @@ 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();
imap_message_view_finished(uid, details);
get_message_content(false, uid, list_path, details, callback, true);
}
};
Expand Down