2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
import window from 'window';
|
|
|
|
import _ from '_';
|
|
|
|
import ko from 'ko';
|
|
|
|
import $ from '$';
|
|
|
|
|
|
|
|
import {
|
|
|
|
Magics, Layout, Focused,
|
|
|
|
MessageSetAction,
|
|
|
|
StorageResultType,
|
|
|
|
Notification
|
|
|
|
} from 'Common/Enums';
|
|
|
|
|
|
|
|
import {
|
|
|
|
trim, isNormal, isArray, inArray,
|
|
|
|
pInt, pString, plainToHtml,
|
2016-10-26 06:10:36 +08:00
|
|
|
windowResize, findEmailAndLinks,
|
|
|
|
getRealHeight
|
2016-08-17 06:01:20 +08:00
|
|
|
} from 'Common/Utils';
|
|
|
|
|
|
|
|
import {
|
|
|
|
getFolderInboxName,
|
|
|
|
addNewMessageCache,
|
|
|
|
setFolderUidNext,
|
|
|
|
getFolderFromCacheList,
|
|
|
|
setFolderHash,
|
|
|
|
initMessageFlagsFromCache,
|
|
|
|
addRequestedMessage,
|
|
|
|
clearMessageFlagsFromCacheByFolder,
|
|
|
|
hasNewMessageAndRemoveFromCache,
|
|
|
|
storeMessageFlagsToCache,
|
|
|
|
clearNewMessageCache
|
|
|
|
} from 'Common/Cache';
|
|
|
|
|
|
|
|
import {MESSAGE_BODY_CACHE_LIMIT} from 'Common/Consts';
|
|
|
|
import {data as GlobalsData, $div} from 'Common/Globals';
|
|
|
|
import {mailBox, notificationMailIcon} from 'Common/Links';
|
|
|
|
import {i18n, getNotification} from 'Common/Translator';
|
2016-09-13 04:50:21 +08:00
|
|
|
import {momentNowUnix} from 'Common/Momentor';
|
2016-08-17 06:01:20 +08:00
|
|
|
|
|
|
|
import * as MessageHelper from 'Helper/Message';
|
|
|
|
import {MessageModel} from 'Model/Message';
|
|
|
|
|
|
|
|
import {setHash} from 'Knoin/Knoin';
|
|
|
|
|
|
|
|
import AppStore from 'Stores/User/App';
|
2016-09-13 04:50:21 +08:00
|
|
|
import AccountStore from 'Stores/User/Account';
|
2016-08-17 06:01:20 +08:00
|
|
|
import FolderStore from 'Stores/User/Folder';
|
|
|
|
import PgpStore from 'Stores/User/Pgp';
|
|
|
|
import SettingsStore from 'Stores/User/Settings';
|
2016-09-13 04:50:21 +08:00
|
|
|
import NotificationStore from 'Stores/User/Notification';
|
2016-08-17 06:01:20 +08:00
|
|
|
|
|
|
|
import {getApp} from 'Helper/Apps/User';
|
|
|
|
|
|
|
|
import Remote from 'Remote/User/Ajax';
|
|
|
|
|
|
|
|
class MessageUserStore
|
|
|
|
{
|
|
|
|
constructor()
|
|
|
|
{
|
|
|
|
this.staticMessage = new MessageModel();
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.messageList = ko.observableArray([]).extend({rateLimit: 0});
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.messageListCount = ko.observable(0);
|
|
|
|
this.messageListSearch = ko.observable('');
|
|
|
|
this.messageListThreadUid = ko.observable('');
|
|
|
|
this.messageListPage = ko.observable(1);
|
|
|
|
this.messageListPageBeforeThread = ko.observable(1);
|
|
|
|
this.messageListError = ko.observable('');
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.messageListEndFolder = ko.observable('');
|
|
|
|
this.messageListEndSearch = ko.observable('');
|
|
|
|
this.messageListEndThreadUid = ko.observable('');
|
|
|
|
this.messageListEndPage = ko.observable(1);
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.messageListLoading = ko.observable(false);
|
|
|
|
this.messageListIsNotCompleted = ko.observable(false);
|
|
|
|
this.messageListCompleteLoadingThrottle = ko.observable(false).extend({throttle: 200});
|
|
|
|
this.messageListCompleteLoadingThrottleForAnimation = ko.observable(false).extend({specialThrottle: 700});
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.messageListDisableAutoSelect = ko.observable(false).extend({falseTimeout: 500});
|
2015-02-23 00:35:17 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.selectorMessageSelected = ko.observable(null);
|
|
|
|
this.selectorMessageFocused = ko.observable(null);
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
// message viewer
|
|
|
|
this.message = ko.observable(null);
|
2015-03-06 08:42:40 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.message.viewTrigger = ko.observable(false);
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.messageError = ko.observable('');
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.messageCurrentLoading = ko.observable(false);
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.messageLoadingThrottle = ko.observable(false).extend({throttle: Magics.Time50ms});
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.messageFullScreenMode = ko.observable(false);
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.messagesBodiesDom = ko.observable(null);
|
|
|
|
this.messageActiveDom = ko.observable(null);
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.computers();
|
|
|
|
this.subscribers();
|
2015-03-06 08:42:40 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.onMessageResponse = _.bind(this.onMessageResponse, this);
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.purgeMessageBodyCacheThrottle = _.throttle(this.purgeMessageBodyCache, Magics.Time30s);
|
|
|
|
}
|
2015-04-07 03:32:19 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
computers() {
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.messageLoading = ko.computed(() => this.messageCurrentLoading());
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.messageListEndHash = ko.computed(
|
|
|
|
() => this.messageListEndFolder() + '|' + this.messageListEndSearch() +
|
|
|
|
'|' + this.messageListEndThreadUid() + '|' + this.messageListEndPage()
|
|
|
|
);
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.messageListPageCount = ko.computed(() => {
|
|
|
|
const page = window.Math.ceil(this.messageListCount() / SettingsStore.messagesPerPage());
|
|
|
|
return 0 >= page ? 1 : page;
|
|
|
|
});
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.mainMessageListSearch = ko.computed({
|
|
|
|
read: this.messageListSearch,
|
|
|
|
write: (value) => {
|
|
|
|
setHash(
|
|
|
|
mailBox(FolderStore.currentFolderFullNameHash(), 1, trim(value.toString()), this.messageListThreadUid())
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2015-03-06 08:42:40 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.messageListCompleteLoading = ko.computed(() => {
|
|
|
|
const
|
|
|
|
one = this.messageListLoading(),
|
|
|
|
two = this.messageListIsNotCompleted();
|
|
|
|
return one || two;
|
|
|
|
});
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.isMessageSelected = ko.computed(() => null !== this.message());
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.messageListChecked = ko.computed(
|
|
|
|
() => _.filter(this.messageList(), (item) => item.checked())
|
|
|
|
).extend({rateLimit: 0});
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.hasCheckedMessages = ko.computed(() => 0 < this.messageListChecked().length).extend({rateLimit: 0});
|
|
|
|
|
|
|
|
this.messageListCheckedOrSelected = ko.computed(() => {
|
|
|
|
const
|
|
|
|
checked = this.messageListChecked(),
|
2016-12-15 05:56:17 +08:00
|
|
|
selectedMessage = this.selectorMessageSelected(),
|
|
|
|
focusedMessage = this.selectorMessageFocused();
|
|
|
|
|
2017-04-03 05:15:31 +08:00
|
|
|
if (checked.length) {
|
|
|
|
return _.union(checked, selectedMessage ? [selectedMessage] : []);
|
|
|
|
} else if (selectedMessage) {
|
|
|
|
return [selectedMessage];
|
|
|
|
}
|
2017-04-03 05:40:13 +08:00
|
|
|
|
|
|
|
return focusedMessage ? [focusedMessage] : [];
|
2016-06-30 08:02:45 +08:00
|
|
|
});
|
2015-03-06 08:42:40 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.messageListCheckedOrSelectedUidsWithSubMails = ko.computed(() => {
|
|
|
|
let result = [];
|
|
|
|
_.each(this.messageListCheckedOrSelected(), (message) => {
|
|
|
|
if (message)
|
|
|
|
{
|
|
|
|
result.push(message.uid);
|
|
|
|
if (1 < message.threadsLen())
|
|
|
|
{
|
|
|
|
result = _.union(result, message.threads());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
});
|
|
|
|
}
|
2015-03-06 08:42:40 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
subscribers() {
|
2015-03-06 08:42:40 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.messageListCompleteLoading.subscribe((value) => {
|
|
|
|
value = !!value;
|
|
|
|
this.messageListCompleteLoadingThrottle(value);
|
|
|
|
this.messageListCompleteLoadingThrottleForAnimation(value);
|
|
|
|
});
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.messageList.subscribe(_.debounce((list) => {
|
|
|
|
_.each(list, (item) => {
|
|
|
|
if (item && item.newForAnimation())
|
|
|
|
{
|
|
|
|
item.newForAnimation(false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, Magics.Time500ms));
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.message.subscribe((message) => {
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
if (message)
|
2015-04-02 02:18:15 +08:00
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
if (Layout.NoPreview === SettingsStore.layout())
|
2015-02-22 06:00:51 +08:00
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
AppStore.focusedState(Focused.MessageView);
|
2015-02-22 06:00:51 +08:00
|
|
|
}
|
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
else
|
2015-02-22 06:00:51 +08:00
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
AppStore.focusedState(Focused.MessageList);
|
|
|
|
|
|
|
|
this.messageFullScreenMode(false);
|
|
|
|
this.hideMessageBodies();
|
2015-02-22 06:00:51 +08:00
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
});
|
2015-04-02 02:18:15 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.messageLoading.subscribe((value) => {
|
|
|
|
this.messageLoadingThrottle(value);
|
|
|
|
});
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.messagesBodiesDom.subscribe((dom) => {
|
|
|
|
if (dom && !(dom instanceof $))
|
2015-02-22 06:00:51 +08:00
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
this.messagesBodiesDom($(dom));
|
2015-02-22 06:00:51 +08:00
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.messageListEndFolder.subscribe((folder) => {
|
|
|
|
const message = this.message();
|
|
|
|
if (message && folder && folder !== message.folderFullNameRaw)
|
|
|
|
{
|
|
|
|
this.message(null);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
purgeMessageBodyCache() {
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
let count = 0;
|
|
|
|
const end = GlobalsData.iMessageBodyCacheCount - MESSAGE_BODY_CACHE_LIMIT;
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
if (0 < end)
|
2016-06-30 08:02:45 +08:00
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
const messagesDom = this.messagesBodiesDom();
|
|
|
|
if (messagesDom)
|
|
|
|
{
|
|
|
|
messagesDom.find('.rl-cache-class').each(function() {
|
|
|
|
const item = $(this); // eslint-disable-line no-invalid-this
|
|
|
|
if (end > item.data('rl-cache-count'))
|
|
|
|
{
|
|
|
|
item.addClass('rl-cache-purge');
|
|
|
|
count += 1;
|
|
|
|
}
|
|
|
|
});
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
if (0 < count)
|
2015-02-22 06:00:51 +08:00
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
_.delay(() => messagesDom.find('.rl-cache-purge').remove(), Magics.Time350ms);
|
2015-02-22 06:00:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
initUidNextAndNewMessages(folder, uidNext, newMessages) {
|
|
|
|
if (getFolderInboxName() === folder && isNormal(uidNext) && '' !== uidNext)
|
2015-02-22 06:00:51 +08:00
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
if (isArray(newMessages) && 0 < newMessages.length)
|
|
|
|
{
|
|
|
|
_.each(newMessages, (item) => {
|
|
|
|
addNewMessageCache(folder, item.Uid);
|
|
|
|
});
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
NotificationStore.playSoundNotification();
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-09-13 04:50:21 +08:00
|
|
|
const len = newMessages.length;
|
2016-08-17 06:01:20 +08:00
|
|
|
if (3 < len)
|
2015-02-22 06:00:51 +08:00
|
|
|
{
|
|
|
|
NotificationStore.displayDesktopNotification(
|
2016-08-17 06:01:20 +08:00
|
|
|
notificationMailIcon(),
|
2016-09-13 04:50:21 +08:00
|
|
|
AccountStore.email(),
|
2016-08-17 06:01:20 +08:00
|
|
|
i18n('MESSAGE_LIST/NEW_MESSAGE_NOTIFICATION', {
|
|
|
|
'COUNT': len
|
|
|
|
}),
|
|
|
|
{'Folder': '', 'Uid': ''}
|
2015-02-22 06:00:51 +08:00
|
|
|
);
|
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
_.each(newMessages, (item) => {
|
|
|
|
NotificationStore.displayDesktopNotification(
|
|
|
|
notificationMailIcon(),
|
|
|
|
MessageHelper.emailArrayToString(MessageHelper.emailArrayFromJson(item.From), false),
|
|
|
|
item.Subject,
|
|
|
|
{'Folder': item.Folder, 'Uid': item.Uid}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
2015-02-22 06:00:51 +08:00
|
|
|
}
|
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
setFolderUidNext(folder, uidNext);
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
hideMessageBodies() {
|
|
|
|
const messagesDom = this.messagesBodiesDom();
|
|
|
|
if (messagesDom)
|
2015-02-22 06:00:51 +08:00
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
messagesDom.find('.b-text-part').hide();
|
2015-02-22 06:00:51 +08:00
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
/**
|
|
|
|
* @param {string} fromFolderFullNameRaw
|
|
|
|
* @param {Array} uidForRemove
|
|
|
|
* @param {string=} toFolderFullNameRaw = ''
|
2016-12-15 05:56:17 +08:00
|
|
|
* @param {boolean=} copy = false
|
2016-08-17 06:01:20 +08:00
|
|
|
*/
|
|
|
|
removeMessagesFromList(fromFolderFullNameRaw, uidForRemove, toFolderFullNameRaw = '', copy = false) {
|
|
|
|
|
|
|
|
uidForRemove = _.map(uidForRemove, (mValue) => pInt(mValue));
|
|
|
|
|
|
|
|
let
|
|
|
|
unseenCount = 0,
|
|
|
|
messageList = this.messageList(),
|
|
|
|
currentMessage = this.message();
|
|
|
|
|
|
|
|
const
|
|
|
|
trashFolder = FolderStore.trashFolder(),
|
|
|
|
spamFolder = FolderStore.spamFolder(),
|
|
|
|
fromFolder = getFolderFromCacheList(fromFolderFullNameRaw),
|
|
|
|
toFolder = '' === toFolderFullNameRaw ? null : getFolderFromCacheList(toFolderFullNameRaw || ''),
|
|
|
|
currentFolderFullNameRaw = FolderStore.currentFolderFullNameRaw(),
|
|
|
|
messages = currentFolderFullNameRaw === fromFolderFullNameRaw ?
|
|
|
|
_.filter(messageList, (item) => (item && -1 < inArray(pInt(item.uid), uidForRemove))) : [];
|
|
|
|
|
|
|
|
_.each(messages, (item) => {
|
|
|
|
if (item && item.unseen())
|
|
|
|
{
|
|
|
|
unseenCount += 1;
|
|
|
|
}
|
|
|
|
});
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
if (fromFolder && !copy)
|
2015-02-22 06:00:51 +08:00
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
fromFolder.messageCountAll(0 <= fromFolder.messageCountAll() - uidForRemove.length ?
|
|
|
|
fromFolder.messageCountAll() - uidForRemove.length : 0);
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
if (0 < unseenCount)
|
|
|
|
{
|
|
|
|
fromFolder.messageCountUnread(0 <= fromFolder.messageCountUnread() - unseenCount ?
|
|
|
|
fromFolder.messageCountUnread() - unseenCount : 0);
|
|
|
|
}
|
2015-02-22 06:00:51 +08:00
|
|
|
}
|
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
if (toFolder)
|
2015-02-22 06:00:51 +08:00
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
if (trashFolder === toFolder.fullNameRaw || spamFolder === toFolder.fullNameRaw)
|
|
|
|
{
|
|
|
|
unseenCount = 0;
|
|
|
|
}
|
2015-06-05 02:02:31 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
toFolder.messageCountAll(toFolder.messageCountAll() + uidForRemove.length);
|
|
|
|
if (0 < unseenCount)
|
|
|
|
{
|
|
|
|
toFolder.messageCountUnread(toFolder.messageCountUnread() + unseenCount);
|
|
|
|
}
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
toFolder.actionBlink(true);
|
2015-02-22 06:00:51 +08:00
|
|
|
}
|
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
if (0 < messages.length)
|
|
|
|
{
|
|
|
|
if (copy)
|
|
|
|
{
|
|
|
|
_.each(messages, (item) => {
|
|
|
|
item.checked(false);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.messageListIsNotCompleted(true);
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
_.each(messages, (item) => {
|
|
|
|
if (currentMessage && currentMessage.hash === item.hash)
|
|
|
|
{
|
|
|
|
currentMessage = null;
|
|
|
|
this.message(null);
|
|
|
|
}
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
item.deleted(true);
|
2016-06-30 08:02:45 +08:00
|
|
|
});
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
_.delay(() => {
|
|
|
|
_.each(messages, (item) => {
|
|
|
|
this.messageList.remove(item);
|
|
|
|
});
|
|
|
|
}, Magics.Time350ms);
|
|
|
|
}
|
|
|
|
}
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
if ('' !== fromFolderFullNameRaw)
|
|
|
|
{
|
|
|
|
setFolderHash(fromFolderFullNameRaw, '');
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
if ('' !== toFolderFullNameRaw)
|
|
|
|
{
|
|
|
|
setFolderHash(toFolderFullNameRaw, '');
|
|
|
|
}
|
2015-04-22 05:01:29 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
if ('' !== this.messageListThreadUid())
|
2015-04-22 05:01:29 +08:00
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
messageList = this.messageList();
|
2015-04-22 05:01:29 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
if (messageList && 0 < messageList.length &&
|
|
|
|
!!_.find(messageList, (item) => !!(item && item.deleted() && item.uid === this.messageListThreadUid())))
|
2015-04-22 05:01:29 +08:00
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
const message = _.find(messageList, (item) => item && !item.deleted());
|
|
|
|
if (message && this.messageListThreadUid() !== pString(message.uid))
|
2015-04-22 05:01:29 +08:00
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
this.messageListThreadUid(pString(message.uid));
|
2015-04-22 05:01:29 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
setHash(mailBox(
|
2015-04-22 05:01:29 +08:00
|
|
|
FolderStore.currentFolderFullNameHash(),
|
|
|
|
this.messageListPage(),
|
|
|
|
this.messageListSearch(),
|
|
|
|
this.messageListThreadUid()
|
|
|
|
), true, true);
|
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
else if (!message)
|
2015-04-22 05:01:29 +08:00
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
if (1 < this.messageListPage())
|
|
|
|
{
|
|
|
|
this.messageListPage(this.messageListPage() - 1);
|
|
|
|
|
|
|
|
setHash(mailBox(
|
|
|
|
FolderStore.currentFolderFullNameHash(),
|
|
|
|
this.messageListPage(),
|
|
|
|
this.messageListSearch(),
|
|
|
|
this.messageListThreadUid()
|
|
|
|
), true, true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.messageListThreadUid('');
|
2015-04-22 05:01:29 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
setHash(mailBox(
|
|
|
|
FolderStore.currentFolderFullNameHash(),
|
|
|
|
this.messageListPageBeforeThread(),
|
|
|
|
this.messageListSearch()
|
|
|
|
), true, true);
|
|
|
|
}
|
2015-04-22 05:01:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
/**
|
|
|
|
* @param {Object} messageTextBody
|
|
|
|
*/
|
|
|
|
initBlockquoteSwitcher(messageTextBody) {
|
|
|
|
if (messageTextBody)
|
2015-04-07 03:32:19 +08:00
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
const $oList = $('blockquote:not(.rl-bq-switcher)', messageTextBody).filter(function() {
|
|
|
|
return 0 === $(this).parent().closest('blockquote', messageTextBody).length; // eslint-disable-line no-invalid-this
|
|
|
|
});
|
|
|
|
|
|
|
|
if ($oList && 0 < $oList.length)
|
|
|
|
{
|
|
|
|
$oList.each(function() {
|
|
|
|
const $this = $(this); // eslint-disable-line no-invalid-this
|
2016-10-26 06:10:36 +08:00
|
|
|
|
|
|
|
let h = $this.height();
|
|
|
|
if (0 === h)
|
|
|
|
{
|
|
|
|
h = getRealHeight($this);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ('' !== trim($this.text()) && (0 === h || 100 < h))
|
2016-08-17 06:01:20 +08:00
|
|
|
{
|
|
|
|
$this.addClass('rl-bq-switcher hidden-bq');
|
|
|
|
$('<span class="rlBlockquoteSwitcher"><i class="icon-ellipsis" /></span>')
|
|
|
|
.insertBefore($this)
|
|
|
|
.on('click.rlBlockquoteSwitcher', () => {
|
|
|
|
$this.toggleClass('hidden-bq');
|
|
|
|
windowResize();
|
|
|
|
})
|
|
|
|
.after('<br />')
|
|
|
|
.before('<br />');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-04-07 03:32:19 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
/**
|
2016-12-15 05:56:17 +08:00
|
|
|
* @param {Object} messageTextBody
|
|
|
|
* @param {Object} message
|
2016-08-17 06:01:20 +08:00
|
|
|
*/
|
2016-12-15 05:56:17 +08:00
|
|
|
initOpenPgpControls(messageTextBody, message) {
|
|
|
|
if (messageTextBody && messageTextBody.find)
|
2016-08-17 06:01:20 +08:00
|
|
|
{
|
2016-12-15 05:56:17 +08:00
|
|
|
messageTextBody.find('.b-plain-openpgp:not(.inited)').each(function() {
|
|
|
|
PgpStore.initMessageBodyControls($(this), message); // eslint-disable-line no-invalid-this
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2015-04-07 03:32:19 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
setMessage(data, cached) {
|
|
|
|
|
|
|
|
let
|
|
|
|
isNew = false,
|
|
|
|
body = null,
|
|
|
|
id = '',
|
|
|
|
plain = '',
|
|
|
|
resultHtml = '',
|
|
|
|
pgpSigned = false,
|
|
|
|
messagesDom = this.messagesBodiesDom(),
|
|
|
|
selectedMessage = this.selectorMessageSelected(),
|
|
|
|
message = this.message();
|
|
|
|
|
|
|
|
if (data && message && data.Result && 'Object/Message' === data.Result['@Object'] &&
|
|
|
|
message.folderFullNameRaw === data.Result.Folder)
|
2015-02-22 06:00:51 +08:00
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
const threads = message.threads();
|
|
|
|
if (message.uid !== data.Result.Uid && 1 < threads.length && -1 < inArray(data.Result.Uid, threads))
|
2015-02-22 06:00:51 +08:00
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
message = MessageModel.newInstanceFromJson(data.Result);
|
|
|
|
if (message)
|
|
|
|
{
|
|
|
|
message.threads(threads);
|
|
|
|
initMessageFlagsFromCache(message);
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.message(this.staticMessage.populateByMessageListItem(message));
|
|
|
|
message = this.message();
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
isNew = true;
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
if (message && message.uid === data.Result.Uid)
|
2016-06-30 08:02:45 +08:00
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
this.messageError('');
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
message.initUpdateByMessageJson(data.Result);
|
|
|
|
addRequestedMessage(message.folderFullNameRaw, message.uid);
|
2015-03-06 08:42:40 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
if (!cached)
|
2015-03-06 08:42:40 +08:00
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
message.initFlagsByJson(data.Result);
|
|
|
|
}
|
2015-03-06 08:42:40 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
messagesDom = messagesDom && messagesDom[0] ? messagesDom : null;
|
|
|
|
if (messagesDom)
|
|
|
|
{
|
|
|
|
id = 'rl-mgs-' + message.hash.replace(/[^a-zA-Z0-9]/g, '');
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
const textBody = messagesDom.find('#' + id);
|
|
|
|
if (!textBody || !textBody[0])
|
|
|
|
{
|
|
|
|
let isHtml = false;
|
|
|
|
if (isNormal(data.Result.Html) && '' !== data.Result.Html)
|
|
|
|
{
|
|
|
|
isHtml = true;
|
|
|
|
resultHtml = data.Result.Html.toString();
|
|
|
|
}
|
|
|
|
else if (isNormal(data.Result.Plain) && '' !== data.Result.Plain)
|
|
|
|
{
|
|
|
|
isHtml = false;
|
|
|
|
resultHtml = plainToHtml(data.Result.Plain.toString(), false);
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-09-13 04:50:21 +08:00
|
|
|
if ((message.isPgpSigned() || message.isPgpEncrypted()) && PgpStore.capaOpenPGP())
|
2016-06-30 08:02:45 +08:00
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
plain = pString(data.Result.Plain);
|
|
|
|
|
|
|
|
const isPgpEncrypted = (/---BEGIN PGP MESSAGE---/).test(plain);
|
|
|
|
if (!isPgpEncrypted)
|
|
|
|
{
|
|
|
|
pgpSigned = (/-----BEGIN PGP SIGNED MESSAGE-----/).test(plain) &&
|
|
|
|
(/-----BEGIN PGP SIGNATURE-----/).test(plain);
|
|
|
|
}
|
|
|
|
|
|
|
|
$div.empty();
|
|
|
|
if (pgpSigned && message.isPgpSigned())
|
|
|
|
{
|
|
|
|
resultHtml = $div.append(
|
|
|
|
$('<pre class="b-plain-openpgp signed"></pre>').text(plain)
|
2016-06-30 08:02:45 +08:00
|
|
|
).html();
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
|
|
|
else if (isPgpEncrypted && message.isPgpEncrypted())
|
|
|
|
{
|
|
|
|
resultHtml = $div.append(
|
|
|
|
$('<pre class="b-plain-openpgp encrypted"></pre>').text(plain)
|
2016-06-30 08:02:45 +08:00
|
|
|
).html();
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
resultHtml = '<pre>' + resultHtml + '</pre>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$div.empty();
|
|
|
|
|
|
|
|
message.isPgpSigned(pgpSigned);
|
|
|
|
message.isPgpEncrypted(isPgpEncrypted);
|
2015-02-22 06:00:51 +08:00
|
|
|
}
|
2015-07-30 01:21:24 +08:00
|
|
|
else
|
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
resultHtml = '<pre>' + resultHtml + '</pre>';
|
2015-07-30 01:21:24 +08:00
|
|
|
}
|
2015-03-06 08:42:40 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
isHtml = false;
|
|
|
|
resultHtml = '<pre>' + resultHtml + '</pre>';
|
2015-03-06 08:42:40 +08:00
|
|
|
}
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
GlobalsData.iMessageBodyCacheCount += 1;
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
body = $('<div id="' + id + '" ></div>').hide().addClass('rl-cache-class');
|
|
|
|
body.data('rl-cache-count', GlobalsData.iMessageBodyCacheCount);
|
2015-03-06 08:42:40 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
body
|
|
|
|
.html(findEmailAndLinks(resultHtml))
|
|
|
|
.addClass('b-text-part ' + (isHtml ? 'html' : 'plain'));
|
2015-03-06 08:42:40 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
message.isHtml(!!isHtml);
|
|
|
|
message.hasImages(!!data.Result.HasExternals);
|
2015-03-06 08:42:40 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
message.body = body;
|
|
|
|
if (message.body)
|
|
|
|
{
|
|
|
|
messagesDom.append(message.body);
|
|
|
|
}
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
message.storeDataInDom();
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
if (data.Result.HasInternals)
|
|
|
|
{
|
|
|
|
message.showInternalImages(true);
|
|
|
|
}
|
2015-06-23 05:33:27 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
if (message.hasImages() && SettingsStore.showImages())
|
|
|
|
{
|
|
|
|
message.showExternalImages(true);
|
|
|
|
}
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.purgeMessageBodyCacheThrottle();
|
|
|
|
}
|
|
|
|
else
|
2016-06-30 08:02:45 +08:00
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
message.body = textBody;
|
|
|
|
if (message.body)
|
|
|
|
{
|
|
|
|
GlobalsData.iMessageBodyCacheCount += 1;
|
|
|
|
message.body.data('rl-cache-count', GlobalsData.iMessageBodyCacheCount);
|
|
|
|
message.fetchDataFromDom();
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.messageActiveDom(message.body);
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.hideMessageBodies();
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
if (body)
|
|
|
|
{
|
|
|
|
this.initOpenPgpControls(body, message);
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.initBlockquoteSwitcher(body);
|
|
|
|
}
|
2015-03-06 08:42:40 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
message.body.show();
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
initMessageFlagsFromCache(message);
|
|
|
|
if (message.unseen() || message.hasUnseenSubMessage())
|
2016-06-30 08:02:45 +08:00
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
getApp().messageListAction(
|
2016-12-15 05:56:17 +08:00
|
|
|
message.folderFullNameRaw, MessageSetAction.SetSeen, [message]);
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
|
|
|
|
if (isNew)
|
2016-06-30 08:02:45 +08:00
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
message = this.message();
|
2015-03-06 08:42:40 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
if (selectedMessage && message && (
|
|
|
|
message.folderFullNameRaw !== selectedMessage.folderFullNameRaw ||
|
|
|
|
message.uid !== selectedMessage.uid
|
|
|
|
))
|
|
|
|
{
|
|
|
|
this.selectorMessageSelected(null);
|
|
|
|
if (1 === this.messageList().length)
|
|
|
|
{
|
|
|
|
this.selectorMessageFocused(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!selectedMessage && message)
|
2016-06-30 08:02:45 +08:00
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
selectedMessage = _.find(this.messageList(),
|
|
|
|
(subMessage) => subMessage &&
|
|
|
|
subMessage.folderFullNameRaw === message.folderFullNameRaw &&
|
|
|
|
subMessage.uid === message.uid
|
|
|
|
);
|
|
|
|
|
|
|
|
if (selectedMessage)
|
|
|
|
{
|
|
|
|
this.selectorMessageSelected(selectedMessage);
|
|
|
|
this.selectorMessageFocused(selectedMessage);
|
|
|
|
}
|
2015-02-22 06:00:51 +08:00
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2015-02-22 06:00:51 +08:00
|
|
|
}
|
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
windowResize();
|
2015-03-06 08:42:40 +08:00
|
|
|
}
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
selectMessage(oMessage) {
|
|
|
|
if (oMessage)
|
|
|
|
{
|
|
|
|
this.message(this.staticMessage.populateByMessageListItem(oMessage));
|
|
|
|
this.populateMessageBody(this.message());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.message(null);
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2015-03-06 08:42:40 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
selectMessageByFolderAndUid(sFolder, sUid) {
|
|
|
|
if (sFolder && sUid)
|
|
|
|
{
|
|
|
|
this.message(this.staticMessage.populateByMessageListItem(null));
|
|
|
|
this.message().folderFullNameRaw = sFolder;
|
|
|
|
this.message().uid = sUid;
|
2015-07-07 02:46:44 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.populateMessageBody(this.message());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.message(null);
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2015-07-07 02:46:44 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
populateMessageBody(oMessage) {
|
|
|
|
if (oMessage)
|
2015-03-06 08:42:40 +08:00
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
if (Remote.message(this.onMessageResponse, oMessage.folderFullNameRaw, oMessage.uid))
|
|
|
|
{
|
|
|
|
this.messageCurrentLoading(true);
|
|
|
|
}
|
2015-03-06 08:42:40 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
/**
|
|
|
|
* @param {string} sResult
|
|
|
|
* @param {AjaxJsonDefaultResponse} oData
|
|
|
|
* @param {boolean} bCached
|
|
|
|
*/
|
|
|
|
onMessageResponse(sResult, oData, bCached) {
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.hideMessageBodies();
|
|
|
|
|
|
|
|
this.messageCurrentLoading(false);
|
|
|
|
|
|
|
|
if (StorageResultType.Success === sResult && oData && oData.Result)
|
|
|
|
{
|
|
|
|
this.setMessage(oData, bCached);
|
|
|
|
}
|
|
|
|
else if (StorageResultType.Unload === sResult)
|
|
|
|
{
|
|
|
|
this.message(null);
|
|
|
|
this.messageError('');
|
|
|
|
}
|
|
|
|
else if (StorageResultType.Abort !== sResult)
|
|
|
|
{
|
|
|
|
this.message(null);
|
|
|
|
this.messageError((oData && oData.ErrorCode ?
|
|
|
|
getNotification(oData.ErrorCode) : getNotification(Notification.UnknownError)));
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
/**
|
2016-12-15 05:56:17 +08:00
|
|
|
* @param {Array} list
|
2016-08-17 06:01:20 +08:00
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
calculateMessageListHash(list) {
|
|
|
|
return _.map(list, (message) => '' + message.hash + '_' + message.threadsLen() + '_' + message.flagHash()).join('|');
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
setMessageList(data, cached) {
|
|
|
|
if (data && data.Result && 'Collection/MessageCollection' === data.Result['@Object'] &&
|
|
|
|
data.Result['@Collection'] && isArray(data.Result['@Collection']))
|
2016-06-30 08:02:45 +08:00
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
let
|
|
|
|
newCount = 0,
|
|
|
|
unreadCountChange = false;
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
const
|
|
|
|
list = [],
|
2016-09-13 04:50:21 +08:00
|
|
|
utc = momentNowUnix(),
|
2016-08-17 06:01:20 +08:00
|
|
|
iCount = pInt(data.Result.MessageResultCount),
|
|
|
|
iOffset = pInt(data.Result.Offset);
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
const folder = getFolderFromCacheList(isNormal(data.Result.Folder) ? data.Result.Folder : '');
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
if (folder && !cached)
|
2015-02-22 06:00:51 +08:00
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
folder.interval = utc;
|
|
|
|
|
|
|
|
setFolderHash(data.Result.Folder, data.Result.FolderHash);
|
|
|
|
|
|
|
|
if (isNormal(data.Result.MessageCount))
|
2016-06-30 08:02:45 +08:00
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
folder.messageCountAll(data.Result.MessageCount);
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
if (isNormal(data.Result.MessageUnseenCount))
|
|
|
|
{
|
|
|
|
if (pInt(folder.messageCountUnread()) !== pInt(data.Result.MessageUnseenCount))
|
|
|
|
{
|
|
|
|
unreadCountChange = true;
|
|
|
|
}
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
folder.messageCountUnread(data.Result.MessageUnseenCount);
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.initUidNextAndNewMessages(folder.fullNameRaw, data.Result.UidNext, data.Result.NewMessages);
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
if (unreadCountChange && folder)
|
2015-02-22 06:00:51 +08:00
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
clearMessageFlagsFromCacheByFolder(folder.fullNameRaw);
|
|
|
|
}
|
|
|
|
|
|
|
|
_.each(data.Result['@Collection'], (jsonMessage) => {
|
|
|
|
if (jsonMessage && 'Object/Message' === jsonMessage['@Object'])
|
2015-02-22 06:00:51 +08:00
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
const message = MessageModel.newInstanceFromJson(jsonMessage);
|
|
|
|
if (message)
|
2015-02-22 06:00:51 +08:00
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
if (hasNewMessageAndRemoveFromCache(message.folderFullNameRaw, message.uid) && 5 >= newCount)
|
|
|
|
{
|
|
|
|
newCount += 1;
|
|
|
|
message.newForAnimation(true);
|
|
|
|
}
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
message.deleted(false);
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
if (cached)
|
|
|
|
{
|
|
|
|
initMessageFlagsFromCache(message);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
storeMessageFlagsToCache(message);
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
list.push(message);
|
|
|
|
}
|
2015-02-22 06:00:51 +08:00
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.messageListCount(iCount);
|
|
|
|
this.messageListSearch(isNormal(data.Result.Search) ? data.Result.Search : '');
|
|
|
|
this.messageListPage(window.Math.ceil((iOffset / SettingsStore.messagesPerPage()) + 1));
|
|
|
|
this.messageListThreadUid(isNormal(data.Result.ThreadUid) ? pString(data.Result.ThreadUid) : '');
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.messageListEndFolder(isNormal(data.Result.Folder) ? data.Result.Folder : '');
|
|
|
|
this.messageListEndSearch(this.messageListSearch());
|
|
|
|
this.messageListEndThreadUid(this.messageListThreadUid());
|
|
|
|
this.messageListEndPage(this.messageListPage());
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.messageListDisableAutoSelect(true);
|
2015-03-06 08:42:40 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.messageList(list);
|
|
|
|
this.messageListIsNotCompleted(false);
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
clearNewMessageCache();
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
if (folder && (cached || unreadCountChange || SettingsStore.useThreads()))
|
|
|
|
{
|
|
|
|
getApp().folderInformation(folder.fullNameRaw, list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2015-02-22 06:00:51 +08:00
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
this.messageListCount(0);
|
|
|
|
this.messageList([]);
|
|
|
|
this.messageListError(getNotification(
|
|
|
|
data && data.ErrorCode ? data.ErrorCode : Notification.CantGetMessageList
|
|
|
|
));
|
2015-02-22 06:00:51 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-09-13 04:50:21 +08:00
|
|
|
export default new MessageUserStore();
|