2022-02-24 02:26:52 +08:00
|
|
|
import { Scope } from 'Common/Enums';
|
2022-03-22 23:24:58 +08:00
|
|
|
import { elementById } from 'Common/Globals';
|
|
|
|
import { exitFullscreen } from 'Common/Fullscreen';
|
2022-02-24 02:26:52 +08:00
|
|
|
import { addObservablesTo, addSubscribablesTo } from 'External/ko';
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2021-03-11 05:41:35 +08:00
|
|
|
import { AppUserStore } from 'Stores/User/App';
|
|
|
|
import { SettingsUserStore } from 'Stores/User/Settings';
|
2021-07-26 16:15:50 +08:00
|
|
|
|
2021-03-11 05:41:35 +08:00
|
|
|
export const MessageUserStore = new class {
|
2019-07-05 03:19:24 +08:00
|
|
|
constructor() {
|
2021-03-16 17:59:47 +08:00
|
|
|
addObservablesTo(this, {
|
2020-10-27 18:09:24 +08:00
|
|
|
// message viewer
|
|
|
|
message: null,
|
2022-02-24 02:26:52 +08:00
|
|
|
error: '',
|
|
|
|
loading: false,
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2021-02-10 23:50:58 +08:00
|
|
|
// Cache mail bodies
|
2022-10-28 19:57:13 +08:00
|
|
|
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-02-10 19:12:36 +08:00
|
|
|
|
2021-03-16 18:38:40 +08:00
|
|
|
addSubscribablesTo(this, {
|
|
|
|
message: message => {
|
2022-02-24 02:26:52 +08:00
|
|
|
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 {
|
2021-03-16 23:06:16 +08:00
|
|
|
AppUserStore.focusedState(Scope.MessageList);
|
2022-03-22 18:47:17 +08:00
|
|
|
exitFullscreen();
|
2021-03-16 18:38:40 +08:00
|
|
|
}
|
2022-10-28 19:57:13 +08:00
|
|
|
this.hideMessageBodies();
|
2021-03-16 18:38:40 +08:00
|
|
|
},
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
2021-03-12 23:54:37 +08:00
|
|
|
|
2021-07-19 17:57:47 +08:00
|
|
|
this.purgeMessageBodyCache = this.purgeMessageBodyCache.throttle(30000);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2015-02-22 06:00:51 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
purgeMessageBodyCache() {
|
2022-02-24 02:26:52 +08:00
|
|
|
const messagesDom = this.bodiesDom(),
|
2022-09-02 17:52:07 +08:00
|
|
|
children = messagesDom?.children;
|
2021-02-10 23:50:58 +08:00
|
|
|
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
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
hideMessageBodies() {
|
2022-02-24 02:26:52 +08:00
|
|
|
const messagesDom = this.bodiesDom();
|
2021-02-10 23:50:58 +08:00
|
|
|
messagesDom && Array.from(messagesDom.children).forEach(el => el.hidden = true);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2021-03-11 05:41:35 +08:00
|
|
|
};
|