This commit is contained in:
janisslsm committed 2026-11-01 12:12:55 +02:00
1 parent 1781d25a15
commit 732c0ad767
33051 files changed
+2591613 -3019689

No files matched your search

@@ -0,0 +1,59 @@
// Metro module 7854 (f7855).
import { setYear, isSameDay, differenceInDays, differenceInMonths } from "../../../../_bundle/Module3414";
export const FRIEND_ANNIVERSARY_ELIGIBILITY_WINDOW_DAYS = 7;
export function isFriendAnniversary(a0) {
const date = new Date();
const fullYear = date.getFullYear();
for (const item of [-1, 0, 1]) {
const r36 = setYear(a0, fullYear + item);
if (isSameDay(r36, a0)) {
continue;
}
if (!(Math.abs(differenceInDays(date, r36)) <= 7)) {
continue;
}
return true;
}
return false;
}
export function yearsSince(a0) {
return Math.round(differenceInMonths(new Date(), a0) / 12);
}
export function categorizeFriendAnniversariesByAffinity(a0, a1, a2) {
const set = new Set();
let c16043_0 = set;
const set2 = new Set();
let c16043_1 = set2;
if (a2) {
a0.slice(0, Math.ceil(a0.length / 2)).forEach((item) => {
c16043_0.add(item);
});
a0.forEach((item) => {
c16043_1.add(item);
});
} else {
for (const item of a0) {
const r39 = a1(item);
if (r39 != null && r39 > 0.7) {
set.add(item);
}
if (r39 != null && r39 > 0.5) {
set2.add(item);
}
}
}
return {
highestAffinity: set,
highAffinity: set2
};
}
export function pruneTimestampMap(a0, a1, a2) {
const r2 = {};
for (const key in a0) {
const r9 = a0[key];
if (a1 - r9 <= a2) {
r2[key] = r9;
}
}
return r2;
}
@@ -0,0 +1,141 @@
// Metro module 16301 (f16302).
import EphemeralMessageStore from "../../../messages/EphemeralMessageStore";
import UserSettingsProtoStore from "../../../user_settings/UserSettingsProtoStore";
import ChannelStore from "../../../../stores/ChannelStore";
import PremiumGiftingIntentStore from "../PremiumGiftingIntentStore";
import { MessageTypes } from "../../../../Constants";
import Durations from "../../../../utils/Durations";
import AutomaticLifecycleManager from "../../../../lib/AutomaticLifecycleManager";
import Backoff from "../../../../_bundle/Backoff";
import { FriendshipAnniversaryBackendPersistenceExperiment } from "../../experiments/FriendshipAnniversaryBackendPersistenceExperiment";
import { fetchAndReconcileGiftIntentDismissals } from "../PremiumGiftingIntentActionCreators";
import Dispatcher from "../../../../Dispatcher";
import MessageActionCreators from "../../../../actions/MessageActionCreators";
let c11720_8 = 10 * Durations.Millis.SECOND;
let c11720_9 = 5 * Durations.Millis.MINUTE;
class GiftIntentReconcilingManager extends AutomaticLifecycleManager {
actions = {
POST_CONNECTION_OPEN: () => this.onPostConnectionOpen(),
CHANNEL_SELECT: (a0) => this.onChannelSelect(a0),
GIFT_INTENT_DISMISSALS_FETCH_SUCCESS: (a0) => this.onReconcileSuccess(a0),
GIFT_INTENT_DISMISSALS_FETCH_FAILURE: () => this.onReconcileSettled(false),
LOGOUT: () => this.onLogout()
};
stores = new Map([[PremiumGiftingIntentStore, () => this.onPremiumGiftingIntentStoreChange()]]);
reconcileBackoff = new Backoff(c11720_8, c11720_9);
isReconciling = false;
heldGiftingPromptSystemMessage = false;
lastReconciledDismissalAtMs = new Map();
retryReconcileServerDismissals = () => {
if (this.isReconcileEligible("retryReconcileServerDismissals")) {
this.attemptReconcileFetch();
}
};
onPostConnectionOpen() {
this.lastReconciledDismissalAtMs.clear();
this.sendGiftingPromptSystemMessagesIfEligible();
}
onPremiumGiftingIntentStoreChange() {
this.maybeReconcileServerDismissals();
this.maybeRetryHeldGiftingPromptSystemMessage();
}
maybeReconcileServerDismissals() {
if (this.isReconcileEligible("maybeReconcileServerDismissals") && !this.reconcileBackoff.pending) {
this.attemptReconcileFetch();
}
}
isReconcileEligible(a0) {
return PremiumGiftingIntentStore.getFriendAnniversaries().length !== 0 && FriendshipAnniversaryBackendPersistenceExperiment.getConfig({
location: a0
}).enabled;
}
getServerDismissalTimestampMs() {
const r4 = Number;
let r9 = UserSettingsProtoStore.settings.userContent?.lastGiftIntentDismissedAtMs;
if (r9 == null) {
r9 = "0";
}
return r4(r9);
}
attemptReconcileFetch() {
const serverDismissalTimestampMs = this.getServerDismissalTimestampMs();
if (!(PremiumGiftingIntentStore.getLastKnownGiftIntentDismissedAtMs() >= serverDismissalTimestampMs || this.isReconciling)) {
this.isReconciling = true;
fetchAndReconcileGiftIntentDismissals(serverDismissalTimestampMs);
}
}
onReconcileSuccess(a0) {
this.onReconcileSettled(true);
this.removeRemotelyDismissedGiftIntentCards(a0.dismissals);
}
onReconcileSettled(a0) {
this.isReconciling = false;
const reconcileBackoff = this.reconcileBackoff;
if (a0) {
reconcileBackoff.succeed();
} else {
reconcileBackoff.fail(this.retryReconcileServerDismissals);
}
}
removeRemotelyDismissedGiftIntentCards(a0) {
for (const item of a0) {
const { targetId, dismissedAtMs } = item;
const r39 = this.lastReconciledDismissalAtMs.get(targetId);
const lastReconciledDismissalAtMs = this.lastReconciledDismissalAtMs;
const r19 = Math;
let r17 = r39;
if (r17 == null) {
r17 = 0;
}
lastReconciledDismissalAtMs.set(targetId, r19.max(r17, dismissedAtMs));
if (r39 != null && !(dismissedAtMs <= r39)) {
const dMFromUserId = ChannelStore.getDMFromUserId(targetId);
const channelId = dMFromUserId;
if (dMFromUserId != null) {
for (const item2 of EphemeralMessageStore.getMessages(channelId)) {
if (item2.type === MessageTypes.GIFTING_PROMPT && item2.giftingPrompt?.recipientUserId === targetId) {
Dispatcher.dispatch({
type: "MESSAGE_DELETE",
id: item2.id,
channelId
});
}
}
}
}
}
}
onLogout() {
this.reconcileBackoff.cancel();
this.isReconciling = false;
this.heldGiftingPromptSystemMessage = false;
this.lastReconciledDismissalAtMs.clear();
}
maybeRetryHeldGiftingPromptSystemMessage() {
if (this.heldGiftingPromptSystemMessage && !(PremiumGiftingIntentStore.getLastKnownGiftIntentDismissedAtMs() < this.getServerDismissalTimestampMs())) {
this.heldGiftingPromptSystemMessage = false;
this.sendGiftingPromptSystemMessagesIfEligible();
}
}
shouldHoldGiftingPromptSystemMessageForServerReconcile(a0) {
return !!FriendshipAnniversaryBackendPersistenceExperiment.getConfig({
location: a0
}).enabled && PremiumGiftingIntentStore.getLastKnownGiftIntentDismissedAtMs() < this.getServerDismissalTimestampMs();
}
trySendGiftingPromptSystemMessage(a0, a1, a2, a3, a4) {
let r18;
if (this.shouldHoldGiftingPromptSystemMessageForServerReconcile(a4)) {
this.heldGiftingPromptSystemMessage = true;
r18 = false;
} else {
MessageActionCreators.sendGiftingPromptSystemMessage(a0, {
giftIntentType: a1,
recipientUserId: a2,
giftIntentSecondaryAction: a3
});
r18 = true;
}
return r18;
}
}
export default GiftIntentReconcilingManager;