change AbstractFetchRemote with a better structure

This commit is contained in:
djmaze 2021-12-02 23:15:24 +01:00
parent 0d809dd574
commit 792fee547a
26 changed files with 265 additions and 723 deletions

View file

@ -43,8 +43,7 @@ class AccountPopupView extends AbstractViewPopup {
this.submitRequest(true);
Remote.accountSetup(
(iError, data) => {
Remote.request('AccountSetup', (iError, data) => {
this.submitRequest(false);
if (iError) {
this.submitError(getNotification(iError));
@ -53,10 +52,11 @@ class AccountPopupView extends AbstractViewPopup {
rl.app.accountsAndIdentities();
this.cancelCommand();
}
},
this.email(),
this.password(),
this.isNew()
}, {
Email: this.email(),
Password: this.password(),
New: this.isNew() ? 1 : 0
}
);
return true;

View file

@ -415,7 +415,7 @@ class ComposePopupView extends AbstractViewPopup {
setFolderHash(this.draftsFolder(), '');
setFolderHash(sSentFolder, '');
Remote.sendMessage(
Remote.request('SendMessage',
(iError, data) => {
this.sending(false);
if (this.modalVisibility()) {
@ -434,7 +434,8 @@ class ComposePopupView extends AbstractViewPopup {
}
this.reloadDraftFolder();
},
this.getMessageRequestParams(sSentFolder)
this.getMessageRequestParams(sSentFolder),
30000
);
}
}
@ -451,7 +452,7 @@ class ComposePopupView extends AbstractViewPopup {
setFolderHash(FolderUserStore.draftsFolder(), '');
Remote.saveMessage(
Remote.request('SaveMessage',
(iError, oData) => {
let result = false;
@ -486,7 +487,8 @@ class ComposePopupView extends AbstractViewPopup {
this.reloadDraftFolder();
},
this.getMessageRequestParams(FolderUserStore.draftsFolder())
this.getMessageRequestParams(FolderUserStore.draftsFolder()),
200000
);
}
@ -1016,30 +1018,36 @@ class ComposePopupView extends AbstractViewPopup {
const downloads = this.getAttachmentsDownloadsForUpload();
if (arrayLength(downloads)) {
Remote.messageUploadAttachments((iError, oData) => {
if (!iError) {
forEachObjectEntry(oData.Result, (tempName, id) => {
const attachment = this.getAttachmentById(id);
if (attachment) {
attachment.tempName(tempName);
attachment
.waiting(false)
.uploading(false)
.complete(true);
}
});
} else {
this.attachments.forEach(attachment => {
if (attachment && attachment.fromMessage) {
attachment
.waiting(false)
.uploading(false)
.complete(true)
.error(getUploadErrorDescByCode(UploadErrorCode.NoFileUploaded));
}
});
}
}, downloads);
Remote.request('MessageUploadAttachments',
(iError, oData) => {
if (!iError) {
forEachObjectEntry(oData.Result, (tempName, id) => {
const attachment = this.getAttachmentById(id);
if (attachment) {
attachment.tempName(tempName);
attachment
.waiting(false)
.uploading(false)
.complete(true);
}
});
} else {
this.attachments.forEach(attachment => {
if (attachment && attachment.fromMessage) {
attachment
.waiting(false)
.uploading(false)
.complete(true)
.error(getUploadErrorDescByCode(UploadErrorCode.NoFileUploaded));
}
});
}
},
{
Attachments: downloads
},
999000
);
}
if (identity) {

View file

@ -217,7 +217,7 @@ class ContactsPopupView extends AbstractViewPopup {
const requestUid = Jua.randomId();
Remote.contactSave(
Remote.request('ContactSave',
(iError, oData) => {
let res = false;
this.viewSaving(false);
@ -243,10 +243,11 @@ class ContactsPopupView extends AbstractViewPopup {
this.watchDirty(false);
setTimeout(() => this.viewSaveTrigger(SaveSettingsStep.Idle), 1000);
}
},
requestUid,
this.viewID(),
this.viewProperties.map(oItem => oItem.toJSON())
}, {
RequestUid: requestUid,
Uid: this.viewID(),
Properties: this.viewProperties.map(oItem => oItem.toJSON())
}
);
}
@ -355,14 +356,17 @@ class ContactsPopupView extends AbstractViewPopup {
deleteSelectedContacts() {
if (this.contactsCheckedOrSelected().length) {
Remote.contactsDelete((iError, oData) => {
if (500 < (!iError && oData && oData.Time ? pInt(oData.Time) : 0)) {
this.reloadContactList(this.bDropPageAfterDelete);
} else {
setTimeout(() => this.reloadContactList(this.bDropPageAfterDelete), 500);
Remote.request('ContactsDelete',
(iError, oData) => {
if (500 < (!iError && oData && oData.Time ? pInt(oData.Time) : 0)) {
this.reloadContactList(this.bDropPageAfterDelete);
} else {
setTimeout(() => this.reloadContactList(this.bDropPageAfterDelete), 500);
}
}, {
Uids: this.contactsCheckedOrSelectedUids().join(',')
}
}, this.contactsCheckedOrSelectedUids());
);
this.removeCheckedOrSelectedContactsFromList();
}
}
@ -415,7 +419,7 @@ class ContactsPopupView extends AbstractViewPopup {
}
ContactUserStore.loading(true);
Remote.contacts(
Remote.request('Contacts',
(iError, data) => {
let count = 0,
list = [];
@ -438,9 +442,14 @@ class ContactsPopupView extends AbstractViewPopup {
ContactUserStore.loading(false);
this.viewClearSearch(!!this.search());
},
offset,
CONTACTS_PER_PAGE,
this.search()
{
Offset: offset,
Limit: CONTACTS_PER_PAGE,
Search: this.search()
},
null,
'',
['Contacts']
);
}

View file

@ -54,7 +54,7 @@ class FolderClearPopupView extends AbstractViewPopup {
setFolderHash(folderToClear.fullName, '');
Remote.folderClear(iError => {
Remote.request('FolderClear', iError => {
this.clearingProcess(false);
if (iError) {
this.clearingError(getNotification(iError));
@ -62,7 +62,9 @@ class FolderClearPopupView extends AbstractViewPopup {
rl.app.reloadMessageList(true);
this.cancelCommand();
}
}, folderToClear.fullName);
}, {
Folder: folderToClear.fullName
});
}
}

View file

@ -50,7 +50,10 @@ class FolderCreatePopupView extends AbstractViewPopup {
}
rl.app.foldersPromisesActionHelper(
Remote.folderCreate(this.folderName(), parentFolderName),
Remote.post('FolderCreate', FolderUserStore.foldersCreating, {
Folder: this.folderName(),
Parent: parentFolderName
}),
Notification.CantCreateFolder
);

View file

@ -94,8 +94,7 @@ class IdentityPopupView extends AbstractViewPopup {
this.submitRequest(true);
Remote.identityUpdate(
iError => {
Remote.request('IdentityUpdate', iError => {
this.submitRequest(false);
if (iError) {
this.submitError(getNotification(iError));
@ -103,14 +102,15 @@ class IdentityPopupView extends AbstractViewPopup {
rl.app.accountsAndIdentities();
this.cancelCommand();
}
},
this.id,
this.email(),
this.name(),
this.replyTo(),
this.bcc(),
this.signature(),
this.signatureInsertBefore()
}, {
Id: this.id,
Email: this.email(),
Name: this.name(),
ReplyTo: this.replyTo(),
Bcc: this.bcc(),
Signature: this.signature(),
SignatureInsertBefore: this.signatureInsertBefore() ? 1 : 0
}
);
return true;

View file

@ -57,7 +57,7 @@ class SieveScriptPopupView extends AbstractViewPopup {
script.body(script.filtersToRaw());
}
Remote.filtersScriptSave(
Remote.request('FiltersScriptSave',
(iError, data) => {
self.saving = false;
@ -70,7 +70,7 @@ class SieveScriptPopupView extends AbstractViewPopup {
script.hasChanges(false);
}
},
script
script.toJson()
);
}

View file

@ -99,7 +99,7 @@ class LoginUserView extends AbstractViewLogin {
this.submitRequest(true);
data.set('Language', this.bSendLanguage ? this.language() : '');
data.set('SignMe', this.signMe() ? 1 : 0);
Remote.defaultRequest(
Remote.request('Login',
(iError, oData) => {
if (iError) {
this.submitRequest(false);
@ -114,7 +114,7 @@ class LoginUserView extends AbstractViewLogin {
// rl.route.reload();
}
},
'Login', data
data
);
Local.set(ClientSideKeyName.LastSignMe, this.signMe() ? '-1-' : '-0-');

View file

@ -467,55 +467,50 @@ export class MailMessageList extends AbstractViewRight {
if (folder) {
switch (iSetAction) {
case MessageSetAction.SetSeen:
folder = getFolderFromCacheList(sFolderFullName);
if (folder) {
MessageUserStore.list.forEach(message => {
if (message.isUnseen()) {
++cnt;
}
message.isUnseen(false);
uids.push(message.uid);
});
if (iThreadUid) {
folder.messageCountUnread(folder.messageCountUnread() - cnt);
if (0 > folder.messageCountUnread()) {
folder.messageCountUnread(0);
}
} else {
folder.messageCountUnread(0);
MessageUserStore.list.forEach(message => {
if (message.isUnseen()) {
++cnt;
}
MessageFlagsCache.clearFolder(sFolderFullName);
message.isUnseen(false);
uids.push(message.uid);
});
if (iThreadUid) {
folder.messageCountUnread(folder.messageCountUnread() - cnt);
if (0 > folder.messageCountUnread()) {
folder.messageCountUnread(0);
}
} else {
folder.messageCountUnread(0);
}
MessageFlagsCache.clearFolder(sFolderFullName);
Remote.messageSetSeenToAll(null, sFolderFullName, true, iThreadUid ? uids : null);
break;
case MessageSetAction.UnsetSeen:
folder = getFolderFromCacheList(sFolderFullName);
if (folder) {
MessageUserStore.list.forEach(message => {
if (!message.isUnseen()) {
++cnt;
}
message.isUnseen(true);
uids.push(message.uid);
});
if (iThreadUid) {
folder.messageCountUnread(folder.messageCountUnread() + cnt);
if (folder.messageCountAll() < folder.messageCountUnread()) {
folder.messageCountUnread(folder.messageCountAll());
}
} else {
folder.messageCountUnread(folder.messageCountAll());
MessageUserStore.list.forEach(message => {
if (!message.isUnseen()) {
++cnt;
}
MessageFlagsCache.clearFolder(sFolderFullName);
message.isUnseen(true);
uids.push(message.uid);
});
if (iThreadUid) {
folder.messageCountUnread(folder.messageCountUnread() + cnt);
if (folder.messageCountAll() < folder.messageCountUnread()) {
folder.messageCountUnread(folder.messageCountAll());
}
} else {
folder.messageCountUnread(folder.messageCountAll());
}
MessageFlagsCache.clearFolder(sFolderFullName);
Remote.messageSetSeenToAll(null, sFolderFullName, false, iThreadUid ? uids : null);
break;
// no default

View file

@ -598,14 +598,13 @@ export class MailMessageView extends AbstractViewRight {
readReceipt() {
let oMessage = MessageUserStore.message()
if (oMessage && oMessage.readReceipt()) {
Remote.sendReadReceiptMessage(
null,
oMessage.folder,
oMessage.uid,
oMessage.readReceipt(),
i18n('READ_RECEIPT/SUBJECT', { SUBJECT: oMessage.subject() }),
i18n('READ_RECEIPT/BODY', { 'READ-RECEIPT': AccountUserStore.email() })
);
Remote.request('SendReadReceiptMessage', null, {
MessageFolder: oMessage.folder,
MessageUid: oMessage.uid,
ReadReceipt: oMessage.readReceipt(),
Subject: i18n('READ_RECEIPT/SUBJECT', { SUBJECT: oMessage.subject() }),
Text: i18n('READ_RECEIPT/BODY', { 'READ-RECEIPT': AccountUserStore.email() })
});
oMessage.isReadReceipt(true);

View file

@ -56,7 +56,7 @@ export class SystemDropDownUserView extends AbstractViewRight {
AccountUserStore.loading(true);
event.preventDefault();
event.stopPropagation();
Remote.defaultRequest(
Remote.request('AccountSwitch',
(iError/*, oData*/) => {
if (iError) {
AccountUserStore.loading(false);
@ -86,7 +86,7 @@ export class SystemDropDownUserView extends AbstractViewRight {
// rl.route.reload();
location.reload();
}
}, 'AccountSwitch', {Email:account.email}
}, {Email:account.email}
);
}
return true;