snappymail/dev/Stores/User/Message.js

51 lines
1.3 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.bodiesDom()?.children || [])].forEach(el => el.hidden = true);
2021-03-16 18:38:40 +08:00
},
});
2021-03-12 23:54:37 +08:00
this.purgeCache = this.purgeCache.throttle(30000);
}
2015-02-22 06:00:51 +08:00
purgeCache(all) {
const children = this.bodiesDom()?.children || [];
let i = Math.max(0, children.length - (all ? 0 : 15));
while (i--) {
children[i].remove();
if (children[i].message) {
children[i].message.body = null;
2015-02-22 06:00:51 +08:00
}
}
2016-06-30 08:02:45 +08:00
}
};