mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-01-01 04:22:15 +08:00
Merge some parts of initByJson and initUpdateByMessageJson
Cleanup messageListChecked handling
This commit is contained in:
parent
46198861bc
commit
b66e68a3b1
8 changed files with 46 additions and 61 deletions
|
@ -146,7 +146,7 @@ class Selector {
|
|||
if (0 < len && aCheckedCache.includes(uid)) {
|
||||
isChecked = true;
|
||||
item.checked(true);
|
||||
len -= 1;
|
||||
--len;
|
||||
}
|
||||
|
||||
if (!isChecked && null !== mSelected && mSelected === uid) {
|
||||
|
|
|
@ -418,7 +418,7 @@ export function htmlToPlain(html) {
|
|||
limit = 800;
|
||||
|
||||
while (0 < limit) {
|
||||
limit -= 1;
|
||||
--limit;
|
||||
iP1 = text.indexOf('__bq__start__', pos);
|
||||
if (-1 < iP1) {
|
||||
iP2 = text.indexOf('__bq__start__', iP1 + 5);
|
||||
|
@ -778,17 +778,17 @@ export function computedPagenatorHelper(koCurrentPage, koPageCount) {
|
|||
}
|
||||
|
||||
while (0 < limit) {
|
||||
prev -= 1;
|
||||
next += 1;
|
||||
--prev;
|
||||
++next;
|
||||
|
||||
if (0 < prev) {
|
||||
fAdd(prev, false);
|
||||
limit -= 1;
|
||||
--limit;
|
||||
}
|
||||
|
||||
if (pageCount >= next) {
|
||||
fAdd(next, true);
|
||||
limit -= 1;
|
||||
--limit;
|
||||
} else if (0 >= prev) {
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -154,11 +154,9 @@ class MessageUserStore {
|
|||
return selectedMessage
|
||||
? checked.concat([selectedMessage]).filter((value, index, self) => self.indexOf(value) == index)
|
||||
: checked;
|
||||
} else if (selectedMessage) {
|
||||
return [selectedMessage];
|
||||
}
|
||||
|
||||
return focusedMessage ? [focusedMessage] : [];
|
||||
return selectedMessage ? [selectedMessage] : (focusedMessage ? [focusedMessage] : []);
|
||||
});
|
||||
|
||||
this.messageListCheckedOrSelectedUidsWithSubMails = ko.computed(() => {
|
||||
|
@ -298,7 +296,7 @@ class MessageUserStore {
|
|||
|
||||
messages.forEach(item => {
|
||||
if (item && item.unseen()) {
|
||||
unseenCount += 1;
|
||||
++unseenCount;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -488,8 +486,7 @@ class MessageUserStore {
|
|||
|
||||
const textBody = document.getElementById(id);
|
||||
if (textBody) {
|
||||
iMessageBodyCacheCount += 1;
|
||||
textBody.rlCacheCount = iMessageBodyCacheCount;
|
||||
textBody.rlCacheCount = ++iMessageBodyCacheCount;
|
||||
message.fetchDataFromDom();
|
||||
message.body = textBody;
|
||||
} else {
|
||||
|
@ -532,13 +529,11 @@ class MessageUserStore {
|
|||
resultHtml = '<pre>' + resultHtml + '</pre>';
|
||||
}
|
||||
|
||||
iMessageBodyCacheCount += 1;
|
||||
|
||||
body = Element.fromHTML('<div id="' + id + '" hidden="" class="rl-cache-class b-text-part '
|
||||
+ (isHtml ? 'html' : 'plain') + '">'
|
||||
+ findEmailAndLinks(resultHtml)
|
||||
+ '</div>');
|
||||
body.rlCacheCount = iMessageBodyCacheCount;
|
||||
body.rlCacheCount = ++iMessageBodyCacheCount;
|
||||
|
||||
// Drop Microsoft Office style properties
|
||||
const rgbRE = /rgb\((\d+),\s*(\d+),\s*(\d+)\)/g,
|
||||
|
|
|
@ -64,7 +64,7 @@ class AddOpenPgpKeyPopupView extends AbstractViewNext {
|
|||
}
|
||||
}
|
||||
|
||||
count -= 1;
|
||||
--count;
|
||||
done = false;
|
||||
} else {
|
||||
done = true;
|
||||
|
|
|
@ -449,7 +449,7 @@ class ContactsPopupView extends AbstractViewNext {
|
|||
}
|
||||
|
||||
contact.deleted(true);
|
||||
count -= 1;
|
||||
--count;
|
||||
});
|
||||
|
||||
if (0 >= count) {
|
||||
|
|
|
@ -98,7 +98,6 @@ class MessageListMailBoxUserView extends AbstractViewNext {
|
|||
this.messageListEndFolder = MessageStore.messageListEndFolder;
|
||||
this.messageListEndThreadUid = MessageStore.messageListEndThreadUid;
|
||||
|
||||
this.messageListChecked = MessageStore.messageListChecked;
|
||||
this.messageListCheckedOrSelected = MessageStore.messageListCheckedOrSelected;
|
||||
this.messageListCheckedOrSelectedUidsWithSubMails = MessageStore.messageListCheckedOrSelectedUidsWithSubMails;
|
||||
this.messageListCompleteLoadingThrottle = MessageStore.messageListCompleteLoadingThrottle;
|
||||
|
@ -195,11 +194,10 @@ class MessageListMailBoxUserView extends AbstractViewNext {
|
|||
() => this.isSpamFolder() && !this.isSpamDisabled() && !this.isDraftFolder() && !this.isSentFolder()
|
||||
);
|
||||
|
||||
this.mobileCheckedStateShow = ko.computed(() => {
|
||||
return this.mobile ? 0 < this.messageListChecked().length : true;
|
||||
});
|
||||
// this.messageListChecked = MessageStore.messageListChecked;
|
||||
this.mobileCheckedStateShow = ko.computed(() => this.mobile ? 0 < MessageStore.messageListChecked().length : true);
|
||||
|
||||
this.mobileCheckedStateHide = ko.computed(() => this.mobile ? !this.messageListChecked().length : true);
|
||||
this.mobileCheckedStateHide = ko.computed(() => this.mobile ? !MessageStore.messageListChecked().length : true);
|
||||
|
||||
this.messageListFocused = ko.computed(() => Focused.MessageList === AppStore.focusedState());
|
||||
|
||||
|
@ -376,7 +374,7 @@ class MessageListMailBoxUserView extends AbstractViewNext {
|
|||
}
|
||||
|
||||
goToUpUpOrDownDown(up) {
|
||||
if (this.messageListChecked().length) {
|
||||
if (MessageStore.messageListChecked().length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -488,6 +486,7 @@ class MessageListMailBoxUserView extends AbstractViewNext {
|
|||
dragImage || (dragImage = document.getElementById('messagesDragImage'));
|
||||
|
||||
const uids = MessageStore.messageListCheckedOrSelectedUidsWithSubMails();
|
||||
item && !uids.includes(item.uid) && uids.push(item.uid);
|
||||
if (dragImage && uids.length) {
|
||||
dragImage.querySelector('.text').textContent = uids.length;
|
||||
let img = dragImage.querySelector('.icon-white');
|
||||
|
@ -544,7 +543,7 @@ class MessageListMailBoxUserView extends AbstractViewNext {
|
|||
if (folder) {
|
||||
MessageStore.messageList().forEach(message => {
|
||||
if (message.unseen()) {
|
||||
cnt += 1;
|
||||
++cnt;
|
||||
}
|
||||
|
||||
message.unseen(false);
|
||||
|
@ -570,7 +569,7 @@ class MessageListMailBoxUserView extends AbstractViewNext {
|
|||
if (folder) {
|
||||
MessageStore.messageList().forEach(message => {
|
||||
if (!message.unseen()) {
|
||||
cnt += 1;
|
||||
++cnt;
|
||||
}
|
||||
|
||||
message.unseen(true);
|
||||
|
|
|
@ -92,7 +92,7 @@ class MessageViewMailBoxUserView extends AbstractViewNext {
|
|||
this.attachmentsActions = AppStore.attachmentsActions;
|
||||
|
||||
this.message = MessageStore.message;
|
||||
this.messageListChecked = MessageStore.messageListChecked;
|
||||
// this.messageListChecked = MessageStore.messageListChecked;
|
||||
this.hasCheckedMessages = MessageStore.hasCheckedMessages;
|
||||
this.messageListCheckedOrSelectedUidsWithSubMails = MessageStore.messageListCheckedOrSelectedUidsWithSubMails;
|
||||
this.messageLoadingThrottle = MessageStore.messageLoadingThrottle;
|
||||
|
@ -410,7 +410,7 @@ class MessageViewMailBoxUserView extends AbstractViewNext {
|
|||
index = listIndex;
|
||||
}
|
||||
|
||||
listIndex += 1;
|
||||
++listIndex;
|
||||
|
||||
return {
|
||||
src: item.linkPreview(),
|
||||
|
|
Loading…
Reference in a new issue