mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Fetch response 'Collection/MessageCollection' to new MessageCollectionModel
This commit is contained in:
parent
8f07cf4ac6
commit
086a2c1927
4 changed files with 163 additions and 139 deletions
|
|
@ -16,7 +16,7 @@ import Remote from 'Remote/User/Fetch';
|
||||||
|
|
||||||
const Settings = rl.settings,
|
const Settings = rl.settings,
|
||||||
|
|
||||||
normalizeFolder = sFolderFullNameRaw => (!sFolderFullNameRaw
|
normalizeFolder = sFolderFullNameRaw => ('' === sFolderFullNameRaw
|
||||||
|| UNUSED_OPTION_VALUE === sFolderFullNameRaw
|
|| UNUSED_OPTION_VALUE === sFolderFullNameRaw
|
||||||
|| null !== Cache.getFolderFromCacheList(sFolderFullNameRaw))
|
|| null !== Cache.getFolderFromCacheList(sFolderFullNameRaw))
|
||||||
? sFolderFullNameRaw
|
? sFolderFullNameRaw
|
||||||
|
|
@ -28,35 +28,28 @@ class FolderCollectionModel extends Array
|
||||||
super();
|
super();
|
||||||
/*
|
/*
|
||||||
this.CountRec
|
this.CountRec
|
||||||
this.Namespace;
|
this.FoldersHash
|
||||||
this.IsThreadsSupported
|
this.IsThreadsSupported
|
||||||
|
this.Namespace;
|
||||||
this.Optimized
|
this.Optimized
|
||||||
this.SystemFolders
|
this.SystemFolders
|
||||||
this.FoldersHash
|
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {?Array} json
|
* @param {?Object} json
|
||||||
* @returns {FolderCollectionModel}
|
* @returns {FolderCollectionModel}
|
||||||
*/
|
*/
|
||||||
static reviveFromJson(items) {
|
static reviveFromJson(collection) {
|
||||||
if (!items || 'Collection/FolderCollection' !== items['@Object'] || !Array.isArray(items['@Collection'])) {
|
if (collection && 'Collection/FolderCollection' === collection['@Object']
|
||||||
return;
|
&& Array.isArray(collection['@Collection'])) {
|
||||||
}
|
|
||||||
|
|
||||||
const result = new FolderCollectionModel,
|
const result = new FolderCollectionModel,
|
||||||
expandedFolders = Local.get(ClientSideKeyName.ExpandedFolders),
|
expandedFolders = Local.get(ClientSideKeyName.ExpandedFolders),
|
||||||
bDisplaySpecSetting = FolderStore.displaySpecSetting();
|
bDisplaySpecSetting = FolderStore.displaySpecSetting();
|
||||||
|
|
||||||
result.CountRec = items.CountRec;
|
Object.entries(collection).forEach(([key, value]) => '@' !== key[0] && (result[key] = value));
|
||||||
result.Namespace = items.Namespace;
|
|
||||||
result.IsThreadsSupported = items.IsThreadsSupported;
|
|
||||||
result.Optimized = !!items.Optimized;
|
|
||||||
result.SystemFolders = items.SystemFolders;
|
|
||||||
result.FoldersHash = items.FoldersHash;
|
|
||||||
|
|
||||||
items['@Collection'].forEach(oFolder => {
|
collection['@Collection'].forEach(oFolder => {
|
||||||
if (oFolder) {
|
if (oFolder) {
|
||||||
let oCacheFolder = Cache.getFolderFromCacheList(oFolder.FullNameRaw);
|
let oCacheFolder = Cache.getFolderFromCacheList(oFolder.FullNameRaw);
|
||||||
if (!oCacheFolder) {
|
if (!oCacheFolder) {
|
||||||
|
|
@ -92,10 +85,8 @@ class FolderCollectionModel extends Array
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oFolder.SubFolders) {
|
|
||||||
oFolder.SubFolders = FolderCollectionModel.reviveFromJson(oFolder.SubFolders);
|
oFolder.SubFolders = FolderCollectionModel.reviveFromJson(oFolder.SubFolders);
|
||||||
oCacheFolder.subFolders(oFolder.SubFolders);
|
oFolder.SubFolders && oCacheFolder.subFolders(oFolder.SubFolders);
|
||||||
}
|
|
||||||
|
|
||||||
result.push(oCacheFolder);
|
result.push(oCacheFolder);
|
||||||
}
|
}
|
||||||
|
|
@ -104,6 +95,7 @@ class FolderCollectionModel extends Array
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
storeIt() {
|
storeIt() {
|
||||||
const cnt = pInt(this.CountRec);
|
const cnt = pInt(this.CountRec);
|
||||||
|
|
@ -121,7 +113,7 @@ class FolderCollectionModel extends Array
|
||||||
|
|
||||||
AppStore.threadsAllowed(!!(Settings.app('useImapThread') && this.IsThreadsSupported));
|
AppStore.threadsAllowed(!!(Settings.app('useImapThread') && this.IsThreadsSupported));
|
||||||
|
|
||||||
FolderStore.folderList.optimized(this.Optimized);
|
FolderStore.folderList.optimized(!!this.Optimized);
|
||||||
|
|
||||||
let update = false;
|
let update = false;
|
||||||
|
|
||||||
|
|
|
||||||
69
dev/Model/MessageCollection.js
Normal file
69
dev/Model/MessageCollection.js
Normal file
|
|
@ -0,0 +1,69 @@
|
||||||
|
import { MessageModel } from 'Model/Message';
|
||||||
|
|
||||||
|
import {
|
||||||
|
initMessageFlagsFromCache,
|
||||||
|
storeMessageFlagsToCache,
|
||||||
|
hasNewMessageAndRemoveFromCache
|
||||||
|
} from 'Common/Cache';
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
class MessageCollectionModel extends Array
|
||||||
|
{
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
/*
|
||||||
|
this.Filtered
|
||||||
|
this.Folder
|
||||||
|
this.FolderHash
|
||||||
|
this.Limit
|
||||||
|
this.MessageCount
|
||||||
|
this.MessageUnseenCount
|
||||||
|
this.MessageResultCount
|
||||||
|
this.NewMessages
|
||||||
|
this.Offset
|
||||||
|
this.Search
|
||||||
|
this.ThreadUid
|
||||||
|
this.UidNext
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {?Object} json
|
||||||
|
* @returns {MessageCollectionModel}
|
||||||
|
*/
|
||||||
|
static reviveFromJson(collection, cached) {
|
||||||
|
if (collection
|
||||||
|
&& 'Collection/MessageCollection' === collection['@Object']
|
||||||
|
&& Array.isArray(collection['@Collection'])) {
|
||||||
|
const result = new MessageCollectionModel;
|
||||||
|
|
||||||
|
Object.entries(collection).forEach(([key, value]) => '@' !== key[0] && (result[key] = value));
|
||||||
|
|
||||||
|
let newCount = 0;
|
||||||
|
collection['@Collection'].forEach(message => {
|
||||||
|
if (message && 'Object/Message' === message['@Object']) {
|
||||||
|
message = MessageModel.newInstanceFromJson(message);
|
||||||
|
if (message) {
|
||||||
|
if (hasNewMessageAndRemoveFromCache(message.folderFullNameRaw, message.uid) && 5 >= newCount) {
|
||||||
|
++newCount;
|
||||||
|
message.newForAnimation(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
message.deleted(false);
|
||||||
|
|
||||||
|
cached ? initMessageFlagsFromCache(message) : storeMessageFlagsToCache(message);
|
||||||
|
|
||||||
|
result.push(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// collection[@Count] == result.length
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { MessageCollectionModel, MessageCollectionModel as default };
|
||||||
|
|
@ -308,13 +308,10 @@ class RemoteUserFetch extends AbstractFetchRemote {
|
||||||
useThreads = AppStore.threadsAllowed() && SettingsStore.useThreads(),
|
useThreads = AppStore.threadsAllowed() && SettingsStore.useThreads(),
|
||||||
inboxUidNext = getFolderInboxName() === sFolderFullNameRaw ? getFolderUidNext(sFolderFullNameRaw) : '';
|
inboxUidNext = getFolderInboxName() === sFolderFullNameRaw ? getFolderUidNext(sFolderFullNameRaw) : '';
|
||||||
|
|
||||||
|
let params = {}, sGetAdd = '';
|
||||||
|
|
||||||
if (folderHash && (!sSearch || !sSearch.includes('is:'))) {
|
if (folderHash && (!sSearch || !sSearch.includes('is:'))) {
|
||||||
return this.defaultRequest(
|
sGetAdd = 'MessageList/' +
|
||||||
fCallback,
|
|
||||||
'MessageList',
|
|
||||||
{},
|
|
||||||
sSearch ? SEARCH_AJAX_TIMEOUT : DEFAULT_AJAX_TIMEOUT,
|
|
||||||
'MessageList/' +
|
|
||||||
subQueryPrefix() +
|
subQueryPrefix() +
|
||||||
'/' +
|
'/' +
|
||||||
urlsafeArray([
|
urlsafeArray([
|
||||||
|
|
@ -327,15 +324,9 @@ class RemoteUserFetch extends AbstractFetchRemote {
|
||||||
inboxUidNext,
|
inboxUidNext,
|
||||||
useThreads ? 1 : 0,
|
useThreads ? 1 : 0,
|
||||||
useThreads ? sThreadUid : ''
|
useThreads ? sThreadUid : ''
|
||||||
]),
|
]);
|
||||||
bSilent ? [] : ['MessageList']
|
} else {
|
||||||
);
|
params = {
|
||||||
}
|
|
||||||
|
|
||||||
return this.defaultRequest(
|
|
||||||
fCallback,
|
|
||||||
'MessageList',
|
|
||||||
{
|
|
||||||
Folder: sFolderFullNameRaw,
|
Folder: sFolderFullNameRaw,
|
||||||
Offset: iOffset,
|
Offset: iOffset,
|
||||||
Limit: iLimit,
|
Limit: iLimit,
|
||||||
|
|
@ -343,9 +334,15 @@ class RemoteUserFetch extends AbstractFetchRemote {
|
||||||
UidNext: inboxUidNext,
|
UidNext: inboxUidNext,
|
||||||
UseThreads: useThreads ? 1 : 0,
|
UseThreads: useThreads ? 1 : 0,
|
||||||
ThreadUid: useThreads ? sThreadUid : ''
|
ThreadUid: useThreads ? sThreadUid : ''
|
||||||
},
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.defaultRequest(
|
||||||
|
fCallback,
|
||||||
|
'MessageList',
|
||||||
|
params,
|
||||||
sSearch ? SEARCH_AJAX_TIMEOUT : DEFAULT_AJAX_TIMEOUT,
|
sSearch ? SEARCH_AJAX_TIMEOUT : DEFAULT_AJAX_TIMEOUT,
|
||||||
'',
|
sGetAdd,
|
||||||
bSilent ? [] : ['MessageList']
|
bSilent ? [] : ['MessageList']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,6 @@ import {
|
||||||
initMessageFlagsFromCache,
|
initMessageFlagsFromCache,
|
||||||
addRequestedMessage,
|
addRequestedMessage,
|
||||||
clearMessageFlagsFromCacheByFolder,
|
clearMessageFlagsFromCacheByFolder,
|
||||||
hasNewMessageAndRemoveFromCache,
|
|
||||||
storeMessageFlagsToCache,
|
|
||||||
clearNewMessageCache
|
clearNewMessageCache
|
||||||
} from 'Common/Cache';
|
} from 'Common/Cache';
|
||||||
|
|
||||||
|
|
@ -29,6 +27,7 @@ import { i18n, getNotification } from 'Common/Translator';
|
||||||
|
|
||||||
import { EmailCollectionModel } from 'Model/EmailCollection';
|
import { EmailCollectionModel } from 'Model/EmailCollection';
|
||||||
import { MessageModel } from 'Model/Message';
|
import { MessageModel } from 'Model/Message';
|
||||||
|
import { MessageCollectionModel } from 'Model/MessageCollection';
|
||||||
|
|
||||||
import { setHash } from 'Knoin/Knoin';
|
import { setHash } from 'Knoin/Knoin';
|
||||||
|
|
||||||
|
|
@ -681,87 +680,54 @@ class MessageUserStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
setMessageList(data, cached) {
|
setMessageList(data, cached) {
|
||||||
if (
|
const collection = data && MessageCollectionModel.reviveFromJson(data.Result, cached);
|
||||||
data &&
|
if (collection) {
|
||||||
data.Result &&
|
let unreadCountChange = false;
|
||||||
'Collection/MessageCollection' === data.Result['@Object'] &&
|
|
||||||
data.Result['@Collection'] &&
|
|
||||||
Array.isArray(data.Result['@Collection'])
|
|
||||||
) {
|
|
||||||
let newCount = 0,
|
|
||||||
unreadCountChange = false;
|
|
||||||
|
|
||||||
const list = [],
|
const iCount = collection.MessageResultCount,
|
||||||
iCount = pInt(data.Result.MessageResultCount),
|
iOffset = collection.Offset,
|
||||||
iOffset = pInt(data.Result.Offset);
|
folder = getFolderFromCacheList(collection.Folder);
|
||||||
|
|
||||||
const folder = getFolderFromCacheList(data.Result.Folder);
|
|
||||||
|
|
||||||
if (folder && !cached) {
|
if (folder && !cached) {
|
||||||
folder.interval = Date.now() / 1000;
|
folder.interval = Date.now() / 1000;
|
||||||
|
|
||||||
setFolderHash(data.Result.Folder, data.Result.FolderHash);
|
setFolderHash(collection.Folder, collection.FolderHash);
|
||||||
|
|
||||||
if (null != data.Result.MessageCount) {
|
if (null != collection.MessageCount) {
|
||||||
folder.messageCountAll(data.Result.MessageCount);
|
folder.messageCountAll(collection.MessageCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null != data.Result.MessageUnseenCount) {
|
if (null != collection.MessageUnseenCount) {
|
||||||
if (pInt(folder.messageCountUnread()) !== pInt(data.Result.MessageUnseenCount)) {
|
if (pInt(folder.messageCountUnread()) !== pInt(collection.MessageUnseenCount)) {
|
||||||
unreadCountChange = true;
|
unreadCountChange = true;
|
||||||
}
|
|
||||||
|
|
||||||
folder.messageCountUnread(data.Result.MessageUnseenCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.initUidNextAndNewMessages(folder.fullNameRaw, data.Result.UidNext, data.Result.NewMessages);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unreadCountChange && folder) {
|
|
||||||
clearMessageFlagsFromCacheByFolder(folder.fullNameRaw);
|
clearMessageFlagsFromCacheByFolder(folder.fullNameRaw);
|
||||||
}
|
}
|
||||||
|
|
||||||
data.Result['@Collection'].forEach(jsonMessage => {
|
folder.messageCountUnread(collection.MessageUnseenCount);
|
||||||
if (jsonMessage && 'Object/Message' === jsonMessage['@Object']) {
|
|
||||||
const message = MessageModel.newInstanceFromJson(jsonMessage);
|
|
||||||
if (message) {
|
|
||||||
if (hasNewMessageAndRemoveFromCache(message.folderFullNameRaw, message.uid) && 5 >= newCount) {
|
|
||||||
newCount += 1;
|
|
||||||
message.newForAnimation(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
message.deleted(false);
|
this.initUidNextAndNewMessages(folder.fullNameRaw, collection.UidNext, collection.NewMessages);
|
||||||
|
|
||||||
if (cached) {
|
|
||||||
initMessageFlagsFromCache(message);
|
|
||||||
} else {
|
|
||||||
storeMessageFlagsToCache(message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
list.push(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.messageListCount(iCount);
|
this.messageListCount(iCount);
|
||||||
this.messageListSearch(null != data.Result.Search ? data.Result.Search : '');
|
this.messageListSearch(pString(collection.Search));
|
||||||
this.messageListPage(Math.ceil(iOffset / SettingsStore.messagesPerPage() + 1));
|
this.messageListPage(Math.ceil(iOffset / SettingsStore.messagesPerPage() + 1));
|
||||||
this.messageListThreadUid(null != data.Result.ThreadUid ? pString(data.Result.ThreadUid) : '');
|
this.messageListThreadUid(pString(data.Result.ThreadUid));
|
||||||
|
|
||||||
this.messageListEndFolder(null != data.Result.Folder ? data.Result.Folder : '');
|
this.messageListEndFolder(collection.Folder);
|
||||||
this.messageListEndSearch(this.messageListSearch());
|
this.messageListEndSearch(this.messageListSearch());
|
||||||
this.messageListEndThreadUid(this.messageListThreadUid());
|
this.messageListEndThreadUid(this.messageListThreadUid());
|
||||||
this.messageListEndPage(this.messageListPage());
|
this.messageListEndPage(this.messageListPage());
|
||||||
|
|
||||||
this.messageListDisableAutoSelect(true);
|
this.messageListDisableAutoSelect(true);
|
||||||
|
|
||||||
this.messageList(list);
|
this.messageList(collection);
|
||||||
this.messageListIsNotCompleted(false);
|
this.messageListIsNotCompleted(false);
|
||||||
|
|
||||||
clearNewMessageCache();
|
clearNewMessageCache();
|
||||||
|
|
||||||
if (folder && (cached || unreadCountChange || SettingsStore.useThreads())) {
|
if (folder && (cached || unreadCountChange || SettingsStore.useThreads())) {
|
||||||
rl.app.folderInformation(folder.fullNameRaw, list);
|
rl.app.folderInformation(folder.fullNameRaw, collection);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.messageListCount(0);
|
this.messageListCount(0);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue