Files
discord-decomp/modules/nuf/native/NotificationPermissionManager.tsx
T
2026-11-01 12:12:55 +02:00

264 lines
11 KiB
TypeScript

// Metro module 16281 (f16282).
import { NativeModules } from "react-native";
import JoinedThreadsStore from "../../threads/JoinedThreadsStore";
import AuthenticationStore from "../../../stores/AuthenticationStore";
import ChannelStore from "../../../stores/ChannelStore";
import UserGuildSettingsStore from "../../../stores/UserGuildSettingsStore";
import PushNotificationPermissionStore, { PermissionPromptType } from "../../../stores/native/PushNotificationPermissionStore";
import { EventActionLocation, NOTIFICATION_REACTIVATION_ACTIONSHEET_KEY } from "./components/notification/NotificationPermissionConstants";
import { AnalyticEvents, GuildFeatures, RelationshipTypes } from "../../../Constants";
import { NotificationAuthorizationStatus } from "../../native_permissions/NativePermissionConstants";
import ActionSheetActionCreators from "../../action_sheet/native/ActionSheetActionCreators";
import { ImpressionNames } from "../../../_bundle/Module503";
import Module3771 from "../../../_bundle/Module3771";
import { setPushPermissionReactivationSeen, updateNotificationAuthorizationStatus, setPushNotificationPermissionEligibleForPrompt } from "../../../actions/native/PushNotificationActionCreators";
import { allowInAppNotifications } from "../../notifications/NotificationTextUtils";
import AnalyticsUtils from "../../../utils/AnalyticsUtils";
import { isIOS } from "../../../utils/PlatformUtils";
import AutomaticLifecycleManager from "../../../lib/AutomaticLifecycleManager";
import ContextualOptInNudgeHoldoutExperiment from "./ContextualOptInNudgeHoldoutExperiment";
import { AppStates } from "../../../ConstantsIOS";
let c11699_17, shouldShowPrompt, shouldShowReactivationPrompt, c11699_23, showPrompt, _logNotificationPermissionStatus;
const haveNotSeenPromptSince = function haveNotSeenPromptSince(a0, a1) {
const r7 = PushNotificationPermissionStore.getState().promptLastSeen[a0];
return r7 == null || (c11699_17.includes(a0) ? Module3771().diff(r7, "days") >= 1 : void 0);
};
shouldShowPrompt = async function shouldShowPrompt(c28318_0) {
let c28318_2;
c28318_2 = void 0;
let c31014_0 = c28318_0;
let c31014_1 = await NativeModules.NativePermissionManager.getNotificationAuthorizationStatus();
return (c31014_1 === NotificationAuthorizationStatus.UNDETERMINED || c31014_1 === NotificationAuthorizationStatus.PROVISIONAL) && (0, haveNotSeenPromptSince)(c31014_0, 1);
};
shouldShowReactivationPrompt = async function shouldShowReactivationPrompt(c28319_0) {
let c28319_2;
c28319_2 = void 0;
let c31015_0 = c28319_0;
return await NativeModules.NativePermissionManager.getNotificationAuthorizationStatus() === NotificationAuthorizationStatus.DENIED && (0, haveNotSeenPromptSince)(c31015_0, 1);
};
showPrompt = function showPrompt(c22941_0, action_location, a2) {
if (c11699_23 != null) {
clearTimeout(c11699_23);
}
c11699_23 = setTimeout(() => {
setPushPermissionReactivationSeen(c22941_0);
ActionSheetActionCreators.openLazy(import("./components/notification/NotificationReactivationActionSheet"), NOTIFICATION_REACTIVATION_ACTIONSHEET_KEY, {
impressionName: ImpressionNames.PUSH_NOTIFICATION_REACTIVATION_PROMPT,
impressionProperties: {
action_location
},
location: action_location
});
}, a2);
};
_logNotificationPermissionStatus = async function _logNotificationPermissionStatus() {
let c28320_1;
c28320_1 = void 0;
let c31016_0 = await NativeModules.NativePermissionManager.getNotificationAuthorizationStatus();
let c31016_1 = allowInAppNotifications();
AnalyticsUtils.track(AnalyticEvents.NOTIFICATION_PERMISSION_STATUS, {
os_enabled: c31016_0 === NotificationAuthorizationStatus.AUTHORIZED,
foreground_app_enabled: c31016_1,
background_app_enabled: c31016_1,
notification_authorization_status: isIOS() ? c31016_0 : null
});
};
c11699_17 = [PermissionPromptType.FRIEND_REQUEST_SENT, PermissionPromptType.INVITE_ACCEPTED];
c11699_23 = null;
class NotificationPermissionManager extends AutomaticLifecycleManager {
constructor() {
let c22943_0;
let c22944_0;
let c22945_0;
let c22946_0;
let c22947_0, c22947_1;
super(...arguments);
const _this = this;
this.previousAppState = null;
this.actions = {
MESSAGE_CREATE: (a0) => {
_this.handleMessageCreate(a0);
_this.handleMessageCreateForNudge(a0);
},
MESSAGE_REACTION_ADD: (a0) => {
_this.handleReactionAddForNudge(a0);
},
INVITE_ACCEPT_SUCCESS: (a0) => {
_this.handleInviteAccept(a0);
},
RELATIONSHIP_ADD: (a0) => {
_this.handleSendFriendRequest(a0);
},
POST_CONNECTION_OPEN: () => {
_this.handleConnectionOpen();
},
APP_STATE_UPDATE: (a0) => {
_this.handleAppStateUpdate(a0);
}
};
c22943_0 = this;
this.handleConnectionOpen = async () => {
let c31017_0;
c31017_0 = void 0;
await _logNotificationPermissionStatus();
await c22943_0._handleNotificationAuthorizationStatusUpdate();
};
c22944_0 = void 0;
c22944_0 = async (c31018_0) => {
let c31018_2;
let c31808_0, c31808_1, c31808_2, c31808_3;
L23: {
c31018_2 = void 0;
c31808_0 = void 0;
c31808_1 = void 0;
c31808_2 = void 0;
c31808_3 = void 0;
c31808_0 = c31018_0.message;
c31808_1 = c31018_0.optimistic;
c31808_2 = c31018_0.isPushNotification;
c31808_3 = c31018_0.sendMessageOptions;
await void 0;
if (!(c31808_1 || c31808_2 || c31808_3 != null)) {
const r51 = c31808_0;
const r59 = (r51 == null ? void 0 : r51.author?.id) === AuthenticationStore.getId();
if (r59) {
if (!await (0, shouldShowPrompt)(PermissionPromptType.MESSAGE_SENT)) {
break L23;
}
} else if (!r59) {
break L23;
}
(0, showPrompt)(PermissionPromptType.MESSAGE_SENT, EventActionLocation.MESSAGE_SENT, 1000);
}
}
};
this.handleMessageCreate = function() {
return c22944_0.apply(this, arguments);
};
c22945_0 = void 0;
c22945_0 = async (c31019_0) => {
let features, c31019_3;
let c31809_0;
L23: {
c31019_3 = void 0;
c31809_0 = void 0;
c31809_0 = c31019_0.invite;
await void 0;
const features2 = c31809_0.guild?.features;
features = features2;
if (features2 == null) {
features = [];
}
if (!features.includes(GuildFeatures.COMMUNITY)) {
L17: {
let inHoldout = ContextualOptInNudgeHoldoutExperiment.getConfig({
location: "NotificationPermissionManager"
}).inHoldout;
if (inHoldout) {
const r88 = await (0, shouldShowPrompt)(PermissionPromptType.INVITE_ACCEPTED);
inHoldout = r88;
if (!r88) {
if (!await (0, shouldShowReactivationPrompt)(PermissionPromptType.INVITE_ACCEPTED)) {
break L23;
}
break L17;
}
}
if (!inHoldout) {
break L23;
}
}
(0, showPrompt)(PermissionPromptType.INVITE_ACCEPTED, EventActionLocation.INVITE_ACCEPTED, 1000);
}
}
};
this.handleInviteAccept = function() {
return c22945_0.apply(this, arguments);
};
c22946_0 = void 0;
c22946_0 = async (c31020_0) => {
let c31020_2;
let c31810_0;
L13: {
c31020_2 = void 0;
c31810_0 = void 0;
c31810_0 = c31020_0.relationship;
await void 0;
L12: {
let r50 = c31810_0.type === RelationshipTypes.PENDING_OUTGOING;
if (r50) {
const r72 = await (0, shouldShowPrompt)(PermissionPromptType.FRIEND_REQUEST_SENT);
r50 = r72;
if (!r72) {
if (!await (0, shouldShowReactivationPrompt)(PermissionPromptType.FRIEND_REQUEST_SENT)) {
break L13;
}
break L12;
}
}
if (!r50) {
break L13;
}
}
(0, showPrompt)(PermissionPromptType.FRIEND_REQUEST_SENT, EventActionLocation.FRIEND_REQUEST_SENT, 100);
}
};
this.handleSendFriendRequest = function() {
return c22946_0.apply(this, arguments);
};
c22947_0 = void 0;
c22947_1 = this;
c22947_0 = async (c31021_0) => {
let c31021_2;
c31021_2 = void 0;
let c31811_0 = c31021_0.state;
await void 0;
let c31811_1 = c22947_1.previousAppState === AppStates.BACKGROUND;
let c31811_2 = c31811_0 === AppStates.ACTIVE;
if (c31811_1 && c31811_2) {
await c22947_1._handleNotificationAuthorizationStatusUpdate();
}
if (c31811_0 === AppStates.ACTIVE) {
await (0, _logNotificationPermissionStatus)();
}
c22947_1.previousAppState = c31811_0;
};
this.handleAppStateUpdate = function() {
return c22947_0.apply(this, arguments);
};
this._handleNotificationAuthorizationStatusUpdate = async () => {
let c31022_1;
c31022_1 = void 0;
let c31812_0 = await NativeModules.NativePermissionManager.getNotificationAuthorizationStatus();
updateNotificationAuthorizationStatus(c31812_0);
};
}
handleMessageCreateForNudge({ channelId, message, optimistic, isPushNotification, sendMessageOptions }) {
if (!optimistic && !isPushNotification && sendMessageOptions == null) {
if ((message == null ? void 0 : message.author?.id) === AuthenticationStore.getId()) {
const channel = ChannelStore.getChannel(channelId);
if (channel != null) {
const guildId = channel.getGuildId();
if (!(channel.isThread() ? JoinedThreadsStore.isMuted(channel.id) : UserGuildSettingsStore.isChannelMuted(guildId, channel.id))) {
setPushNotificationPermissionEligibleForPrompt(PermissionPromptType.CHANNEL_BANNER);
}
}
}
}
}
handleReactionAddForNudge(a0) {
const { channelId, userId } = a0;
if (!a0.optimistic && userId === AuthenticationStore.getId()) {
const channel = ChannelStore.getChannel(channelId);
if (channel != null) {
const guildId = channel.getGuildId();
if (!(channel.isThread() ? JoinedThreadsStore.isMuted(channel.id) : UserGuildSettingsStore.isChannelMuted(guildId, channel.id))) {
setPushNotificationPermissionEligibleForPrompt(PermissionPromptType.POST_REACTION_BANNER);
}
}
}
}
}
const notificationPermissionManager = new NotificationPermissionManager();
export default notificationPermissionManager;