mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
foldersReload promises populator to the new FolderCollectionModel
This commit is contained in:
parent
d33f9710c2
commit
8f07cf4ac6
5 changed files with 182 additions and 192 deletions
169
dev/Model/FolderCollection.js
Normal file
169
dev/Model/FolderCollection.js
Normal file
|
|
@ -0,0 +1,169 @@
|
||||||
|
import { UNUSED_OPTION_VALUE } from 'Common/Consts';
|
||||||
|
import { pInt } from 'Common/Utils';
|
||||||
|
import { ClientSideKeyName, ServerFolderType } from 'Common/Enums';
|
||||||
|
import * as Cache from 'Common/Cache';
|
||||||
|
|
||||||
|
import * as Local from 'Storage/Client';
|
||||||
|
|
||||||
|
import AppStore from 'Stores/User/App';
|
||||||
|
import FolderStore from 'Stores/User/Folder';
|
||||||
|
|
||||||
|
import { FolderModel } from 'Model/Folder';
|
||||||
|
|
||||||
|
import Remote from 'Remote/User/Fetch';
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const Settings = rl.settings,
|
||||||
|
|
||||||
|
normalizeFolder = sFolderFullNameRaw => (!sFolderFullNameRaw
|
||||||
|
|| UNUSED_OPTION_VALUE === sFolderFullNameRaw
|
||||||
|
|| null !== Cache.getFolderFromCacheList(sFolderFullNameRaw))
|
||||||
|
? sFolderFullNameRaw
|
||||||
|
: '';
|
||||||
|
|
||||||
|
class FolderCollectionModel extends Array
|
||||||
|
{
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
/*
|
||||||
|
this.CountRec
|
||||||
|
this.Namespace;
|
||||||
|
this.IsThreadsSupported
|
||||||
|
this.Optimized
|
||||||
|
this.SystemFolders
|
||||||
|
this.FoldersHash
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {?Array} json
|
||||||
|
* @returns {FolderCollectionModel}
|
||||||
|
*/
|
||||||
|
static reviveFromJson(items) {
|
||||||
|
if (!items || 'Collection/FolderCollection' !== items['@Object'] || !Array.isArray(items['@Collection'])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = new FolderCollectionModel,
|
||||||
|
expandedFolders = Local.get(ClientSideKeyName.ExpandedFolders),
|
||||||
|
bDisplaySpecSetting = FolderStore.displaySpecSetting();
|
||||||
|
|
||||||
|
result.CountRec = items.CountRec;
|
||||||
|
result.Namespace = items.Namespace;
|
||||||
|
result.IsThreadsSupported = items.IsThreadsSupported;
|
||||||
|
result.Optimized = !!items.Optimized;
|
||||||
|
result.SystemFolders = items.SystemFolders;
|
||||||
|
result.FoldersHash = items.FoldersHash;
|
||||||
|
|
||||||
|
items['@Collection'].forEach(oFolder => {
|
||||||
|
if (oFolder) {
|
||||||
|
let oCacheFolder = Cache.getFolderFromCacheList(oFolder.FullNameRaw);
|
||||||
|
if (!oCacheFolder) {
|
||||||
|
oCacheFolder = FolderModel.newInstanceFromJson(oFolder);
|
||||||
|
if (oCacheFolder) {
|
||||||
|
Cache.setFolderToCacheList(oFolder.FullNameRaw, oCacheFolder);
|
||||||
|
Cache.setFolderFullNameRaw(oCacheFolder.fullNameHash, oFolder.FullNameRaw, oCacheFolder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oCacheFolder) {
|
||||||
|
if (bDisplaySpecSetting) {
|
||||||
|
oCacheFolder.checkable(!!oFolder.Checkable);
|
||||||
|
} else {
|
||||||
|
oCacheFolder.checkable(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
oCacheFolder.collapsed(!expandedFolders
|
||||||
|
|| !Array.isArray(expandedFolders)
|
||||||
|
|| !expandedFolders.includes(oCacheFolder.fullNameHash));
|
||||||
|
|
||||||
|
if (oFolder.Extended) {
|
||||||
|
if (oFolder.Extended.Hash) {
|
||||||
|
Cache.setFolderHash(oCacheFolder.fullNameRaw, oFolder.Extended.Hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null != oFolder.Extended.MessageCount) {
|
||||||
|
oCacheFolder.messageCountAll(oFolder.Extended.MessageCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null != oFolder.Extended.MessageUnseenCount) {
|
||||||
|
oCacheFolder.messageCountUnread(oFolder.Extended.MessageUnseenCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oFolder.SubFolders) {
|
||||||
|
oFolder.SubFolders = FolderCollectionModel.reviveFromJson(oFolder.SubFolders);
|
||||||
|
oCacheFolder.subFolders(oFolder.SubFolders);
|
||||||
|
}
|
||||||
|
|
||||||
|
result.push(oCacheFolder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
storeIt() {
|
||||||
|
const cnt = pInt(this.CountRec);
|
||||||
|
|
||||||
|
let limit = pInt(Settings.app('folderSpecLimit'));
|
||||||
|
limit = 100 < limit ? 100 : 10 > limit ? 10 : limit;
|
||||||
|
|
||||||
|
FolderStore.displaySpecSetting(0 >= cnt || limit < cnt);
|
||||||
|
|
||||||
|
FolderStore.folderList(this);
|
||||||
|
|
||||||
|
if (undefined !== this.Namespace) {
|
||||||
|
FolderStore.namespace = this.Namespace;
|
||||||
|
}
|
||||||
|
|
||||||
|
AppStore.threadsAllowed(!!(Settings.app('useImapThread') && this.IsThreadsSupported));
|
||||||
|
|
||||||
|
FolderStore.folderList.optimized(this.Optimized);
|
||||||
|
|
||||||
|
let update = false;
|
||||||
|
|
||||||
|
if (
|
||||||
|
this.SystemFolders &&
|
||||||
|
!('' +
|
||||||
|
Settings.get('SentFolder') +
|
||||||
|
Settings.get('DraftFolder') +
|
||||||
|
Settings.get('SpamFolder') +
|
||||||
|
Settings.get('TrashFolder') +
|
||||||
|
Settings.get('ArchiveFolder') +
|
||||||
|
Settings.get('NullFolder'))
|
||||||
|
) {
|
||||||
|
Settings.set('SentFolder', this.SystemFolders[ServerFolderType.SENT] || null);
|
||||||
|
Settings.set('DraftFolder', this.SystemFolders[ServerFolderType.DRAFTS] || null);
|
||||||
|
Settings.set('SpamFolder', this.SystemFolders[ServerFolderType.JUNK] || null);
|
||||||
|
Settings.set('TrashFolder', this.SystemFolders[ServerFolderType.TRASH] || null);
|
||||||
|
Settings.set('ArchiveFolder', this.SystemFolders[ServerFolderType.ALL] || null);
|
||||||
|
|
||||||
|
update = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
FolderStore.sentFolder(normalizeFolder(Settings.get('SentFolder')));
|
||||||
|
FolderStore.draftFolder(normalizeFolder(Settings.get('DraftFolder')));
|
||||||
|
FolderStore.spamFolder(normalizeFolder(Settings.get('SpamFolder')));
|
||||||
|
FolderStore.trashFolder(normalizeFolder(Settings.get('TrashFolder')));
|
||||||
|
FolderStore.archiveFolder(normalizeFolder(Settings.get('ArchiveFolder')));
|
||||||
|
|
||||||
|
if (update) {
|
||||||
|
Remote.saveSystemFolders(()=>{}, {
|
||||||
|
SentFolder: FolderStore.sentFolder(),
|
||||||
|
DraftFolder: FolderStore.draftFolder(),
|
||||||
|
SpamFolder: FolderStore.spamFolder(),
|
||||||
|
TrashFolder: FolderStore.trashFolder(),
|
||||||
|
ArchiveFolder: FolderStore.archiveFolder(),
|
||||||
|
NullFolder: 'NullFolder'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Local.set(ClientSideKeyName.FoldersLashHash, this.FoldersHash);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export { FolderCollectionModel, FolderCollectionModel as default };
|
||||||
|
|
@ -1,187 +0,0 @@
|
||||||
import { UNUSED_OPTION_VALUE } from 'Common/Consts';
|
|
||||||
import { pInt } from 'Common/Utils';
|
|
||||||
import { ClientSideKeyName, ServerFolderType } from 'Common/Enums';
|
|
||||||
import * as Cache from 'Common/Cache';
|
|
||||||
|
|
||||||
import * as Local from 'Storage/Client';
|
|
||||||
|
|
||||||
import AppStore from 'Stores/User/App';
|
|
||||||
import FolderStore from 'Stores/User/Folder';
|
|
||||||
|
|
||||||
import Remote from 'Remote/User/Fetch';
|
|
||||||
|
|
||||||
import { FolderModel } from 'Model/Folder';
|
|
||||||
|
|
||||||
const Settings = rl.settings;
|
|
||||||
|
|
||||||
class PromisesUserPopulator {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {string} sFullNameHash
|
|
||||||
* @param {Array?} expandedFolders
|
|
||||||
* @returns {boolean}
|
|
||||||
*/
|
|
||||||
isFolderExpanded(sFullNameHash, expandedFolders) {
|
|
||||||
return expandedFolders && Array.isArray(expandedFolders) && expandedFolders.includes(sFullNameHash);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {string} sFolderFullNameRaw
|
|
||||||
* @returns {string}
|
|
||||||
*/
|
|
||||||
normalizeFolder(sFolderFullNameRaw) {
|
|
||||||
return !sFolderFullNameRaw ||
|
|
||||||
UNUSED_OPTION_VALUE === sFolderFullNameRaw ||
|
|
||||||
null !== Cache.getFolderFromCacheList(sFolderFullNameRaw)
|
|
||||||
? sFolderFullNameRaw
|
|
||||||
: '';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {string} sNamespace
|
|
||||||
* @param {Array} aFolders
|
|
||||||
* @param {Array?} expandedFolders
|
|
||||||
* @returns {Array}
|
|
||||||
*/
|
|
||||||
folderResponseParseRec(sNamespace, aFolders, expandedFolders) {
|
|
||||||
const bDisplaySpecSetting = FolderStore.displaySpecSetting(),
|
|
||||||
aList = [];
|
|
||||||
|
|
||||||
aFolders.forEach(oFolder => {
|
|
||||||
if (oFolder) {
|
|
||||||
let oCacheFolder = Cache.getFolderFromCacheList(oFolder.FullNameRaw);
|
|
||||||
if (!oCacheFolder) {
|
|
||||||
oCacheFolder = FolderModel.newInstanceFromJson(oFolder);
|
|
||||||
if (oCacheFolder) {
|
|
||||||
Cache.setFolderToCacheList(oFolder.FullNameRaw, oCacheFolder);
|
|
||||||
Cache.setFolderFullNameRaw(oCacheFolder.fullNameHash, oFolder.FullNameRaw, oCacheFolder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (oCacheFolder) {
|
|
||||||
if (bDisplaySpecSetting) {
|
|
||||||
oCacheFolder.checkable(!!oFolder.Checkable);
|
|
||||||
} else {
|
|
||||||
oCacheFolder.checkable(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
oCacheFolder.collapsed(!this.isFolderExpanded(oCacheFolder.fullNameHash, expandedFolders));
|
|
||||||
|
|
||||||
if (oFolder.Extended) {
|
|
||||||
if (oFolder.Extended.Hash) {
|
|
||||||
Cache.setFolderHash(oCacheFolder.fullNameRaw, oFolder.Extended.Hash);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null != oFolder.Extended.MessageCount) {
|
|
||||||
oCacheFolder.messageCountAll(oFolder.Extended.MessageCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null != oFolder.Extended.MessageUnseenCount) {
|
|
||||||
oCacheFolder.messageCountUnread(oFolder.Extended.MessageUnseenCount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
oFolder.SubFolders &&
|
|
||||||
'Collection/FolderCollection' === oFolder.SubFolders['@Object'] &&
|
|
||||||
oFolder.SubFolders['@Collection'] &&
|
|
||||||
Array.isArray(oFolder.SubFolders['@Collection'])
|
|
||||||
) {
|
|
||||||
oCacheFolder.subFolders(
|
|
||||||
this.folderResponseParseRec(sNamespace, oFolder.SubFolders['@Collection'], expandedFolders)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
aList.push(oCacheFolder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return aList;
|
|
||||||
}
|
|
||||||
|
|
||||||
foldersList(oData) {
|
|
||||||
if (
|
|
||||||
oData &&
|
|
||||||
'Collection/FolderCollection' === oData['@Object'] &&
|
|
||||||
oData['@Collection'] &&
|
|
||||||
Array.isArray(oData['@Collection'])
|
|
||||||
) {
|
|
||||||
const expandedFolders = Local.get(ClientSideKeyName.ExpandedFolders),
|
|
||||||
cnt = pInt(oData.CountRec);
|
|
||||||
|
|
||||||
let limit = pInt(Settings.app('folderSpecLimit'));
|
|
||||||
limit = 100 < limit ? 100 : 10 > limit ? 10 : limit;
|
|
||||||
|
|
||||||
FolderStore.displaySpecSetting(0 >= cnt || limit < cnt);
|
|
||||||
|
|
||||||
FolderStore.folderList(
|
|
||||||
this.folderResponseParseRec(
|
|
||||||
undefined === oData.Namespace ? '' : oData.Namespace,
|
|
||||||
oData['@Collection'],
|
|
||||||
expandedFolders
|
|
||||||
)
|
|
||||||
); // @todo optimization required
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foldersAdditionalParameters(oData) {
|
|
||||||
if (
|
|
||||||
oData &&
|
|
||||||
oData &&
|
|
||||||
'Collection/FolderCollection' === oData['@Object'] &&
|
|
||||||
oData['@Collection'] &&
|
|
||||||
Array.isArray(oData['@Collection'])
|
|
||||||
) {
|
|
||||||
if (undefined !== oData.Namespace) {
|
|
||||||
FolderStore.namespace = oData.Namespace;
|
|
||||||
}
|
|
||||||
|
|
||||||
AppStore.threadsAllowed(!!Settings.app('useImapThread') && oData.IsThreadsSupported && true);
|
|
||||||
|
|
||||||
FolderStore.folderList.optimized(!!oData.Optimized);
|
|
||||||
|
|
||||||
let update = false;
|
|
||||||
|
|
||||||
if (
|
|
||||||
oData.SystemFolders &&
|
|
||||||
!('' +
|
|
||||||
Settings.get('SentFolder') +
|
|
||||||
Settings.get('DraftFolder') +
|
|
||||||
Settings.get('SpamFolder') +
|
|
||||||
Settings.get('TrashFolder') +
|
|
||||||
Settings.get('ArchiveFolder') +
|
|
||||||
Settings.get('NullFolder'))
|
|
||||||
) {
|
|
||||||
Settings.set('SentFolder', oData.SystemFolders[ServerFolderType.SENT] || null);
|
|
||||||
Settings.set('DraftFolder', oData.SystemFolders[ServerFolderType.DRAFTS] || null);
|
|
||||||
Settings.set('SpamFolder', oData.SystemFolders[ServerFolderType.JUNK] || null);
|
|
||||||
Settings.set('TrashFolder', oData.SystemFolders[ServerFolderType.TRASH] || null);
|
|
||||||
Settings.set('ArchiveFolder', oData.SystemFolders[ServerFolderType.ALL] || null);
|
|
||||||
|
|
||||||
update = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
FolderStore.sentFolder(this.normalizeFolder(Settings.get('SentFolder')));
|
|
||||||
FolderStore.draftFolder(this.normalizeFolder(Settings.get('DraftFolder')));
|
|
||||||
FolderStore.spamFolder(this.normalizeFolder(Settings.get('SpamFolder')));
|
|
||||||
FolderStore.trashFolder(this.normalizeFolder(Settings.get('TrashFolder')));
|
|
||||||
FolderStore.archiveFolder(this.normalizeFolder(Settings.get('ArchiveFolder')));
|
|
||||||
|
|
||||||
if (update) {
|
|
||||||
Remote.saveSystemFolders(()=>{}, {
|
|
||||||
SentFolder: FolderStore.sentFolder(),
|
|
||||||
DraftFolder: FolderStore.draftFolder(),
|
|
||||||
SpamFolder: FolderStore.spamFolder(),
|
|
||||||
TrashFolder: FolderStore.trashFolder(),
|
|
||||||
ArchiveFolder: FolderStore.archiveFolder(),
|
|
||||||
NullFolder: 'NullFolder'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Local.set(ClientSideKeyName.FoldersLashHash, oData.FoldersHash);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default new PromisesUserPopulator();
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
import { pString, pInt } from 'Common/Utils';
|
import { pString, pInt } from 'Common/Utils';
|
||||||
import PromisesPopulator from 'Promises/User/Populator';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
CONTACTS_SYNC_AJAX_TIMEOUT,
|
CONTACTS_SYNC_AJAX_TIMEOUT,
|
||||||
|
|
@ -24,6 +23,8 @@ import SettingsStore from 'Stores/User/Settings';
|
||||||
|
|
||||||
import { AbstractFetchRemote } from 'Remote/AbstractFetch';
|
import { AbstractFetchRemote } from 'Remote/AbstractFetch';
|
||||||
|
|
||||||
|
import { FolderCollectionModel } from 'Model/FolderCollection';
|
||||||
|
|
||||||
//const toUTF8 = window.TextEncoder
|
//const toUTF8 = window.TextEncoder
|
||||||
// ? text => String.fromCharCode(...new TextEncoder().encode(text))
|
// ? text => String.fromCharCode(...new TextEncoder().encode(text))
|
||||||
// : text => unescape(encodeURIComponent(text)),
|
// : text => unescape(encodeURIComponent(text)),
|
||||||
|
|
@ -773,9 +774,9 @@ class RemoteUserFetch extends AbstractFetchRemote {
|
||||||
foldersReload(fTrigger) {
|
foldersReload(fTrigger) {
|
||||||
return this.abort('Folders')
|
return this.abort('Folders')
|
||||||
.postRequest('Folders', fTrigger)
|
.postRequest('Folders', fTrigger)
|
||||||
.then((data) => {
|
.then(data => {
|
||||||
PromisesPopulator.foldersList(data.Result);
|
data = FolderCollectionModel.reviveFromJson(data.Result);
|
||||||
PromisesPopulator.foldersAdditionalParameters(data.Result);
|
data && data.storeIt();
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -543,6 +543,13 @@ class MessageUserStore {
|
||||||
+ '</div>');
|
+ '</div>');
|
||||||
body.rlCacheCount = iMessageBodyCacheCount;
|
body.rlCacheCount = iMessageBodyCacheCount;
|
||||||
|
|
||||||
|
// Drop Microsoft Office style properties
|
||||||
|
const rgbRE = /rgb\((\d+),\s*(\d+),\s*(\d+)\)/g,
|
||||||
|
hex = n => ('0' + parseInt(n).toString(16)).slice(-2);
|
||||||
|
body.querySelectorAll('[style*=mso]').forEach(el =>
|
||||||
|
el.setAttribute('style', el.style.cssText.replace(rgbRE, (m,r,g,b) => '#' + hex(r) + hex(g) + hex(b)))
|
||||||
|
);
|
||||||
|
|
||||||
message.body = body;
|
message.body = body;
|
||||||
|
|
||||||
message.isHtml(!!isHtml);
|
message.isHtml(!!isHtml);
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
width: 98%;
|
width: 98%;
|
||||||
max-width: 1000px;
|
max-width: 1000px;
|
||||||
margin: 10px auto;
|
margin: 10px auto;
|
||||||
min-height: calc(100% - 44px);
|
min-height: calc(100% - 52px);
|
||||||
|
|
||||||
.modal-body {
|
.modal-body {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue