170 lines
5.5 KiB
TypeScript
170 lines
5.5 KiB
TypeScript
// Metro module 10215 (f10216).
|
|
import SelectedGuildStore from "../../stores/SelectedGuildStore";
|
|
import UserStore from "../../stores/UserStore";
|
|
import FavoriteStore from "./FavoriteStore";
|
|
import { useFavoritesNotificationStore } from "./FavoritesNotificationStore";
|
|
import { MAX_FAVORITE_CHANNELS } from "./FavoritesConstants";
|
|
import { PremiumTypes } from "../premium/PremiumConstants";
|
|
import { FREE_FAVORITE_LIMIT } from "../../_bundle/Module10217";
|
|
import { useFavoritesGuildConfig, getFavoritesGuildConfig } from "./FavoritesGuildExperiment";
|
|
import { useStateFromStores, useStateFromStoresObject } from "../../_bundle/Module589";
|
|
import PremiumTypeUtils from "../../utils/PremiumTypeUtils";
|
|
import SnowflakeUtils from "../../utils/SnowflakeUtils";
|
|
import { FavoriteChannelType } from "../../_bundle/Module1306";
|
|
import * as _FavoritesUtils from "./FavoritesUtils";
|
|
function $mk84199($env) {
|
|
return (a0, a1) => {
|
|
const r6 = $env[0];
|
|
let r9 = r6[a0.id]?.order;
|
|
if (r9 == null) {
|
|
r9 = 0;
|
|
}
|
|
let r4 = r6[a1.id]?.order;
|
|
if (r4 == null) {
|
|
r4 = 0;
|
|
}
|
|
return r9 - r4;
|
|
};
|
|
}
|
|
let $mk84198 = function() {
|
|
return () => FavoriteStore.getFavoriteChannels();
|
|
}, $mk84200 = function() {
|
|
return () => SelectedGuildStore.getGuildId();
|
|
};
|
|
const useFavoritesAccess = function useFavoritesAccess(location2 = "useFavoritesAccess") {
|
|
const favoritesGuildConfig = useFavoritesGuildConfig({
|
|
location: location2
|
|
});
|
|
const { enabled, hasHigherPrivileges, isFreemium: isFreemium2 = false } = favoritesGuildConfig;
|
|
const isPremiumExactly = PremiumTypeUtils.isPremiumExactly(useStateFromStores([UserStore], () => UserStore.getCurrentUser()), PremiumTypes.TIER_2);
|
|
const hasAccess = enabled && (isPremiumExactly || isFreemium2);
|
|
return {
|
|
hasAccess,
|
|
isExperimentEnabled: enabled,
|
|
isFreemium: isFreemium2,
|
|
hasHigherPrivileges,
|
|
favoriteLimit: hasAccess ? isPremiumExactly ? MAX_FAVORITE_CHANNELS : isFreemium2 ? FREE_FAVORITE_LIMIT : 0 : 0
|
|
};
|
|
};
|
|
export { useFavoritesAccess };
|
|
export function getFavoritesAccess() {
|
|
const favoritesGuildConfig = getFavoritesGuildConfig({
|
|
location: "getFavoritesAccess"
|
|
});
|
|
const { enabled, hasHigherPrivileges, isFreemium: isFreemium2 = false } = favoritesGuildConfig;
|
|
const isPremiumExactly = PremiumTypeUtils.isPremiumExactly(UserStore.getCurrentUser(), PremiumTypes.TIER_2);
|
|
const hasAccess = enabled && (isPremiumExactly || isFreemium2);
|
|
return {
|
|
hasAccess,
|
|
isExperimentEnabled: enabled,
|
|
isFreemium: isFreemium2,
|
|
hasHigherPrivileges,
|
|
favoriteLimit: hasAccess ? isPremiumExactly ? MAX_FAVORITE_CHANNELS : isFreemium2 ? FREE_FAVORITE_LIMIT : 0 : 0
|
|
};
|
|
}
|
|
export function useFavorites() {
|
|
return useStateFromStoresObject([FavoriteStore], $mk84198());
|
|
}
|
|
export function useFavorite(c17779_0) {
|
|
return useStateFromStores([FavoriteStore], () => FavoriteStore.getFavorite(c17779_0));
|
|
}
|
|
export function useFavoritedChannelIds() {
|
|
return SnowflakeUtils.keys(useStateFromStoresObject([FavoriteStore], $mk84198()));
|
|
}
|
|
export function getFavoritesCategories(r10 = FavoriteStore.getFavoriteChannels()) {
|
|
let env17778;
|
|
const r16 = env17778 = {};
|
|
env17778[0] = r10;
|
|
const r17 = [{
|
|
id: null,
|
|
name: ""
|
|
}];
|
|
for (const key in r10) {
|
|
const r14 = r10[key];
|
|
if (r14.type === FavoriteChannelType.CATEGORY) {
|
|
let nickname = r14.nickname;
|
|
if (nickname == null) {
|
|
nickname = "";
|
|
}
|
|
r17.push({
|
|
id: r14.id,
|
|
name: nickname
|
|
});
|
|
}
|
|
}
|
|
r17.sort($mk84199(r16));
|
|
return r17;
|
|
}
|
|
export function useFavoritesCategories() {
|
|
return useStateFromStores([FavoriteStore], () => {
|
|
let env26637;
|
|
let r10 = FavoriteStore.getFavoriteChannels();
|
|
const r5 = env26637 = {};
|
|
env26637[0] = void 0;
|
|
if (r10 === void 0) {
|
|
r10 = FavoriteStore.getFavoriteChannels();
|
|
}
|
|
env26637[0] = r10;
|
|
const r18 = [{
|
|
id: null,
|
|
name: ""
|
|
}];
|
|
for (const key in r10) {
|
|
const r14 = r10[key];
|
|
if (r14.type === FavoriteChannelType.CATEGORY) {
|
|
let nickname = r14.nickname;
|
|
if (nickname == null) {
|
|
nickname = "";
|
|
}
|
|
r18.push({
|
|
id: r14.id,
|
|
name: nickname
|
|
});
|
|
}
|
|
}
|
|
r18.sort($mk84199(r5));
|
|
return r18;
|
|
});
|
|
}
|
|
export function useIsFavoritesGuildSelected() {
|
|
return _FavoritesUtils.isFavoritesGuildId(useStateFromStores([SelectedGuildStore], $mk84200()));
|
|
}
|
|
export function useFavoritesAwareChannel(a0, a1) {
|
|
let r31;
|
|
let c17780_0;
|
|
L9: {
|
|
let r4 = a0;
|
|
c17780_0 = a0;
|
|
const isFavoritesGuildId = _FavoritesUtils.isFavoritesGuildId(useStateFromStores([SelectedGuildStore], $mk84200()));
|
|
const hasAccess = useFavoritesAccess(a1).hasAccess;
|
|
const stateFromStores = useStateFromStores([FavoriteStore], () => c17780_0 != null && (FavoriteStore.isFavorite(c17780_0.id) || c17780_0.isThread() && FavoriteStore.isFavorite(c17780_0.parent_id)), [a0]);
|
|
if (isFavoritesGuildId) {
|
|
r31 = null;
|
|
if (!hasAccess) {
|
|
break L9;
|
|
}
|
|
r31 = null;
|
|
if (!stateFromStores) {
|
|
break L9;
|
|
}
|
|
const r32 = a0 == null ? void 0 : a0.isCategory();
|
|
r31 = null;
|
|
if (r32) {
|
|
break L9;
|
|
}
|
|
}
|
|
if (a0 == null) {
|
|
r4 = null;
|
|
}
|
|
r31 = r4;
|
|
}
|
|
return r31;
|
|
}
|
|
export function useFavoriteAdded() {
|
|
return {
|
|
favoriteAdded: useFavoritesNotificationStore((a0) => a0.favoriteAdded),
|
|
notifyFavoriteAdded: useFavoritesNotificationStore((a0) => a0.notifyFavoriteAdded),
|
|
clearFavoriteAdded: useFavoritesNotificationStore((a0) => a0.clearFavoriteAdded)
|
|
};
|
|
}
|