Merge some parts of initByJson and initUpdateByMessageJson

Cleanup messageListChecked handling
This commit is contained in:
djmaze 2020-09-20 11:29:31 +02:00
parent 46198861bc
commit b66e68a3b1
8 changed files with 46 additions and 61 deletions

View file

@ -209,27 +209,36 @@ class MessageModel extends AbstractModel {
);
}
setFromJson(json) {
if (json && 'Object/Message' === json['@Object']) {
let priority = pInt(json.Priority);
this.priority(
[MessagePriority.High, MessagePriority.Low].includes(priority) ? priority : MessagePriority.Normal
);
this.proxy = !!json.ExternalProxy;
this.hasAttachments(!!json.HasAttachments);
this.attachmentsSpecData(isArray(json.AttachmentsSpecData) ? json.AttachmentsSpecData : []);
return true;
}
return false;
}
/**
* @param {AjaxJsonMessage} json
* @returns {boolean}
*/
initByJson(json) {
let result = false,
priority = MessagePriority.Normal;
if (json && 'Object/Message' === json['@Object']) {
priority = pInt(json.Priority);
this.priority(
[MessagePriority.High, MessagePriority.Low].includes(priority) ? priority : MessagePriority.Normal
);
let result = this.setFromJson(json);
if (result) {
this.folderFullNameRaw = json.Folder;
this.uid = json.Uid;
this.hash = json.Hash;
this.requestHash = json.RequestHash;
this.proxy = !!json.ExternalProxy;
this.size(pInt(json.Size));
this.from = EmailCollectionModel.reviveFromJson(json.From);
@ -250,8 +259,6 @@ class MessageModel extends AbstractModel {
}
this.dateTimeStampInUTC(pInt(json.DateTimeStampInUTC));
this.hasAttachments(!!json.HasAttachments);
this.attachmentsSpecData(isArray(json.AttachmentsSpecData) ? json.AttachmentsSpecData : []);
this.fromEmailString(this.from.toString(true));
this.fromClearEmailString(this.from.toStringClear());
@ -262,8 +269,6 @@ class MessageModel extends AbstractModel {
this.initFlagsByJson(json);
this.computeSenderEmail();
result = true;
}
return result;
@ -274,41 +279,27 @@ class MessageModel extends AbstractModel {
* @returns {boolean}
*/
initUpdateByMessageJson(json) {
let result = false,
priority = MessagePriority.Normal;
if (json && 'Object/Message' === json['@Object']) {
priority = pInt(json.Priority);
this.priority(
[MessagePriority.High, MessagePriority.Low].includes(priority) ? priority : MessagePriority.Normal
);
let result = this.setFromJson(json);
if (result) {
this.aDraftInfo = json.DraftInfo;
this.sMessageId = json.MessageId;
this.sInReplyTo = json.InReplyTo;
this.sReferences = json.References;
this.proxy = !!json.ExternalProxy;
if (PgpStore.capaOpenPGP()) {
this.isPgpSigned(!!json.PgpSigned);
this.isPgpEncrypted(!!json.PgpEncrypted);
}
this.hasAttachments(!!json.HasAttachments);
this.attachmentsSpecData(isArray(json.AttachmentsSpecData) ? json.AttachmentsSpecData : []);
this.foundedCIDs = isArray(json.FoundedCIDs) ? json.FoundedCIDs : [];
this.attachments(AttachmentCollectionModel.reviveFromJson(json.Attachments, this.foundedCIDs));
// this.foundedCIDs = isArray(json.FoundedCIDs) ? json.FoundedCIDs : [];
// this.attachments(AttachmentCollectionModel.reviveFromJson(json.Attachments, this.foundedCIDs));
this.attachments(AttachmentCollectionModel.reviveFromJson(json.Attachments));
this.readReceipt(json.ReadReceipt || '');
this.computeSenderEmail();
result = true;
}
return result;
}