77 lines
3.4 KiB
TypeScript
77 lines
3.4 KiB
TypeScript
// Metro module 16300 (f16301).
|
|
import UserAffinitiesV2Store from "../../../user_affinities/UserAffinitiesV2Store";
|
|
import ChannelStore from "../../../../stores/ChannelStore";
|
|
import MessageStore from "../../../../stores/MessageStore";
|
|
import SelectedChannelStore from "../../../../stores/SelectedChannelStore";
|
|
import PremiumGiftingIntentStore from "../PremiumGiftingIntentStore";
|
|
import { GiftIntentSecondaryAction, GiftIntentType } from "../../PremiumConstants";
|
|
import GiftIntentReconcilingManager from "../shared/GiftIntentReconcilingManager";
|
|
import { ChannelTypes } from "../../../../_bundle/Module692";
|
|
import { EnableFriendAnniversaryNotifications } from "../../../user_settings/UserSettings";
|
|
import { logMessageGiftIntentShown } from "../PremiumGiftingIntentActionCreators";
|
|
import { trackImpression } from "../../../app_analytics/useTrackImpression";
|
|
import { ImpressionNames, ImpressionTypes } from "../../../../_bundle/Module503";
|
|
import { DelayedCall } from "../../../../_bundle/Timeout";
|
|
import MobileFriendAnniversaryExperiment from "./MobileFriendAnniversaryExperiment";
|
|
import { fetchUserAffinitiesV2 } from "../../../user_affinities/UserAffinitiesActionCreators";
|
|
class MobileGiftIntentCardManager extends GiftIntentReconcilingManager {
|
|
isChannelEligible(a0) {
|
|
return a0.type === ChannelTypes.DM;
|
|
}
|
|
maybeSendCard(a0, a1) {
|
|
if (EnableFriendAnniversaryNotifications.getSetting() && !PremiumGiftingIntentStore.isGiftIntentMessageInCooldown(a1) && a0 === SelectedChannelStore.getChannelId()) {
|
|
if (MessageStore.isReady(a0)) {
|
|
if (this.trySendGiftingPromptSystemMessage(a0, GiftIntentType.FRIEND_ANNIVERSARY, a1, GiftIntentSecondaryAction.SEND_MESSAGE, "maybeSendCard")) {
|
|
logMessageGiftIntentShown(a1);
|
|
trackImpression({
|
|
name: ImpressionNames.GIFT_INTENT_UNREAD_NOTIFICATION,
|
|
type: ImpressionTypes.VIEW,
|
|
properties: {
|
|
gift_intent_type: GiftIntentType.FRIEND_ANNIVERSARY,
|
|
dm_affinity: UserAffinitiesV2Store.getUserAffinity(a1)?.dmProbability,
|
|
channel_id: a0
|
|
}
|
|
});
|
|
}
|
|
} else {
|
|
MessageStore.whenReady(a0, () => {
|
|
const channelId = SelectedChannelStore.getChannelId();
|
|
if (channelId === a0) {
|
|
this.maybeSendCard(a0, a1);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|
|
sendCardInSelectedChannelIfEligible(a0) {
|
|
let c22957_0, c22957_2;
|
|
const channel = ChannelStore.getChannel(a0);
|
|
if (channel != null && this.isChannelEligible(channel)) {
|
|
c22957_2 = new Set(channel.recipients);
|
|
const r24 = PremiumGiftingIntentStore.getFriendAnniversaries().find((item) => c22957_2.has(item));
|
|
c22957_0 = r24;
|
|
if (r24 != null) {
|
|
new DelayedCall(1000, () => {
|
|
this.maybeSendCard(channel.id, c22957_0);
|
|
}).delay();
|
|
}
|
|
}
|
|
}
|
|
maybeFetchUserAffinities() {
|
|
if (MobileFriendAnniversaryExperiment.getConfig({
|
|
location: "MobileGiftIntentCardManager"
|
|
}).enabled) {
|
|
fetchUserAffinitiesV2();
|
|
}
|
|
}
|
|
onChannelSelect(a0) {
|
|
this.sendCardInSelectedChannelIfEligible(a0.channelId);
|
|
}
|
|
sendGiftingPromptSystemMessagesIfEligible() {
|
|
this.maybeFetchUserAffinities();
|
|
this.sendCardInSelectedChannelIfEligible(SelectedChannelStore.getChannelId());
|
|
}
|
|
}
|
|
const mobileGiftIntentCardManager = new MobileGiftIntentCardManager();
|
|
export default mobileGiftIntentCardManager;
|