Skip to content

Commit

Permalink
Add control of the state of previous fetch call in mail for Usermin
Browse files Browse the repository at this point in the history
  • Loading branch information
iliajie committed Jul 28, 2020
1 parent 74c08b6 commit 629437a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion extensions/mail/mail.min.js

Large diffs are not rendered by default.

Binary file modified extensions/mail/mail.min.js.gz
Binary file not shown.
29 changes: 27 additions & 2 deletions extensions/mail/mail.src.js
Original file line number Diff line number Diff line change
Expand Up @@ -2197,6 +2197,26 @@ const mail = (function() {
*/
const messages = (function() {

/**
* Control the state of previous fetch call
*/
const fetching = {
state: false,
initial: true,
abort: function() {
if (this.pending() === true &&
this.initial === false) {
this.state.abort();
}
},
pending: function() {
if (typeof this.state.state === "function" && this.state.state() === "pending") {
return true;
}
return false;
},
};

/**
* Fetches and renders list of messages for the given folder with particular pagination
*
Expand All @@ -2205,14 +2225,17 @@ const mail = (function() {
const get = (data) => {
loader.start();
// _.notification('hide-all');
$.post(_.path.extensions + '/mail/messages.cgi?' + _.plugin.json_to_query(data),
fetching.abort();
fetching.state = $.post(_.path.extensions + '/mail/messages.cgi?' + _.plugin.json_to_query(data),
function(data) {
render(data);
loader.end();
_.document_title(0, _.lang('titles_mail'));

// Set received config data
config.set(data[0].config);

fetching.initial = false;
});
},

Expand Down Expand Up @@ -2862,6 +2885,7 @@ const mail = (function() {
storage.reset();
}
if (refetch || data.folder_counts_allowed) {
fetching.abort();
$.post(_.path.extensions + '/mail/messages.cgi?' + hidden + 'show_body_len=' + preview_length() + '', function(data) {
render(data);
loader.end();
Expand Down Expand Up @@ -2912,6 +2936,7 @@ const mail = (function() {

// If redirect requested, follow it
if (data.redirect) {
fetching.abort();
_.pjax.fetch(data.redirect);
}
return
Expand Down Expand Up @@ -3192,7 +3217,7 @@ const mail = (function() {
// Update messages, if conditions are met
this.refreshTimer = setInterval(() => {
let refreshing = () => {
panel.find($$.element('controls.refresh.button')).trigger('click');
!fetching.pending() && panel.find($$.element('controls.refresh.button')).trigger('click');
}
if (config.d.u) {
clearInterval(this.refreshTimer);
Expand Down

0 comments on commit 629437a

Please sign in to comment.