Skip to content

Commit

Permalink
fix(Felamimail/js): reload email account after credential changed
Browse files Browse the repository at this point in the history
  • Loading branch information
ccheng-dev committed Jun 4, 2024
1 parent 51f5491 commit ab5b01b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 33 deletions.
52 changes: 25 additions & 27 deletions tine20/Felamimail/js/Felamimail.js
Original file line number Diff line number Diff line change
Expand Up @@ -905,45 +905,43 @@ Tine.Felamimail.Application = Ext.extend(Tine.Tinebase.Application, {
* show felamimail credentials dialog
*
* @param {Tine.Felamimail.Model.Account} account
* @param {String} username [optional]
* @param username
*/
showCredentialsDialog: function(account, username) {
const accountId = account.id;
Tine.Felamimail.credentialsDialog = Tine.widgets.dialog.CredentialsDialog.openWindow({
windowTitle: String.format(this.i18n._('IMAP Credentials for {0}'), account.get('name')),
appName: 'Felamimail',
credentialsId: account.id,
credentialsId: accountId,
i18nRecordName: this.i18n._('Credentials'),
recordClass: Tine.Tinebase.Model.Credentials,
record: new Tine.Tinebase.Model.Credentials({
id: account.id,
username: username ? username : ''
id: accountId,
username: username ?? ''
}),
listeners: {
scope: this,
'update': function(data) {
var folderStore = this.getFolderStore();
if (folderStore.queriesPending.length > 0) {
// reload all folders of account and try to select inbox
var accountId = folderStore.queriesPending[0].substring(16, 56),
account = this.getAccountStore().getById(accountId),
accountNode = this.getMainScreen().getTreePanel().getNodeById(accountId);

folderStore.resetQueryAndRemoveRecords('parent_path', '/' + accountId);
account.set('all_folders_fetched', true);
account.commit();

accountNode.loading = false;
accountNode.reload(function(callback) {
Ext.each(accountNode.childNodes, function(node) {
if (Ext.util.Format.lowercase(node.attributes.localname) == 'inbox') {
node.select();
return false;
}
}, this);
});
} else {
this.checkMailsDelayedTask.delay(0);
}
// reload all folders of account and try to select inbox
const account = this.getAccountStore().getById(accountId);
const accountNode = this.getMainScreen().getTreePanel().getNodeById(accountId);

const folderStore = this.getFolderStore();
folderStore.queriesDone.remove(folderStore.getKey('parent_path', '/' + accountId));
folderStore.resetQueryAndRemoveRecords('parent_path', '/' + accountId);
account.set('all_folders_fetched', true);
account.commit();

accountNode.loading = false;
accountNode.reload(function(callback) {
Ext.each(accountNode.childNodes, function(node) {
if (Ext.util.Format.lowercase(node.attributes.localname) === 'inbox') {
node.select();
return false;
}
}, this);
});
this.checkMailsDelayedTask.delay(0);
}
}
});
Expand Down
17 changes: 11 additions & 6 deletions tine20/Felamimail/js/TreePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,19 @@ Ext.extend(Tine.Felamimail.TreePanel, Ext.tree.TreePanel, {
*/
initAccounts: function() {
this.accountStore = this.app.getAccountStore();
this.accountStore.each(this.addAccount, this);
this.accountStore.each(this.addAccountNode, this);

this.accountStore.on('load', function(store, records) {
this.root.removeAll();
_.map(records, _.bind(this.addAccount, this));
_.map(records, _.bind(this.addAccountNode, this));
this.selectLastSelectedNode();
}, this);
this.accountStore.on('add', function(store, records) {_.map(records, _.bind(this.addAccount, this)); }, this);
this.accountStore.on('add', function(store, records) {
_.map(records, (record) => {
const node = this.addAccountNode(record);
node.expand();
});
}, this);
this.accountStore.on('update', this.onAccountUpdate, this);
this.accountStore.on('remove', this.deleteAccount, this);
},
Expand Down Expand Up @@ -960,9 +965,8 @@ Ext.extend(Tine.Felamimail.TreePanel, Ext.tree.TreePanel, {
*
* @param {Tine.Felamimail.Model.Account} record
*/
addAccount: function(record) {

var node = new Ext.tree.AsyncTreeNode({
addAccountNode: function(record) {
const node = new Ext.tree.AsyncTreeNode({
id: record.data.id,
path: '/' + record.data.id,
record: record,
Expand Down Expand Up @@ -994,6 +998,7 @@ Ext.extend(Tine.Felamimail.TreePanel, Ext.tree.TreePanel, {
_.defer(() => {
this.app.getMainScreen().getCenterPanel().action_write.setDisabled(! this.app.getActiveAccount());
});
return node;
},

deleteAccount: function(store, account) {
Expand Down

0 comments on commit ab5b01b

Please sign in to comment.