Files
discord-decomp/modules/notification_center/NotificationCenterStore.tsx
T
2026-11-01 12:12:55 +02:00

103 lines
2.9 KiB
TypeScript

// Metro module 15282 (f15283).
import RecentMentionsStore from "../inbox/RecentMentionsStore";
import Durations from "../../utils/Durations";
import Module589 from "../../_bundle/Module589";
import { NotificationCenterTabs } from "./NotificationCenterItemsTypes";
import SnowflakeUtils from "../../utils/SnowflakeUtils";
import Dispatcher from "../../Dispatcher";
let c10859_5, c10859_6;
const handleLoadFinished = function handleLoadFinished() {
c10859_6.hasNewMentions = false;
c10859_6.isDataStale = false;
c10859_6.isRefreshing = false;
};
c10859_5 = 90 * Durations.Millis.DAY;
c10859_6 = {
tab: null,
localItemAcks: {},
hasNewMentions: false,
isDataStale: false,
isRefreshing: false
};
class NotificationCenterStore extends Module589.PersistedStore {
static displayName = "NotificationCenterStore";
static persistKey = "NotificationCenterStore";
initialize(a0) {
this.waitFor(RecentMentionsStore);
if (a0 != null) {
c10859_6 = a0;
let localItemAcks = a0.localItemAcks;
if (localItemAcks == null) {
localItemAcks = {};
}
a0.localItemAcks = (function purge(a0) {
const r0 = {};
for (const item of Object.entries(a0)) {
const [r32, r33] = item;
if (Date.now() - r33 < c10859_5) {
r0[r32] = r33;
}
}
return r0;
})(localItemAcks);
c10859_6.isDataStale = true;
}
}
getState() {
return c10859_6;
}
getTab() {
let tab = c10859_6.tab;
if (tab == null) {
tab = NotificationCenterTabs.ForYou;
}
return tab;
}
isLocalItemAcked(a0) {
return a0.local_id != null && (c10859_6.localItemAcks[a0.local_id] != null || SnowflakeUtils.age(a0.id) > c10859_5);
}
hasNewMentions() {
return c10859_6.hasNewMentions;
}
isDataStale() {
return c10859_6.isDataStale;
}
isRefreshing() {
return c10859_6.isRefreshing;
}
shouldReload() {
return c10859_6.hasNewMentions || c10859_6.isDataStale || c10859_6.isRefreshing;
}
}
const notificationCenterStore = new NotificationCenterStore(Dispatcher, {
MESSAGE_CREATE: function handleMessageCreate(a0) {
if (RecentMentionsStore.hasMention(a0.message.id)) {
c10859_6.hasNewMentions = true;
}
},
NOTIFICATION_CENTER_SET_TAB: function handleSetTab(a0) {
c10859_6 = {
...c10859_6,
tab: a0.tab
};
},
NOTIFICATION_CENTER_ITEMS_LOCAL_ACK: function handleAck(a0) {
a0.localIds.forEach((localId) => {
const localItemAcks = {
...c10859_6.localItemAcks
};
localItemAcks[localId] = Date.now();
c10859_6 = {
...c10859_6,
localItemAcks
};
});
},
NOTIFICATION_CENTER_REFRESH: function handleRefreshData() {
c10859_6.isRefreshing = true;
},
LOAD_NOTIFICATION_CENTER_ITEMS_FAILURE: handleLoadFinished,
LOAD_NOTIFICATION_CENTER_ITEMS_SUCCESS: handleLoadFinished
});
export default notificationCenterStore;