90 lines
3.8 KiB
TypeScript
90 lines
3.8 KiB
TypeScript
// Metro module 16131 (f16132).
|
|
import ChannelStore from "../../stores/ChannelStore";
|
|
import MessageStore from "../../stores/MessageStore";
|
|
import SelectedChannelStore from "../../stores/SelectedChannelStore";
|
|
import UserStore, { transformUser } from "../../stores/UserStore";
|
|
import { ChannelTypes, MAX_MESSAGES_PER_CHANNEL } from "../../Constants";
|
|
import { SafetyToastType } from "../safety_common/Constants";
|
|
import Logger from "../debug/Logger";
|
|
import MessageActionCreators from "../../actions/MessageActionCreators";
|
|
import { preloadForumThreads } from "../forums/ForumPostDataLoader";
|
|
import AutomaticLifecycleManager from "../../lib/AutomaticLifecycleManager";
|
|
import { AgeVerificationStatusUkAndAusOnly } from "../../flow/Server";
|
|
import { isFeatureAgeGated } from "../regional_feature_config/RegionalFeatureConfigUtils";
|
|
import { AgeGatedFeature } from "../../_bundle/Module5013";
|
|
import ChannelMessages from "../../lib/ChannelMessages";
|
|
let c11552_10;
|
|
const handleMessageCreate = function handleMessageCreate(a0) {
|
|
MessageStore.getMessage(a0.channelId, a0.message.id);
|
|
};
|
|
SafetyToastType;
|
|
c11552_10 = new Logger("AgeVerificationManager");
|
|
class AgeVerificationManager extends AutomaticLifecycleManager {
|
|
constructor() {
|
|
super(...arguments);
|
|
const _this = this;
|
|
this._previousAgeVerificationStatus = null;
|
|
this.handlePostConnectionOpen = () => {
|
|
let _previousAgeVerificationStatus = UserStore.getCurrentUser()?.ageVerificationStatus;
|
|
if (_previousAgeVerificationStatus == null) {
|
|
_previousAgeVerificationStatus = null;
|
|
}
|
|
_this._previousAgeVerificationStatus = _previousAgeVerificationStatus;
|
|
};
|
|
this.handleCurrentUserUpdate = ({ user }) => {
|
|
let channelId, c28233_1;
|
|
channelId = void 0;
|
|
c28233_1 = void 0;
|
|
let ageVerificationStatus = transformUser(user).ageVerificationStatus;
|
|
if (ageVerificationStatus == null) {
|
|
ageVerificationStatus = null;
|
|
}
|
|
const r17 = _this._previousAgeVerificationStatus !== ageVerificationStatus && ageVerificationStatus === AgeVerificationStatusUkAndAusOnly.VERIFIED_ADULT && isFeatureAgeGated(AgeGatedFeature.AGE_GATED_SPACES);
|
|
try {
|
|
try {
|
|
if (r17) {
|
|
const channelId2 = SelectedChannelStore.getChannelId();
|
|
channelId = channelId2;
|
|
c28233_1 = false;
|
|
ChannelMessages.forEach(({ channelId: channelId2 }) => {
|
|
if (ChannelStore.getChannel(channelId2)?.nsfw) {
|
|
ChannelMessages.clear(channelId2);
|
|
if (channelId2 === channelId) {
|
|
c28233_1 = true;
|
|
}
|
|
}
|
|
});
|
|
if (c28233_1 && channelId2 != null) {
|
|
(function handleLoadChannelMessages(a0) {
|
|
MessageActionCreators.fetchMessages({
|
|
channelId: a0,
|
|
limit: MAX_MESSAGES_PER_CHANNEL
|
|
});
|
|
})(channelId2);
|
|
(function handleLoadForumPosts(a0) {
|
|
const channel = ChannelStore.getChannel(a0);
|
|
if (!(channel?.type !== ChannelTypes.GUILD_FORUM && channel?.type !== ChannelTypes.GUILD_MEDIA)) {
|
|
preloadForumThreads(channel);
|
|
}
|
|
})(channelId2);
|
|
}
|
|
}
|
|
} catch ($e) {
|
|
c11552_10.warn("Error clearing cache and refetching messages", $e);
|
|
}
|
|
} catch (r54) {
|
|
_this._previousAgeVerificationStatus = ageVerificationStatus;
|
|
throw r54;
|
|
}
|
|
_this._previousAgeVerificationStatus = ageVerificationStatus;
|
|
};
|
|
this.actions = {
|
|
POST_CONNECTION_OPEN: this.handlePostConnectionOpen,
|
|
CURRENT_USER_UPDATE: this.handleCurrentUserUpdate,
|
|
MESSAGE_CREATE: handleMessageCreate
|
|
};
|
|
}
|
|
}
|
|
const ageVerificationManager = new AgeVerificationManager();
|
|
export default ageVerificationManager;
|