Skip to content

Commit

Permalink
WIP: Fix combined unread folder content
Browse files Browse the repository at this point in the history
  • Loading branch information
mercihabam committed Oct 5, 2024
1 parent 45537b7 commit 2e03409
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 35 deletions.
2 changes: 1 addition & 1 deletion modules/core/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -1976,7 +1976,7 @@ $(function() {
Hm_Folders.update_folder_list();
}
if (hm_page_name() == 'message_list' || hm_page_name() == 'search') {
Hm_Message_List.select_combined_view();
// Hm_Message_List.select_combined_view();
$('.combined_sort').on("change", function() { Hm_Message_List.sort($(this).val()); });
$('.source_link').on("click", function() { $('.list_sources').toggle(); $('#list_controls_menu').hide(); return false; });
if (hm_list_path() == 'unread' && $('.menu_unread > a').css('font-weight') == 'bold') {
Expand Down
27 changes: 16 additions & 11 deletions modules/imap/handler_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -1397,20 +1397,25 @@ class Hm_Handler_imap_unread extends Hm_Handler_Module {
*/
public function process() {
list($success, $form) = $this->process_form(array('imap_server_ids'));

if ($success) {
$limit = $this->user_config->get('unread_per_source_setting', DEFAULT_UNREAD_PER_SOURCE);
$date = process_since_argument($this->user_config->get('unread_since_setting', DEFAULT_UNREAD_SINCE));
$ids = explode(',', $form['imap_server_ids']);
$msg_list = array();
$folder = bin2hex('INBOX');
if (array_key_exists('folder', $this->request->post)) {
$folder = $this->request->post['folder'];
}
list($status, $msg_list) = merge_imap_search_results($ids, 'UNSEEN', $this->session, $this->cache, array(hex2bin($folder)), $limit, array(array('SINCE', $date)));
$this->out('folder_status', $status);
$this->out('imap_unread_data', $msg_list);
$this->out('imap_server_ids', $form['imap_server_ids']);
} else {
$data_sources = imap_data_sources('');
$ids = array_map(function($ds) { return $ds['id']; }, $data_sources);
}

$limit = $this->user_config->get('unread_per_source_setting', DEFAULT_UNREAD_PER_SOURCE);
$date = process_since_argument($this->user_config->get('unread_since_setting', DEFAULT_UNREAD_SINCE));
$msg_list = array();
$folder = bin2hex('INBOX');
if (array_key_exists('folder', $this->request->post)) {
$folder = $this->request->post['folder'];
}
list($status, $msg_list) = merge_imap_search_results($ids, 'UNSEEN', $this->session, $this->cache, array(hex2bin($folder)), $limit, array(array('SINCE', $date)));
$this->out('folder_status', $status);
$this->out('imap_unread_data', $msg_list);
$this->out('imap_server_ids', implode(',', $ids));
}
}

Expand Down
37 changes: 31 additions & 6 deletions modules/imap/js_modules/Hm_Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,9 @@ class Hm_MessagesStore {
}

#fetch(hideLoadingState = false) {
const detail = Hm_Utils.parse_folder_path(this.path, 'imap');
return new Promise((resolve, reject) => {
Hm_Ajax.request(
[
{ name: "hm_ajax_hook", value: "ajax_imap_folder_display" },
{ name: "imap_server_id", value: detail.server_id },
{ name: "folder", value: detail.folder },
],
this.#getRequestConfig(),
(response) => {
resolve(response);
},
Expand All @@ -131,6 +126,36 @@ class Hm_MessagesStore {
});
}

#getRequestConfig() {
let hook;
let serverId;
let folder;
const config = [];
if (this.path.startsWith('imap')) {
hook = "ajax_imap_folder_display";
const detail = Hm_Utils.parse_folder_path(this.path, 'imap');
serverId = detail.server_id;
folder = detail.folder;
} else {
switch (this.path) {
case 'unread':
hook = "ajax_imap_unread";
break;
}
}

if (hook) {
config.push({ name: "hm_ajax_hook", value: hook });
}
if (serverId) {
config.push({ name: "imap_server_id", value: serverId });
}
if (folder) {
config.push({ name: "folder", value: folder });
}
return config;
}

#saveToLocalStorage() {
Hm_Utils.save_to_local_storage(this.list, JSON.stringify({ rows: this.rows, links: this.links, count: this.count }));
Hm_Utils.save_to_local_storage('flagAsReadOnOpen', this.flagAsReadOnOpen);
Expand Down
40 changes: 23 additions & 17 deletions modules/imap/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,23 +488,29 @@ $('#imap_filter_form').on('submit', async function(event) {

var display_imap_mailbox = function(rows, links) {
const detail = Hm_Utils.parse_folder_path(getListPathParam(), 'imap');
Hm_Message_List.update([detail.server_id], rows, 'imap');
Hm_Message_List.check_empty_list();
$('.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 uid = tr.data('uid');

if (Hm_Utils.get_from_local_storage(getMessageStorageKey(uid))) {
return;
}
preFetchMessageContent(false, uid);
});
const serverIds = [];
if (detail) {
serverIds.push(detail.server_id);
}
if (rows) {
Hm_Message_List.update(serverIds, rows, 'imap');
Hm_Message_List.check_empty_list();
$('.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 uid = tr.data('uid');

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

function preFetchMessageContent(msgPart, uid) {
Expand Down

0 comments on commit 2e03409

Please sign in to comment.