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';
|
||||
|
||||
'use strict';
|
||||
|
||||
class AttachmentCollectionModel extends Array
|
||||
export class AttachmentCollectionModel extends AbstractCollectionModel
|
||||
{
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {?Array} json
|
||||
* @returns {AttachmentCollectionModel}
|
||||
*/
|
||||
static reviveFromJson(items, foundedCIDs) {
|
||||
let result = new AttachmentCollectionModel;
|
||||
if (items && 'Collection/AttachmentCollection' === items['@Object']) {
|
||||
items = items['@Collection'];
|
||||
}
|
||||
items = this.getFromJSON(items, 'AttachmentCollection') || items;
|
||||
Array.isArray(items) && items.forEach(attachment => {
|
||||
attachment = AttachmentModel.newInstanceFromJson(attachment);
|
||||
if (attachment) {
|
||||
|
|
@ -45,5 +40,3 @@ class AttachmentCollectionModel extends Array
|
|||
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';
|
||||
|
||||
'use strict';
|
||||
|
||||
class EmailCollectionModel extends Array
|
||||
export class EmailCollectionModel extends AbstractCollectionModel
|
||||
{
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {?Array} json
|
||||
* @returns {EmailCollectionModel}
|
||||
|
|
@ -45,5 +42,3 @@ class EmailCollectionModel extends Array
|
|||
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 { pInt } from 'Common/Utils';
|
||||
import { ClientSideKeyName, ServerFolderType } from 'Common/Enums';
|
||||
|
|
@ -22,34 +24,32 @@ normalizeFolder = sFolderFullNameRaw => ('' === sFolderFullNameRaw
|
|||
? sFolderFullNameRaw
|
||||
: '';
|
||||
|
||||
class FolderCollectionModel extends Array
|
||||
export class FolderCollectionModel extends AbstractCollectionModel
|
||||
{
|
||||
/*
|
||||
constructor() {
|
||||
super();
|
||||
/*
|
||||
this.CountRec
|
||||
this.FoldersHash
|
||||
this.IsThreadsSupported
|
||||
this.Namespace;
|
||||
this.Optimized
|
||||
this.SystemFolders
|
||||
*/
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {?Object} json
|
||||
* @returns {FolderCollectionModel}
|
||||
*/
|
||||
static reviveFromJson(collection) {
|
||||
if (collection && 'Collection/FolderCollection' === collection['@Object']
|
||||
&& Array.isArray(collection['@Collection'])) {
|
||||
const result = new FolderCollectionModel,
|
||||
static reviveFromJson(object) {
|
||||
const collection = this.getFromJSON(object, 'FolderCollection');
|
||||
if (collection) {
|
||||
const result = new FolderCollectionModel(object),
|
||||
expandedFolders = Local.get(ClientSideKeyName.ExpandedFolders),
|
||||
bDisplaySpecSetting = FolderStore.displaySpecSetting();
|
||||
|
||||
Object.entries(collection).forEach(([key, value]) => '@' !== key[0] && (result[key] = value));
|
||||
|
||||
collection['@Collection'].forEach(oFolder => {
|
||||
collection.forEach(oFolder => {
|
||||
if (oFolder) {
|
||||
let oCacheFolder = Cache.getFolderFromCacheList(oFolder.FullNameRaw);
|
||||
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 {
|
||||
|
|
@ -8,11 +9,11 @@ import {
|
|||
|
||||
'use strict';
|
||||
|
||||
class MessageCollectionModel extends Array
|
||||
export class MessageCollectionModel extends AbstractCollectionModel
|
||||
{
|
||||
/*
|
||||
constructor() {
|
||||
super();
|
||||
/*
|
||||
this.Filtered
|
||||
this.Folder
|
||||
this.FolderHash
|
||||
|
|
@ -25,23 +26,20 @@ class MessageCollectionModel extends Array
|
|||
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));
|
||||
static reviveFromJson(object, cached) {
|
||||
const collection = this.getFromJSON(object, 'MessageCollection');
|
||||
if (collection) {
|
||||
const result = new MessageCollectionModel(object);
|
||||
|
||||
let newCount = 0;
|
||||
collection['@Collection'].forEach(message => {
|
||||
collection.forEach(message => {
|
||||
if (message && 'Object/Message' === message['@Object']) {
|
||||
message = MessageModel.newInstanceFromJson(message);
|
||||
if (message) {
|
||||
|
|
@ -59,11 +57,7 @@ class MessageCollectionModel extends Array
|
|||
}
|
||||
});
|
||||
|
||||
// collection[@Count] == result.length
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { MessageCollectionModel, MessageCollectionModel as default };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue