mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-11 00:14:50 +03:00
Delete and Move optimizations
This commit is contained in:
parent
b6f4e9ad4f
commit
2bf7c2e033
10 changed files with 580 additions and 564 deletions
|
|
@ -99,10 +99,9 @@ MailBoxFolderListViewModel.prototype.messagesDrop = function (oToFolder, oUi)
|
|||
aUids = oUi.helper.data('rl-uids')
|
||||
;
|
||||
|
||||
if (MailBoxMessageListViewModel && MailBoxMessageListViewModel.__vm && Utils.isNormal(sFromFolderFullNameRaw) && Utils.isArray(aUids))
|
||||
if (Utils.isNormal(sFromFolderFullNameRaw) && '' !== sFromFolderFullNameRaw && Utils.isArray(aUids))
|
||||
{
|
||||
MailBoxMessageListViewModel.__vm.moveMessagesToFolder(
|
||||
sFromFolderFullNameRaw, aUids, oToFolder.fullNameRaw, bCopy);
|
||||
RL.moveMessagesToFolder(sFromFolderFullNameRaw, aUids, oToFolder.fullNameRaw, bCopy);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -131,15 +131,21 @@ function MailBoxMessageListViewModel()
|
|||
}, this.canBeMoved);
|
||||
|
||||
this.deleteWithoutMoveCommand = Utils.createCommand(this, function () {
|
||||
this.deleteSelectedMessageFromCurrentFolder(Enums.FolderType.Trash, false);
|
||||
RL.deleteMessagesFromFolder(Enums.FolderType.Trash,
|
||||
RL.data().currentFolderFullNameRaw(),
|
||||
RL.data().messageListCheckedOrSelectedUidsWithSubMails(), false);
|
||||
}, this.canBeMoved);
|
||||
|
||||
this.deleteCommand = Utils.createCommand(this, function () {
|
||||
this.deleteSelectedMessageFromCurrentFolder(Enums.FolderType.Trash, true);
|
||||
RL.deleteMessagesFromFolder(Enums.FolderType.Trash,
|
||||
RL.data().currentFolderFullNameRaw(),
|
||||
RL.data().messageListCheckedOrSelectedUidsWithSubMails(), true);
|
||||
}, this.canBeMoved);
|
||||
|
||||
this.spamCommand = Utils.createCommand(this, function () {
|
||||
this.deleteSelectedMessageFromCurrentFolder(Enums.FolderType.Spam, true);
|
||||
RL.deleteMessagesFromFolder(Enums.FolderType.Spam,
|
||||
RL.data().currentFolderFullNameRaw(),
|
||||
RL.data().messageListCheckedOrSelectedUidsWithSubMails(), true);
|
||||
}, this.canBeMoved);
|
||||
|
||||
this.moveCommand = Utils.createCommand(this, Utils.emptyFunction, this.canBeMoved);
|
||||
|
|
@ -197,8 +203,6 @@ function MailBoxMessageListViewModel()
|
|||
}, this)
|
||||
;
|
||||
|
||||
this.moveOrDeleteResponse = _.bind(this.moveOrDeleteResponse, this);
|
||||
|
||||
Knoin.constructorEnd(this);
|
||||
}
|
||||
|
||||
|
|
@ -221,165 +225,6 @@ MailBoxMessageListViewModel.prototype.cancelSearch = function ()
|
|||
this.inputMessageListSearchFocus(false);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} sFromFolderFullNameRaw
|
||||
* @param {Array} aUidForRemove
|
||||
* @param {string=} sToFolderFullNameRaw
|
||||
* @param {boolean=} bCopy = false
|
||||
*/
|
||||
MailBoxMessageListViewModel.prototype.removeMessagesFromList = function (sFromFolderFullNameRaw, aUidForRemove, sToFolderFullNameRaw, bCopy)
|
||||
{
|
||||
sToFolderFullNameRaw = Utils.isNormal(sToFolderFullNameRaw) ? sToFolderFullNameRaw : '';
|
||||
bCopy = Utils.isUnd(bCopy) ? false : !!bCopy;
|
||||
|
||||
var
|
||||
iUnseenCount = 0 ,
|
||||
oData = RL.data(),
|
||||
oFromFolder = RL.cache().getFolderFromCacheList(sFromFolderFullNameRaw),
|
||||
oToFolder = '' === sToFolderFullNameRaw ? null : RL.cache().getFolderFromCacheList(sToFolderFullNameRaw || ''),
|
||||
sCurrentFolderFullNameRaw = oData.currentFolderFullNameRaw(),
|
||||
oCurrentMessage = oData.message(),
|
||||
aMessages = sCurrentFolderFullNameRaw === sFromFolderFullNameRaw ? _.filter(oData.messageList(), function (oMessage) {
|
||||
return oMessage && -1 < Utils.inArray(oMessage.uid, aUidForRemove);
|
||||
}) : []
|
||||
;
|
||||
|
||||
_.each(aMessages, function (oMessage) {
|
||||
if (oMessage && oMessage.unseen())
|
||||
{
|
||||
iUnseenCount++;
|
||||
}
|
||||
});
|
||||
|
||||
if (oFromFolder && !bCopy)
|
||||
{
|
||||
oFromFolder.messageCountAll(0 <= oFromFolder.messageCountAll() - aUidForRemove.length ?
|
||||
oFromFolder.messageCountAll() - aUidForRemove.length : 0);
|
||||
|
||||
if (0 < iUnseenCount)
|
||||
{
|
||||
oFromFolder.messageCountUnread(0 <= oFromFolder.messageCountUnread() - iUnseenCount ?
|
||||
oFromFolder.messageCountUnread() - iUnseenCount : 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (oToFolder)
|
||||
{
|
||||
oToFolder.messageCountAll(oToFolder.messageCountAll() + aUidForRemove.length);
|
||||
if (0 < iUnseenCount)
|
||||
{
|
||||
oToFolder.messageCountUnread(oToFolder.messageCountUnread() + iUnseenCount);
|
||||
}
|
||||
}
|
||||
|
||||
if (0 < aMessages.length)
|
||||
{
|
||||
if (bCopy)
|
||||
{
|
||||
_.each(aMessages, function (oMessage) {
|
||||
oMessage.checked(false);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
_.each(aMessages, function (oMessage) {
|
||||
if (oCurrentMessage && oCurrentMessage.requestHash === oMessage.requestHash)
|
||||
{
|
||||
oCurrentMessage = null;
|
||||
oData.message(null);
|
||||
}
|
||||
|
||||
oMessage.deleted(true);
|
||||
});
|
||||
|
||||
_.delay(function () {
|
||||
_.each(aMessages, function (oMessage) {
|
||||
oData.messageList.remove(oMessage);
|
||||
});
|
||||
}, 400);
|
||||
|
||||
RL.data().messageListIsNotCompleted(true);
|
||||
RL.cache().setFolderHash(sFromFolderFullNameRaw, '');
|
||||
}
|
||||
|
||||
if (Utils.isNormal(sToFolderFullNameRaw))
|
||||
{
|
||||
RL.cache().setFolderHash(sToFolderFullNameRaw || '', '');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string=} sToFolderFullNameRaw
|
||||
*/
|
||||
MailBoxMessageListViewModel.prototype.removeCheckedOrSelectedMessagesFromList = function (sToFolderFullNameRaw)
|
||||
{
|
||||
this.removeMessagesFromList(RL.data().currentFolderFullNameRaw(), _.map(RL.data().messageListCheckedOrSelected(), function (oMessage) {
|
||||
return oMessage.uid;
|
||||
}), sToFolderFullNameRaw);
|
||||
};
|
||||
|
||||
MailBoxMessageListViewModel.prototype.moveOrDeleteResponse = function (sResult, oData)
|
||||
{
|
||||
if (Enums.StorageResultType.Success === sResult && RL.data().currentFolder())
|
||||
{
|
||||
if (oData && Utils.isArray(oData.Result) && 2 === oData.Result.length)
|
||||
{
|
||||
RL.cache().setFolderHash(oData.Result[0], oData.Result[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (oData && -1 < Utils.inArray(oData.ErrorCode,
|
||||
[Enums.Notification.CantMoveMessage, Enums.Notification.CantCopyMessage]))
|
||||
{
|
||||
window.alert(Utils.getNotification(oData.ErrorCode));
|
||||
}
|
||||
|
||||
RL.cache().setFolderHash(RL.data().currentFolderFullNameRaw(), '');
|
||||
}
|
||||
|
||||
RL.reloadMessageList();
|
||||
|
||||
RL.quotaDebounce();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} sFromFolderFullNameRaw
|
||||
* @param {Array} aUidForRemove
|
||||
* @param {string} sToFolderFullNameRaw
|
||||
* @param {boolean=} bCopy = false
|
||||
*/
|
||||
MailBoxMessageListViewModel.prototype.moveMessagesToFolder = function (sFromFolderFullNameRaw, aUidForRemove, sToFolderFullNameRaw, bCopy)
|
||||
{
|
||||
if (sFromFolderFullNameRaw !== sToFolderFullNameRaw && Utils.isArray(aUidForRemove) && 0 < aUidForRemove.length)
|
||||
{
|
||||
var
|
||||
oFromFolder = RL.cache().getFolderFromCacheList(sFromFolderFullNameRaw),
|
||||
oToFolder = RL.cache().getFolderFromCacheList(sToFolderFullNameRaw)
|
||||
;
|
||||
|
||||
if (oFromFolder && oToFolder)
|
||||
{
|
||||
bCopy = Utils.isUnd(bCopy) ? false : !!bCopy;
|
||||
|
||||
RL.remote()[bCopy ? 'messagesCopy' : 'messagesMove'](
|
||||
this.moveOrDeleteResponse,
|
||||
oFromFolder.fullNameRaw,
|
||||
oToFolder.fullNameRaw,
|
||||
aUidForRemove
|
||||
);
|
||||
|
||||
oToFolder.actionBlink(true);
|
||||
|
||||
this.removeMessagesFromList(sFromFolderFullNameRaw, aUidForRemove, sToFolderFullNameRaw, bCopy);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} sToFolderFullNameRaw
|
||||
* @return {boolean}
|
||||
|
|
@ -388,74 +233,14 @@ MailBoxMessageListViewModel.prototype.moveSelectedMessagesToFolder = function (s
|
|||
{
|
||||
if (this.canBeMoved())
|
||||
{
|
||||
return this.moveMessagesToFolder(RL.data().currentFolderFullNameRaw(),
|
||||
RL.moveMessagesToFolder(
|
||||
RL.data().currentFolderFullNameRaw(),
|
||||
RL.data().messageListCheckedOrSelectedUidsWithSubMails(), sToFolderFullNameRaw);
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {number} iType
|
||||
* @param {boolean=} bUseFolder = true
|
||||
*/
|
||||
MailBoxMessageListViewModel.prototype.deleteSelectedMessageFromCurrentFolder = function (iType, bUseFolder)
|
||||
{
|
||||
if (this.canBeMoved())
|
||||
{
|
||||
bUseFolder = Utils.isUnd(bUseFolder) ? true : !!bUseFolder;
|
||||
if (bUseFolder)
|
||||
{
|
||||
if ((Enums.FolderType.Spam === iType && Consts.Values.UnuseOptionValue === RL.data().spamFolder()) ||
|
||||
(Enums.FolderType.Trash === iType && Consts.Values.UnuseOptionValue === RL.data().trashFolder()))
|
||||
{
|
||||
bUseFolder = false;
|
||||
}
|
||||
}
|
||||
|
||||
var
|
||||
self = this,
|
||||
aUIds = null,
|
||||
sCurrentFolderFullNameRaw = RL.data().currentFolderFullNameRaw(),
|
||||
oTrashOrSpamFolder = RL.cache().getFolderFromCacheList(
|
||||
Enums.FolderType.Spam === iType ? RL.data().spamFolder() : RL.data().trashFolder())
|
||||
;
|
||||
|
||||
if (!oTrashOrSpamFolder && bUseFolder)
|
||||
{
|
||||
kn.showScreenPopup(PopupsFolderSystemViewModel, [
|
||||
Enums.FolderType.Spam === iType ? Enums.SetSystemFoldersNotification.Spam : Enums.SetSystemFoldersNotification.Trash]);
|
||||
}
|
||||
else if (!bUseFolder || (oTrashOrSpamFolder && RL.data().currentFolderFullNameRaw() === oTrashOrSpamFolder.fullNameRaw))
|
||||
{
|
||||
aUIds = RL.data().messageListCheckedOrSelectedUidsWithSubMails();
|
||||
|
||||
kn.showScreenPopup(PopupsAskViewModel, [Utils.i18n('POPUPS_ASK/DESC_WANT_DELETE_MESSAGES'), function () {
|
||||
|
||||
RL.remote().messagesDelete(
|
||||
self.moveOrDeleteResponse,
|
||||
sCurrentFolderFullNameRaw,
|
||||
aUIds
|
||||
);
|
||||
|
||||
self.removeCheckedOrSelectedMessagesFromList();
|
||||
}]);
|
||||
}
|
||||
else if (oTrashOrSpamFolder)
|
||||
{
|
||||
RL.remote().messagesMove(
|
||||
this.moveOrDeleteResponse,
|
||||
sCurrentFolderFullNameRaw,
|
||||
oTrashOrSpamFolder.fullNameRaw,
|
||||
RL.data().messageListCheckedOrSelectedUidsWithSubMails()
|
||||
);
|
||||
|
||||
oTrashOrSpamFolder.actionBlink(true);
|
||||
this.removeCheckedOrSelectedMessagesFromList(oTrashOrSpamFolder.fullNameRaw);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
MailBoxMessageListViewModel.prototype.dragAndDronHelper = function (oMessageListItem, bCopy)
|
||||
{
|
||||
if (oMessageListItem)
|
||||
|
|
|
|||
|
|
@ -68,13 +68,25 @@ function MailBoxMessageViewViewModel()
|
|||
}, this.messageVisibility);
|
||||
|
||||
this.deleteCommand = Utils.createCommand(this, function () {
|
||||
// TODO
|
||||
window.console.log(arguments);
|
||||
|
||||
if (this.message())
|
||||
{
|
||||
RL.deleteMessagesFromFolder(Enums.FolderType.Trash,
|
||||
this.message().folderFullNameRaw,
|
||||
[this.message().uid], true);
|
||||
}
|
||||
|
||||
}, this.messageVisibility);
|
||||
|
||||
this.spamCommand = Utils.createCommand(this, function () {
|
||||
// TODO
|
||||
window.console.log(arguments);
|
||||
|
||||
if (this.message())
|
||||
{
|
||||
RL.deleteMessagesFromFolder(Enums.FolderType.Spam,
|
||||
this.message().folderFullNameRaw,
|
||||
[this.message().uid], true);
|
||||
}
|
||||
|
||||
}, this.messageVisibility);
|
||||
|
||||
// viewer
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ function PopupsComposeViewModel()
|
|||
this.bFromDraft = false;
|
||||
this.sReferences = '';
|
||||
|
||||
this.bReloadFolder = false;
|
||||
this.bAllowIdentities = RL.settingsGet('AllowIdentities');
|
||||
this.bAllowCtrlS = !!RL.settingsGet('AllowCtrlSOnCompose');
|
||||
|
||||
|
|
@ -177,38 +176,7 @@ function PopupsComposeViewModel()
|
|||
|
||||
this.deleteCommand = Utils.createCommand(this, function () {
|
||||
|
||||
var
|
||||
oMessage = null,
|
||||
sDraftFolder = this.draftFolder(),
|
||||
sDraftUid = this.draftUid()
|
||||
;
|
||||
|
||||
if (this.bFromDraft)
|
||||
{
|
||||
oMessage = RL.data().message();
|
||||
if (oMessage && sDraftFolder === oMessage.folderFullNameRaw && sDraftUid === oMessage.uid)
|
||||
{
|
||||
RL.data().message(null);
|
||||
}
|
||||
}
|
||||
|
||||
if (RL.data().currentFolderFullNameRaw() === this.draftFolder())
|
||||
{
|
||||
_.each(RL.data().messageList(), function (oMessage) {
|
||||
if (oMessage && sDraftFolder === oMessage.folderFullNameRaw && sDraftUid === oMessage.uid)
|
||||
{
|
||||
oMessage.deleted(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
RL.data().messageListIsNotCompleted(true);
|
||||
RL.remote().messagesDelete(function () {
|
||||
RL.cache().setFolderHash(sDraftFolder, '');
|
||||
RL.reloadMessageList();
|
||||
}, this.draftFolder(), [this.draftUid()]);
|
||||
|
||||
this.bReloadFolder = false;
|
||||
RL.deleteMessagesFromFolderWithoutCheck(this.draftFolder(), [this.draftUid()]);
|
||||
kn.hideScreenPopup(PopupsComposeViewModel);
|
||||
|
||||
}, function () {
|
||||
|
|
@ -247,7 +215,6 @@ function PopupsComposeViewModel()
|
|||
{
|
||||
this.sendError(false);
|
||||
this.sending(true);
|
||||
this.bReloadFolder = true;
|
||||
|
||||
if (Utils.isArray(this.aDraftInfo) && 3 === this.aDraftInfo.length)
|
||||
{
|
||||
|
|
@ -265,6 +232,7 @@ function PopupsComposeViewModel()
|
|||
|
||||
RL.cache().setMessageFlagsToCache(this.aDraftInfo[2], this.aDraftInfo[1], aFlagsCache);
|
||||
RL.reloadFlagsCurrentMessageListAndMessageFromCache();
|
||||
RL.cache().setFolderHash(this.aDraftInfo[2], '');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -305,7 +273,6 @@ function PopupsComposeViewModel()
|
|||
{
|
||||
this.savedError(false);
|
||||
this.saving(true);
|
||||
this.bReloadFolder = true;
|
||||
|
||||
RL.cache().setFolderHash(RL.data().draftFolder(), '');
|
||||
|
||||
|
|
@ -368,14 +335,6 @@ function PopupsComposeViewModel()
|
|||
return this.dropboxEnabled();
|
||||
});
|
||||
|
||||
this.modalVisibility.subscribe(function (bValue) {
|
||||
if (!bValue && this.bReloadFolder)
|
||||
{
|
||||
this.bReloadFolder = false;
|
||||
RL.reloadMessageList();
|
||||
}
|
||||
}, this);
|
||||
|
||||
this.driveEnabled = ko.observable(false);
|
||||
|
||||
this.driveCommand = Utils.createCommand(this, function () {
|
||||
|
|
@ -396,6 +355,23 @@ function PopupsComposeViewModel()
|
|||
|
||||
Utils.extendAsViewModel('PopupsComposeViewModel', PopupsComposeViewModel);
|
||||
|
||||
PopupsComposeViewModel.prototype.reloadDraftFolder = function ()
|
||||
{
|
||||
var sDraftFolder = RL.data().draftFolder();
|
||||
if ('' !== sDraftFolder)
|
||||
{
|
||||
RL.cache().setFolderHash(sDraftFolder, '');
|
||||
if (RL.data().currentFolderFullNameRaw() === sDraftFolder)
|
||||
{
|
||||
RL.reloadMessageList(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
RL.folderInformation(sDraftFolder);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
PopupsComposeViewModel.prototype.findIdentityIdByMessage = function (sComposeType, oMessage)
|
||||
{
|
||||
var
|
||||
|
|
@ -508,6 +484,8 @@ PopupsComposeViewModel.prototype.sendMessageResponse = function (sResult, oData)
|
|||
window.alert(sMessage || Utils.getNotification(Enums.Notification.CantSendMessage));
|
||||
}
|
||||
}
|
||||
|
||||
this.reloadDraftFolder();
|
||||
};
|
||||
|
||||
PopupsComposeViewModel.prototype.saveMessageResponse = function (sResult, oData)
|
||||
|
|
@ -560,6 +538,8 @@ PopupsComposeViewModel.prototype.saveMessageResponse = function (sResult, oData)
|
|||
this.savedError(true);
|
||||
this.savedOrSendingText(Utils.getNotification(Enums.Notification.CantSaveMessage));
|
||||
}
|
||||
|
||||
this.reloadDraftFolder();
|
||||
};
|
||||
|
||||
PopupsComposeViewModel.prototype.onHide = function ()
|
||||
|
|
@ -1439,7 +1419,6 @@ PopupsComposeViewModel.prototype.reset = function ()
|
|||
this.sInReplyTo = '';
|
||||
this.bFromDraft = false;
|
||||
this.sReferences = '';
|
||||
this.bReloadFolder = false;
|
||||
|
||||
this.sendError(false);
|
||||
this.sendSuccessButSaveError(false);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue