111 lines
2.9 KiB
TypeScript
111 lines
2.9 KiB
TypeScript
// Metro module 6057 (f6058).
|
|
import Durations from "../../utils/Durations";
|
|
import { DelayedCall } from "../../_bundle/Timeout";
|
|
import SnowflakeUtils from "../../utils/SnowflakeUtils";
|
|
import Logger from "../../modules/debug/Logger";
|
|
import Module12 from "../../_bundle/Module12";
|
|
let c3840_3 = 1 * Durations.Millis.MINUTE;
|
|
class GuildMemberSubscriptions {
|
|
_subscriptions = {};
|
|
_unsubscriptions = {};
|
|
_unsubscribe = new DelayedCall(c3840_3, () => this.flushUnsubscriptions());
|
|
constructor(a0) {
|
|
this._onChange = a0;
|
|
}
|
|
reset() {
|
|
this._subscriptions = {};
|
|
this._unsubscriptions = {};
|
|
this._unsubscribe.cancel();
|
|
}
|
|
get(a0) {
|
|
let r3 = this._subscriptions[a0];
|
|
if (r3 == null) {
|
|
r3 = {};
|
|
}
|
|
return SnowflakeUtils.keys(r3);
|
|
}
|
|
clear(a0) {
|
|
delete this._subscriptions[a0];
|
|
delete this._unsubscriptions[a0];
|
|
}
|
|
subscribe(a0, a1) {
|
|
let r7 = this._subscriptions[a0];
|
|
if (r7 == null) {
|
|
r7 = {};
|
|
}
|
|
let r6 = r7[a1];
|
|
if (r6 == null) {
|
|
r6 = 0;
|
|
}
|
|
r7[a1] = r6 + 1;
|
|
this._subscriptions[a0] = r7;
|
|
if (r7[a1] === 1) {
|
|
this._onChange(a0, this.get(a0));
|
|
}
|
|
this.checkForLeaks(a0, a1);
|
|
}
|
|
isSubscribed(a0, a1) {
|
|
return this._subscriptions[a0] != null && this._subscriptions[a0][a1] != null;
|
|
}
|
|
isSubscribedToAnyMember(a0) {
|
|
return this.get(a0).length > 0;
|
|
}
|
|
unsubscribe(a0, a1) {
|
|
if (this.isSubscribed(a0, a1)) {
|
|
let r9 = this._unsubscriptions[a0];
|
|
if (r9 == null) {
|
|
r9 = {};
|
|
}
|
|
let r5 = r9[a1];
|
|
if (r5 == null) {
|
|
r5 = 0;
|
|
}
|
|
r9[a1] = r5 + 1;
|
|
this._unsubscriptions[a0] = r9;
|
|
if (r9[a1] === 1) {
|
|
this._unsubscribe.delay(false);
|
|
}
|
|
}
|
|
}
|
|
checkForLeaks(a0, a1) {
|
|
const r8 = this._subscriptions[a0];
|
|
let r13 = r8 == null ? void 0 : r8[a1];
|
|
if (r13 == null) {
|
|
r13 = 0;
|
|
}
|
|
const r15 = this._unsubscriptions[a0];
|
|
let r17 = r15 == null ? void 0 : r15[a1];
|
|
if (r17 == null) {
|
|
r17 = 0;
|
|
}
|
|
const r9 = r13 - r17;
|
|
if (r9 > 5) {
|
|
new Logger("GuildMemberSubscriptions").warn(`GuildMemberSubscriptions.subscribe(...): Potential reference leak! (${r9} subscriptions)`);
|
|
}
|
|
}
|
|
flushUnsubscriptions() {
|
|
if (!Module12.isEmpty(this._unsubscriptions)) {
|
|
Module12.forEach(this._unsubscriptions, (a0, a1) => {
|
|
const r6 = this._subscriptions[a1];
|
|
let c25688_0 = r6;
|
|
Module12.forEach(a0, (a0, a1) => {
|
|
let r5 = c25688_0[a1];
|
|
if (r5 == null) {
|
|
r5 = 0;
|
|
}
|
|
c25688_0[a1] = r5 - a0;
|
|
if (c25688_0[a1] <= 0) {
|
|
delete c25688_0[a1];
|
|
}
|
|
});
|
|
if (Module12.isEmpty(r6)) {
|
|
delete this._subscriptions[a1];
|
|
}
|
|
this._onChange(a1, this.get(a1));
|
|
});
|
|
this._unsubscriptions = {};
|
|
}
|
|
}
|
|
}
|
|
export default GuildMemberSubscriptions;
|