Files
discord-decomp/modules/notifications/friend_online/FriendOnlineTimer.tsx
T
2026-11-01 12:12:55 +02:00

109 lines
3.6 KiB
TypeScript

// Metro module 16647 (f16648).
import SelfPresenceStore from "../../../stores/SelfPresenceStore";
import FriendOnlineTimerStore from "./FriendOnlineTimerStore";
import { Endpoints } from "../../../Constants";
import { StatusTypes } from "../../../_bundle/Module505";
import Durations from "../../../utils/Durations";
import { HTTP, HTTPResponseError } from "../../../_bundle/sendRequest";
import SentryUtils_native from "../../../utils/SentryUtils.native";
import Dispatcher from "../../../Dispatcher";
import AutomaticLifecycleManager from "../../../lib/AutomaticLifecycleManager";
import { NotifyFriendsOnComeOnline } from "../../user_settings/UserSettings";
let c11986_8;
let _reportSessionMeaningfullyOnline = function _reportSessionMeaningfullyOnline() {
const r8 = async () => {
let c28482_2;
let c28482_3 = 0;
let c31089_0;
L10: {
try {
c28482_3 = 1;
await HTTP.post({
url: Endpoints.USER_MEANINGFULLY_ONLINE,
rejectWithError: true
});
c28482_3 = 0;
Dispatcher.dispatch({
type: "FRIEND_ONLINE_TIMER_REPORTED",
timestampMs: Date.now()
});
} catch ($e) {
const r26 = $e;
let r7 = r26;
c28482_2 = r26;
if (c28482_3 !== 0) {
while (true) {
try {
const r71 = c28482_2;
c28482_3 = 0;
c31089_0 = r71;
if (c31089_0 instanceof HTTPResponseError && c31089_0.status === 429) {
Dispatcher.dispatch({
type: "FRIEND_ONLINE_TIMER_REPORTED",
timestampMs: Date.now()
});
break L10;
}
SentryUtils_native.captureException(c31089_0, {
tags: {
app_context: "session_timer"
}
});
} catch (r67) {
r7 = r67;
c28482_2 = r67;
if (c28482_3 === 0) {
break;
}
continue;
}
return void 0;
}
}
throw r7;
}
}
};
_reportSessionMeaningfullyOnline = r8;
return r8.apply(this, arguments);
};
c11986_8 = 5 * Durations.Millis.MINUTE;
class FriendOnlineTimerManager extends AutomaticLifecycleManager {
constructor() {
super(...arguments);
const _this = this;
this.timerId = null;
this.actions = {
POST_CONNECTION_OPEN: () => _this.start(),
CONNECTION_RESUMED: () => _this.start(),
CONNECTION_CLOSED: () => _this.clear(),
CONNECTION_INTERRUPTED: () => _this.clear(),
SELF_PRESENCE_STORE_UPDATE: () => _this.start()
};
this.start = () => {
if (NotifyFriendsOnComeOnline.getSetting() && FriendOnlineTimerStore.isCooldownElapsed() && _this.timerId == null && [StatusTypes.ONLINE, StatusTypes.STREAMING].includes(SelfPresenceStore.getStatus())) {
_this.timerId = setTimeout(() => {
_this.timerId = null;
if ([StatusTypes.ONLINE, StatusTypes.STREAMING].includes(SelfPresenceStore.getStatus()) && FriendOnlineTimerStore.isCooldownElapsed()) {
(function reportSessionMeaningfullyOnline() {
return _reportSessionMeaningfullyOnline.apply(this, arguments);
})();
}
}, c11986_8);
}
};
this.clear = () => {
if (_this.timerId != null) {
clearTimeout(_this.timerId);
_this.timerId = null;
}
};
}
_initialize() {}
_terminate() {
this.clear();
}
}
const friendOnlineTimerManager = new FriendOnlineTimerManager();
export default friendOnlineTimerManager;