120 lines
4.1 KiB
TypeScript
120 lines
4.1 KiB
TypeScript
// Metro module 9416 (f9417).
|
|
import { useState, useRef, useEffect } from "react";
|
|
import GuildStore from "../../../stores/GuildStore";
|
|
import EmojiStore from "../EmojiStore";
|
|
import { EmojiSourceDataTypes, ExpressionSourceGuildRecord, getEmojiSourceData } from "../records/ExpressionSourceRecord";
|
|
import { GuildFeatures } from "../../../Constants";
|
|
import { EmojiTypes } from "../EmojiTypes";
|
|
import { useStateFromStoresObject } from "../../../_bundle/defaultAreStatesEqual";
|
|
export function useEmojiAndSource({ emojiId, refreshPositionKey }) {
|
|
let c17206_2, setState, setState2, setState3, setState4, ref;
|
|
c17206_2 = void 0;
|
|
setState = void 0;
|
|
setState2 = void 0;
|
|
setState3 = void 0;
|
|
setState4 = void 0;
|
|
ref = void 0;
|
|
const stateFromStoresObject = useStateFromStoresObject([EmojiStore, GuildStore], () => {
|
|
const emoji = emojiId != null ? EmojiStore.getCustomEmojiById(emojiId) : null;
|
|
return emoji?.type === EmojiTypes.GUILD ? {
|
|
emoji,
|
|
joinedEmojiSourceGuildRecord: GuildStore.getGuild(emoji?.guildId)
|
|
} : {
|
|
emoji: null,
|
|
joinedEmojiSourceGuildRecord: null
|
|
};
|
|
});
|
|
const { joinedEmojiSourceGuildRecord, emoji } = stateFromStoresObject;
|
|
const hasJoinedEmojiSourceGuild = joinedEmojiSourceGuildRecord != null;
|
|
const r27 = joinedEmojiSourceGuildRecord != null && joinedEmojiSourceGuildRecord.features.has(GuildFeatures.DISCOVERABLE);
|
|
const r30 = (hasJoinedEmojiSourceGuild ? r27 : !hasJoinedEmojiSourceGuild) && emojiId != null;
|
|
c17206_2 = r30;
|
|
let isFetching;
|
|
[isFetching, setState] = useState(r30);
|
|
let sourceType;
|
|
[sourceType, setState2] = useState(null);
|
|
const r4 = joinedEmojiSourceGuildRecord != null;
|
|
let expressionSourceGuild;
|
|
[expressionSourceGuild, setState3] = useState(r4 ? ExpressionSourceGuildRecord.createFromGuildRecord(joinedEmojiSourceGuildRecord) : null);
|
|
let expressionSourceApplication;
|
|
[expressionSourceApplication, setState4] = useState(null);
|
|
ref = useRef(refreshPositionKey);
|
|
useEffect(() => {
|
|
ref.current = refreshPositionKey;
|
|
});
|
|
useEffect(() => {
|
|
let _fetch2 = function _fetch() {
|
|
const r9 = async () => {
|
|
let c31502_1;
|
|
let c31988_0;
|
|
L26: {
|
|
c31502_1 = void 0;
|
|
c31988_0 = void 0;
|
|
const r11 = emojiId != null;
|
|
const r12 = null;
|
|
if (r11) {
|
|
c31988_0 = await getEmojiSourceData(emojiId);
|
|
if (c31988_0 != null) {
|
|
(0, setState2)(c31988_0.type);
|
|
const type2 = c31988_0.type;
|
|
if (EmojiSourceDataTypes.APPLICATION === type2) {
|
|
(0, setState4)(c31988_0.application);
|
|
} else if (EmojiSourceDataTypes.GUILD === type2) {
|
|
(0, setState3)(c31988_0.guild);
|
|
}
|
|
}
|
|
(0, setState)(false);
|
|
const current2 = ref.current;
|
|
if (current2 == null) {
|
|
break L26;
|
|
}
|
|
current2.call(ref);
|
|
break L26;
|
|
}
|
|
c31988_0 = r12;
|
|
if (c31988_0 != null) {
|
|
(0, setState2)(c31988_0.type);
|
|
const type = c31988_0.type;
|
|
if (EmojiSourceDataTypes.APPLICATION === type) {
|
|
(0, setState4)(c31988_0.application);
|
|
} else if (EmojiSourceDataTypes.GUILD === type) {
|
|
(0, setState3)(c31988_0.guild);
|
|
}
|
|
}
|
|
(0, setState)(false);
|
|
const current = ref.current;
|
|
if (current != null) {
|
|
current.call(ref);
|
|
}
|
|
return void 0;
|
|
}
|
|
};
|
|
_fetch2 = r9;
|
|
return r9.apply(this, arguments);
|
|
};
|
|
const current = ref.current;
|
|
if (current != null) {
|
|
current.call(ref);
|
|
}
|
|
if (c17206_2) {
|
|
(function() {
|
|
return _fetch2.apply(this, arguments);
|
|
})();
|
|
} else {
|
|
const current2 = ref.current;
|
|
if (current2 != null) {
|
|
current2.call(ref);
|
|
}
|
|
}
|
|
}, [emojiId, r30]);
|
|
return {
|
|
expressionSourceGuild,
|
|
expressionSourceApplication,
|
|
sourceType,
|
|
joinedEmojiSourceGuildRecord,
|
|
hasJoinedEmojiSourceGuild,
|
|
emoji,
|
|
isFetching
|
|
};
|
|
}
|