snappymail/dev/Remote/User/Fetch.js

128 lines
2.8 KiB
JavaScript
Raw Normal View History

2022-02-24 06:11:12 +08:00
import { pString, pInt, b64EncodeJSONSafe } from 'Common/Utils';
2016-06-30 08:02:45 +08:00
import {
getFolderHash,
getFolderUidNext,
2022-02-24 06:11:12 +08:00
getFolderFromCacheList
} from 'Common/Cache';
2016-06-30 08:02:45 +08:00
2021-03-10 18:44:48 +08:00
import { SettingsGet } from 'Common/Globals';
2021-01-27 19:02:37 +08:00
import { SUB_QUERY_PREFIX } from 'Common/Links';
2016-06-30 08:02:45 +08:00
import { AppUserStore } from 'Stores/User/App';
import { SettingsUserStore } from 'Stores/User/Settings';
import { FolderUserStore } from 'Stores/User/Folder';
2016-06-30 08:02:45 +08:00
import { AbstractFetchRemote } from 'Remote/AbstractFetch';
class RemoteUserFetch extends AbstractFetchRemote {
2016-06-30 08:02:45 +08:00
/**
* @param {Function} fCallback
* @param {object} params
* @param {boolean=} bSilent = false
*/
messageList(fCallback, params, bSilent = false) {
const
2021-11-30 17:19:43 +08:00
sFolderFullName = pString(params.Folder),
folderHash = getFolderHash(sFolderFullName);
params = Object.assign({
Offset: 0,
Limit: SettingsUserStore.messagesPerPage(),
Search: '',
UidNext: getFolderUidNext(sFolderFullName), // Used to check for new messages
Sort: FolderUserStore.sortMode(),
Hash: folderHash + SettingsGet('AccountHash')
}, params);
2021-11-30 17:19:43 +08:00
params.Folder = sFolderFullName;
if (AppUserStore.threadsAllowed() && SettingsUserStore.useThreads()) {
params.UseThreads = 1;
} else {
params.ThreadUid = 0;
}
let sGetAdd = '';
if (folderHash && (!params.Search || !params.Search.includes('is:'))) {
sGetAdd = 'MessageList/' +
2021-01-27 19:02:37 +08:00
SUB_QUERY_PREFIX +
'/' +
2021-12-07 20:23:38 +08:00
b64EncodeJSONSafe(params);
params = {};
}
this.request('MessageList',
fCallback,
params,
30000,
sGetAdd,
2019-07-05 03:19:24 +08:00
bSilent ? [] : ['MessageList']
);
}
/**
* @param {?Function} fCallback
2021-11-30 17:19:43 +08:00
* @param {string} sFolderFullName
* @param {number} iUid
* @returns {boolean}
*/
2021-11-30 17:19:43 +08:00
message(fCallback, sFolderFullName, iUid) {
sFolderFullName = pString(sFolderFullName);
iUid = pInt(iUid);
2021-11-30 17:19:43 +08:00
if (getFolderFromCacheList(sFolderFullName) && 0 < iUid) {
this.request('Message',
2019-07-05 03:19:24 +08:00
fCallback,
{},
null,
'Message/' +
2021-01-27 19:02:37 +08:00
SUB_QUERY_PREFIX +
2019-07-05 03:19:24 +08:00
'/' +
2021-12-07 20:23:38 +08:00
b64EncodeJSONSafe([
2021-11-30 17:19:43 +08:00
sFolderFullName,
iUid,
AppUserStore.threadsAllowed() && SettingsUserStore.useThreads() ? 1 : 0,
SettingsGet('AccountHash')
]),
2019-07-05 03:19:24 +08:00
['Message']
);
return true;
}
return false;
}
/**
* @param {?Function} fCallback
* @param {Object} oData
*/
saveSettings(fCallback, oData) {
this.request('SettingsUpdate', fCallback, oData);
}
/**
* @param {string} key
2021-03-18 23:12:24 +08:00
* @param {?scalar} value
* @param {?Function} fCallback
*/
2021-03-18 23:12:24 +08:00
saveSetting(key, value, fCallback) {
this.saveSettings(fCallback, {
[key]: value
});
}
/*
folderMove(sPrevFolderFullName, sNewFolderFullName, bSubscribe) {
return this.post('FolderMove', FolderUserStore.foldersRenaming, {
2021-11-30 17:19:43 +08:00
Folder: sPrevFolderFullName,
NewFolder: sNewFolderFullName,
Subscribe: bSubscribe ? 1 : 0
});
}
*/
}
2016-06-30 08:02:45 +08:00
export default new RemoteUserFetch();