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