snappymail/dev/Stores/User/Message.js

55 lines
1.4 KiB
JavaScript
Raw Normal View History

import { Scope } from 'Common/Enums';
2022-03-22 23:24:58 +08:00
import { elementById } from 'Common/Globals';
import { exitFullscreen } from 'Common/Fullscreen';
import { addObservablesTo, addSubscribablesTo } from 'External/ko';
import { AppUserStore } from 'Stores/User/App';
import { SettingsUserStore } from 'Stores/User/Settings';
export const MessageUserStore = new class {
2019-07-05 03:19:24 +08:00
constructor() {
addObservablesTo(this, {
2020-10-27 18:09:24 +08:00
// message viewer
message: null,
error: '',
loading: false,
2015-02-22 06:00:51 +08:00
// Cache mail bodies
bodiesDom: null
2020-10-27 18:09:24 +08:00
});
2015-02-22 06:00:51 +08:00
2021-03-12 23:54:37 +08:00
// Subscribers
2021-03-16 18:38:40 +08:00
addSubscribablesTo(this, {
message: message => {
clearTimeout(this.MessageSeenTimer);
elementById('rl-right').classList.toggle('message-selected', !!message);
2021-03-16 18:38:40 +08:00
if (message) {
2022-10-10 19:52:56 +08:00
SettingsUserStore.usePreviewPane() || AppUserStore.focusedState(Scope.MessageView);
2021-03-16 18:38:40 +08:00
} else {
AppUserStore.focusedState(Scope.MessageList);
2022-03-22 18:47:17 +08:00
exitFullscreen();
2021-03-16 18:38:40 +08:00
}
this.hideMessageBodies();
2021-03-16 18:38:40 +08:00
},
});
2021-03-12 23:54:37 +08:00
2021-07-19 17:57:47 +08:00
this.purgeMessageBodyCache = this.purgeMessageBodyCache.throttle(30000);
}
2015-02-22 06:00:51 +08:00
purgeMessageBodyCache() {
const messagesDom = this.bodiesDom(),
2022-09-02 17:52:07 +08:00
children = messagesDom?.children;
if (children) {
while (15 < children.length) {
children[0].remove();
2015-02-22 06:00:51 +08:00
}
}
2016-06-30 08:02:45 +08:00
}
2015-02-22 06:00:51 +08:00
hideMessageBodies() {
const messagesDom = this.bodiesDom();
messagesDom && Array.from(messagesDom.children).forEach(el => el.hidden = true);
}
};