mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-08 17:07:03 +03:00
Cleanup message attachments collections
This commit is contained in:
parent
eb669715ca
commit
94bfe09f63
6 changed files with 28 additions and 34 deletions
|
|
@ -249,10 +249,10 @@ export const FileInfo = {
|
|||
* @param {string} sFileType
|
||||
* @returns {string}
|
||||
*/
|
||||
getCombinedIconClass: data => {
|
||||
getAttachmentsIconClass: data => {
|
||||
if (arrayLength(data)) {
|
||||
let icons = data
|
||||
.map(item => item ? FileInfo.getIconClass(FileInfo.getExtension(item[0]), item[1]) : '')
|
||||
.map(item => item ? FileInfo.getIconClass(FileInfo.getExtension(item.fileName), item.mimeType) : '')
|
||||
.validUnique();
|
||||
|
||||
return (icons && 1 === icons.length && 'icon-file' !== icons[0])
|
||||
|
|
|
|||
|
|
@ -11,6 +11,13 @@ export class AttachmentCollectionModel extends AbstractCollectionModel
|
|||
*/
|
||||
static reviveFromJson(items) {
|
||||
return super.reviveFromJson(items, attachment => AttachmentModel.reviveFromJson(attachment));
|
||||
/*
|
||||
const attachments = super.reviveFromJson(items, attachment => AttachmentModel.reviveFromJson(attachment));
|
||||
if (attachments) {
|
||||
attachments.InlineCount = attachments.reduce((accumulator, a) => accumulator + (a.isInline ? 1 : 0), 0);
|
||||
}
|
||||
return attachments;
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -77,13 +77,12 @@ export class MessageModel extends AbstractModel {
|
|||
});
|
||||
|
||||
this.attachments = ko.observableArray(new AttachmentCollectionModel);
|
||||
this.attachmentsSpecData = ko.observableArray();
|
||||
this.threads = ko.observableArray();
|
||||
this.unsubsribeLinks = ko.observableArray();
|
||||
this.flags = ko.observableArray();
|
||||
|
||||
this.addComputables({
|
||||
attachmentIconClass: () => FileInfo.getCombinedIconClass(this.hasAttachments() ? this.attachmentsSpecData() : []),
|
||||
attachmentIconClass: () => FileInfo.getAttachmentsIconClass(this.attachments()),
|
||||
threadsLen: () => this.threads().length,
|
||||
isImportant: () => MessagePriority.High === this.priority(),
|
||||
|
||||
|
|
@ -137,7 +136,6 @@ export class MessageModel extends AbstractModel {
|
|||
this.selected(false);
|
||||
this.checked(false);
|
||||
this.hasAttachments(false);
|
||||
this.attachmentsSpecData([]);
|
||||
|
||||
this.isHtml(false);
|
||||
this.hasImages(false);
|
||||
|
|
@ -190,6 +188,7 @@ export class MessageModel extends AbstractModel {
|
|||
json.Priority = MessagePriority.Normal;
|
||||
}
|
||||
if (super.revivePropertiesFromJson(json)) {
|
||||
this.hasAttachments(!!this.attachments.length);
|
||||
// this.foundCIDs = isArray(json.FoundCIDs) ? json.FoundCIDs : [];
|
||||
// this.attachments(AttachmentCollectionModel.reviveFromJson(json.Attachments, this.foundCIDs));
|
||||
|
||||
|
|
@ -441,7 +440,7 @@ export class MessageModel extends AbstractModel {
|
|||
this.selected(message.selected());
|
||||
this.checked(message.checked());
|
||||
this.hasAttachments(message.hasAttachments());
|
||||
this.attachmentsSpecData(message.attachmentsSpecData());
|
||||
this.attachments(message.attachments());
|
||||
}
|
||||
|
||||
this.body = null;
|
||||
|
|
|
|||
|
|
@ -23,32 +23,20 @@ class AttachmentCollection extends \MailSo\Base\Collection
|
|||
parent::append($oAttachment, $bToTop);
|
||||
}
|
||||
|
||||
public function InlineCount() : int
|
||||
{
|
||||
$iCount = 0;
|
||||
foreach ($this as $oAttachment) {
|
||||
if ($oAttachment && $oAttachment->IsInline()) {
|
||||
++$iCount;
|
||||
}
|
||||
}
|
||||
return $iCount;
|
||||
}
|
||||
|
||||
public function SpecData() : array
|
||||
{
|
||||
$aResult = array();
|
||||
foreach ($this as $oAttachment) {
|
||||
$aResult[] = $oAttachment
|
||||
? array($oAttachment->FileName(true), $oAttachment->MimeType())
|
||||
: null;
|
||||
$aResult[] = array(
|
||||
'@Object' => 'Object/Attachment',
|
||||
'FileName' => $oAttachment->FileName(true),
|
||||
'MimeType' => $oAttachment->MimeType(),
|
||||
'IsInline' => $oAttachment->IsInline()
|
||||
);
|
||||
}
|
||||
return $aResult;
|
||||
}
|
||||
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), array(
|
||||
'InlineCount' => $this->InlineCount()
|
||||
));
|
||||
return array(
|
||||
'@Object' => 'Collection/AttachmentCollection',
|
||||
'@Collection' => $aResult
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -654,8 +654,7 @@ class Message implements \JsonSerializable
|
|||
'UnsubsribeLinks' => $this->aUnsubsribeLinks,
|
||||
'ReadReceipt' => '',
|
||||
|
||||
'HasAttachments' => $this->oAttachments && 0 < $this->oAttachments->count(),
|
||||
'AttachmentsSpecData' => $this->oAttachments ? $this->oAttachments->SpecData() : array(),
|
||||
'Attachments' => $this->oAttachments ? $this->oAttachments->SpecData() : null,
|
||||
|
||||
'Flags' => $this->aFlagsLowerCase
|
||||
);
|
||||
|
|
|
|||
|
|
@ -202,13 +202,12 @@ trait Response
|
|||
|
||||
if ('Message' === $sParent)
|
||||
{
|
||||
$oAttachments = /* @var \MailSo\Mail\AttachmentCollection */ $mResponse->Attachments();
|
||||
|
||||
$bHasExternals = false;
|
||||
$mFoundCIDs = array();
|
||||
$aContentLocationUrls = array();
|
||||
$mFoundContentLocationUrls = array();
|
||||
|
||||
$oAttachments = /* @var \MailSo\Mail\AttachmentCollection */ $mResponse->Attachments();
|
||||
if ($oAttachments && 0 < $oAttachments->count())
|
||||
{
|
||||
foreach ($oAttachments as /* @var \MailSo\Mail\Attachment */ $oAttachment)
|
||||
|
|
@ -218,7 +217,7 @@ trait Response
|
|||
$sContentLocation = $oAttachment->ContentLocation();
|
||||
if ($sContentLocation && \strlen($sContentLocation))
|
||||
{
|
||||
$aContentLocationUrls[] = $oAttachment->ContentLocation();
|
||||
$aContentLocationUrls[] = $sContentLocation;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -273,12 +272,14 @@ trait Response
|
|||
$mResult['HasExternals'] = $bHasExternals;
|
||||
$mResult['HasInternals'] = (\is_array($mFoundCIDs) && \count($mFoundCIDs)) ||
|
||||
(\is_array($mFoundContentLocationUrls) && \count($mFoundContentLocationUrls));
|
||||
$mResult['Attachments'] = $this->responseObject($oAttachments, $sParent, $aParameters);
|
||||
/*
|
||||
// $mResult['FoundCIDs'] = $mFoundCIDs;
|
||||
$mResult['Attachments'] = $this->responseObject($oAttachments, $sParent, \array_merge($aParameters, array(
|
||||
'FoundCIDs' => $mFoundCIDs,
|
||||
'FoundContentLocationUrls' => $mFoundContentLocationUrls
|
||||
)));
|
||||
|
||||
*/
|
||||
$mResult['ReadReceipt'] = $mResponse->ReadReceipt();
|
||||
|
||||
if (\strlen($mResult['ReadReceipt']) && !\in_array('$forwarded', $mResult['Flags']))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue