mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Let all the new CollectionModels use AbstractCollectionModel
This commit is contained in:
parent
086a2c1927
commit
71f6fb25e5
5 changed files with 39 additions and 44 deletions
15
dev/Model/AbstractCollection.js
Normal file
15
dev/Model/AbstractCollection.js
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
|
||||||
|
export class AbstractCollectionModel extends Array
|
||||||
|
{
|
||||||
|
constructor(props) {
|
||||||
|
super();
|
||||||
|
props && Object.entries(props).forEach(([key, value]) => '@' !== key[0] && (this[key] = value));
|
||||||
|
// props[@Count]
|
||||||
|
}
|
||||||
|
|
||||||
|
static getFromJSON(object, name) {
|
||||||
|
return object && 'Collection/'+name === object['@Object'] && Array.isArray(object['@Collection'])
|
||||||
|
? object['@Collection']
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,22 +1,17 @@
|
||||||
|
import { AbstractCollectionModel } from 'Model/AbstractCollection';
|
||||||
import { AttachmentModel } from 'Model/Attachment';
|
import { AttachmentModel } from 'Model/Attachment';
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
class AttachmentCollectionModel extends Array
|
export class AttachmentCollectionModel extends AbstractCollectionModel
|
||||||
{
|
{
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {?Array} json
|
* @param {?Array} json
|
||||||
* @returns {AttachmentCollectionModel}
|
* @returns {AttachmentCollectionModel}
|
||||||
*/
|
*/
|
||||||
static reviveFromJson(items, foundedCIDs) {
|
static reviveFromJson(items, foundedCIDs) {
|
||||||
let result = new AttachmentCollectionModel;
|
let result = new AttachmentCollectionModel;
|
||||||
if (items && 'Collection/AttachmentCollection' === items['@Object']) {
|
items = this.getFromJSON(items, 'AttachmentCollection') || items;
|
||||||
items = items['@Collection'];
|
|
||||||
}
|
|
||||||
Array.isArray(items) && items.forEach(attachment => {
|
Array.isArray(items) && items.forEach(attachment => {
|
||||||
attachment = AttachmentModel.newInstanceFromJson(attachment);
|
attachment = AttachmentModel.newInstanceFromJson(attachment);
|
||||||
if (attachment) {
|
if (attachment) {
|
||||||
|
|
@ -45,5 +40,3 @@ class AttachmentCollectionModel extends Array
|
||||||
return this.find(item => cid === item.cidWithOutTags);
|
return this.find(item => cid === item.cidWithOutTags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { AttachmentCollectionModel, AttachmentCollectionModel as default };
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,10 @@
|
||||||
|
import { AbstractCollectionModel } from 'Model/AbstractCollection';
|
||||||
import { EmailModel } from 'Model/Email';
|
import { EmailModel } from 'Model/Email';
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
class EmailCollectionModel extends Array
|
export class EmailCollectionModel extends AbstractCollectionModel
|
||||||
{
|
{
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {?Array} json
|
* @param {?Array} json
|
||||||
* @returns {EmailCollectionModel}
|
* @returns {EmailCollectionModel}
|
||||||
|
|
@ -45,5 +42,3 @@ class EmailCollectionModel extends Array
|
||||||
return result.join(', ');
|
return result.join(', ');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { EmailCollectionModel, EmailCollectionModel as default };
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { AbstractCollectionModel } from 'Model/AbstractCollection';
|
||||||
|
|
||||||
import { UNUSED_OPTION_VALUE } from 'Common/Consts';
|
import { UNUSED_OPTION_VALUE } from 'Common/Consts';
|
||||||
import { pInt } from 'Common/Utils';
|
import { pInt } from 'Common/Utils';
|
||||||
import { ClientSideKeyName, ServerFolderType } from 'Common/Enums';
|
import { ClientSideKeyName, ServerFolderType } from 'Common/Enums';
|
||||||
|
|
@ -22,34 +24,32 @@ normalizeFolder = sFolderFullNameRaw => ('' === sFolderFullNameRaw
|
||||||
? sFolderFullNameRaw
|
? sFolderFullNameRaw
|
||||||
: '';
|
: '';
|
||||||
|
|
||||||
class FolderCollectionModel extends Array
|
export class FolderCollectionModel extends AbstractCollectionModel
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
/*
|
|
||||||
this.CountRec
|
this.CountRec
|
||||||
this.FoldersHash
|
this.FoldersHash
|
||||||
this.IsThreadsSupported
|
this.IsThreadsSupported
|
||||||
this.Namespace;
|
this.Namespace;
|
||||||
this.Optimized
|
this.Optimized
|
||||||
this.SystemFolders
|
this.SystemFolders
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {?Object} json
|
* @param {?Object} json
|
||||||
* @returns {FolderCollectionModel}
|
* @returns {FolderCollectionModel}
|
||||||
*/
|
*/
|
||||||
static reviveFromJson(collection) {
|
static reviveFromJson(object) {
|
||||||
if (collection && 'Collection/FolderCollection' === collection['@Object']
|
const collection = this.getFromJSON(object, 'FolderCollection');
|
||||||
&& Array.isArray(collection['@Collection'])) {
|
if (collection) {
|
||||||
const result = new FolderCollectionModel,
|
const result = new FolderCollectionModel(object),
|
||||||
expandedFolders = Local.get(ClientSideKeyName.ExpandedFolders),
|
expandedFolders = Local.get(ClientSideKeyName.ExpandedFolders),
|
||||||
bDisplaySpecSetting = FolderStore.displaySpecSetting();
|
bDisplaySpecSetting = FolderStore.displaySpecSetting();
|
||||||
|
|
||||||
Object.entries(collection).forEach(([key, value]) => '@' !== key[0] && (result[key] = value));
|
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) {
|
||||||
|
|
@ -157,5 +157,3 @@ class FolderCollectionModel extends Array
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export { FolderCollectionModel, FolderCollectionModel as default };
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { AbstractCollectionModel } from 'Model/AbstractCollection';
|
||||||
import { MessageModel } from 'Model/Message';
|
import { MessageModel } from 'Model/Message';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
|
@ -8,11 +9,11 @@ import {
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
class MessageCollectionModel extends Array
|
export class MessageCollectionModel extends AbstractCollectionModel
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
/*
|
|
||||||
this.Filtered
|
this.Filtered
|
||||||
this.Folder
|
this.Folder
|
||||||
this.FolderHash
|
this.FolderHash
|
||||||
|
|
@ -25,23 +26,20 @@ class MessageCollectionModel extends Array
|
||||||
this.Search
|
this.Search
|
||||||
this.ThreadUid
|
this.ThreadUid
|
||||||
this.UidNext
|
this.UidNext
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {?Object} json
|
* @param {?Object} json
|
||||||
* @returns {MessageCollectionModel}
|
* @returns {MessageCollectionModel}
|
||||||
*/
|
*/
|
||||||
static reviveFromJson(collection, cached) {
|
static reviveFromJson(object, cached) {
|
||||||
if (collection
|
const collection = this.getFromJSON(object, 'MessageCollection');
|
||||||
&& 'Collection/MessageCollection' === collection['@Object']
|
if (collection) {
|
||||||
&& Array.isArray(collection['@Collection'])) {
|
const result = new MessageCollectionModel(object);
|
||||||
const result = new MessageCollectionModel;
|
|
||||||
|
|
||||||
Object.entries(collection).forEach(([key, value]) => '@' !== key[0] && (result[key] = value));
|
|
||||||
|
|
||||||
let newCount = 0;
|
let newCount = 0;
|
||||||
collection['@Collection'].forEach(message => {
|
collection.forEach(message => {
|
||||||
if (message && 'Object/Message' === message['@Object']) {
|
if (message && 'Object/Message' === message['@Object']) {
|
||||||
message = MessageModel.newInstanceFromJson(message);
|
message = MessageModel.newInstanceFromJson(message);
|
||||||
if (message) {
|
if (message) {
|
||||||
|
|
@ -59,11 +57,7 @@ class MessageCollectionModel extends Array
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// collection[@Count] == result.length
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { MessageCollectionModel, MessageCollectionModel as default };
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue