mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-06-29 01:36:44 +03:00
Attachments array to new AttachmentCollectionModel
This commit is contained in:
parent
344edaec2a
commit
e99a69a9aa
5 changed files with 70 additions and 105 deletions
49
dev/Model/AttachmentCollection.js
Normal file
49
dev/Model/AttachmentCollection.js
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import { AttachmentModel } from 'Model/Attachment';
|
||||
|
||||
'use strict';
|
||||
|
||||
class AttachmentCollectionModel extends Array
|
||||
{
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {?Array} json
|
||||
* @returns {AttachmentCollectionModel}
|
||||
*/
|
||||
static reviveFromJson(items, foundedCIDs) {
|
||||
let result = new AttachmentCollectionModel;
|
||||
if (items && 'Collection/AttachmentCollection' === items['@Object']) {
|
||||
items = items['@Collection'];
|
||||
}
|
||||
Array.isArray(items) && items.forEach(attachment => {
|
||||
attachment = AttachmentModel.newInstanceFromJson(attachment);
|
||||
if (attachment) {
|
||||
if (attachment.cidWithOutTags && foundedCIDs.includes(attachment.cidWithOutTags)) {
|
||||
attachment.isLinked = true;
|
||||
}
|
||||
result.push(attachment);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {boolean}
|
||||
*/
|
||||
hasVisible() {
|
||||
return !!this.find(item => !item.isLinked);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} cid
|
||||
* @returns {*}
|
||||
*/
|
||||
findByCid(cid) {
|
||||
cid = cid.replace(/^<+|>+$/, '');
|
||||
return this.find(item => cid === item.cidWithOutTags);
|
||||
}
|
||||
}
|
||||
|
||||
export { AttachmentCollectionModel, AttachmentCollectionModel as default };
|
||||
Loading…
Add table
Add a link
Reference in a new issue