2022-01-16 05:56:31 +01:00
|
|
|
import { ApproveNameMessageEvent, CatalogPageMessageEvent, CatalogPagesListEvent, CatalogPublishedMessageEvent, ClubGiftInfoEvent, GiftReceiverNotFoundEvent, GiftWrappingConfigurationEvent, HabboClubOffersMessageEvent, LimitedEditionSoldOutEvent, MarketplaceConfigurationEvent, MarketplaceMakeOfferResult, NodeData, ProductOfferEvent, PurchaseErrorMessageEvent, PurchaseNotAllowedMessageEvent, PurchaseOKMessageEvent, SellablePetPalettesMessageEvent, UserSubscriptionEvent } from '@nitrots/nitro-renderer';
|
2021-08-25 23:20:32 +02:00
|
|
|
import { GuildMembershipsMessageEvent } from '@nitrots/nitro-renderer/src/nitro/communication/messages/incoming/user/GuildMembershipsMessageEvent';
|
2021-05-05 09:14:54 +02:00
|
|
|
import { FC, useCallback } from 'react';
|
2022-01-16 05:56:31 +01:00
|
|
|
import { GetFurnitureData, GetProductDataForLocalization, LocalizeText } from '../../api';
|
|
|
|
import { CatalogNameResultEvent, CatalogPurchaseFailureEvent, CatalogSelectProductEvent } from '../../events';
|
2021-09-14 21:34:13 +02:00
|
|
|
import { CatalogGiftReceiverNotFoundEvent } from '../../events/catalog/CatalogGiftReceiverNotFoundEvent';
|
2021-05-10 19:11:16 +02:00
|
|
|
import { CatalogPurchasedEvent } from '../../events/catalog/CatalogPurchasedEvent';
|
|
|
|
import { CatalogPurchaseSoldOutEvent } from '../../events/catalog/CatalogPurchaseSoldOutEvent';
|
2022-01-16 05:56:31 +01:00
|
|
|
import { BatchUpdates } from '../../hooks';
|
2021-05-10 19:11:16 +02:00
|
|
|
import { dispatchUiEvent } from '../../hooks/events/ui/ui-event';
|
2021-05-05 09:14:54 +02:00
|
|
|
import { CreateMessageHook } from '../../hooks/messages/message-event';
|
2022-01-06 04:09:53 +01:00
|
|
|
import { NotificationAlertType } from '../../views/notification-center/common/NotificationAlertType';
|
|
|
|
import { NotificationUtilities } from '../../views/notification-center/common/NotificationUtilities';
|
2022-01-16 05:56:31 +01:00
|
|
|
import { CatalogNode } from './common/CatalogNode';
|
2021-06-23 06:03:56 +02:00
|
|
|
import { CatalogPetPalette } from './common/CatalogPetPalette';
|
2022-01-16 05:56:31 +01:00
|
|
|
import { CatalogType } from './common/CatalogType';
|
|
|
|
import { ICatalogNode } from './common/ICatalogNode';
|
|
|
|
import { IProduct } from './common/IProduct';
|
|
|
|
import { IPurchasableOffer } from './common/IPurchasableOffer';
|
|
|
|
import { Offer } from './common/Offer';
|
|
|
|
import { PageLocalization } from './common/PageLocalization';
|
|
|
|
import { Product } from './common/Product';
|
2021-06-23 06:03:56 +02:00
|
|
|
import { SubscriptionInfo } from './common/SubscriptionInfo';
|
2021-05-05 09:14:54 +02:00
|
|
|
import { useCatalogContext } from './context/CatalogContext';
|
|
|
|
import { CatalogActions } from './reducers/CatalogReducer';
|
2021-04-22 05:26:30 +02:00
|
|
|
|
2022-01-06 04:07:33 +01:00
|
|
|
export const CatalogMessageHandler: FC<{}> = props =>
|
2021-04-22 05:26:30 +02:00
|
|
|
{
|
2022-01-16 05:56:31 +01:00
|
|
|
const { setIsBusy, pageId, currentType, setCurrentNode, setCurrentOffers, currentPage, setCurrentOffer, setPurchasableOffer, setFrontPageItems, showCatalogPage, catalogState, dispatchCatalogState } = useCatalogContext();
|
2021-05-05 09:14:54 +02:00
|
|
|
|
2021-09-01 00:18:53 +02:00
|
|
|
const onCatalogPagesListEvent = useCallback((event: CatalogPagesListEvent) =>
|
2021-05-05 09:14:54 +02:00
|
|
|
{
|
|
|
|
const parser = event.getParser();
|
2022-01-16 05:56:31 +01:00
|
|
|
const offers: Map<number, ICatalogNode[]> = new Map();
|
2021-05-05 09:14:54 +02:00
|
|
|
|
2022-01-16 05:56:31 +01:00
|
|
|
const getCatalogNode = (node: NodeData, depth: number, parent: ICatalogNode) =>
|
|
|
|
{
|
|
|
|
const catalogNode = (new CatalogNode(node, depth, parent) as ICatalogNode);
|
|
|
|
|
|
|
|
for(const offerId of catalogNode.offerIds)
|
|
|
|
{
|
|
|
|
if(offers.has(offerId)) offers.get(offerId).push(catalogNode);
|
|
|
|
else offers.set(offerId, [ catalogNode ]);
|
2021-05-05 09:14:54 +02:00
|
|
|
}
|
2022-01-16 05:56:31 +01:00
|
|
|
|
|
|
|
depth++;
|
|
|
|
|
|
|
|
for(const child of node.children) catalogNode.addChild(getCatalogNode(child, depth, catalogNode));
|
|
|
|
|
|
|
|
return catalogNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
BatchUpdates(() =>
|
|
|
|
{
|
|
|
|
setCurrentNode(getCatalogNode(parser.root, 0, null));
|
|
|
|
setCurrentOffers(offers);
|
2021-05-05 09:14:54 +02:00
|
|
|
});
|
2022-01-16 05:56:31 +01:00
|
|
|
}, [ setCurrentNode, setCurrentOffers ]);
|
2021-05-05 09:14:54 +02:00
|
|
|
|
2021-09-01 00:18:53 +02:00
|
|
|
const onCatalogPageMessageEvent = useCallback((event: CatalogPageMessageEvent) =>
|
2021-05-05 09:14:54 +02:00
|
|
|
{
|
|
|
|
const parser = event.getParser();
|
|
|
|
|
2022-01-16 05:56:31 +01:00
|
|
|
if(parser.catalogType !== currentType) return;
|
|
|
|
|
|
|
|
const purchasableOffers: IPurchasableOffer[] = [];
|
|
|
|
|
|
|
|
for(const offer of parser.offers)
|
|
|
|
{
|
|
|
|
const products: IProduct[] = [];
|
|
|
|
const productData = GetProductDataForLocalization(offer.localizationId);
|
|
|
|
|
|
|
|
for(const product of offer.products)
|
|
|
|
{
|
|
|
|
const furnitureData = GetFurnitureData(product.furniClassId, product.productType);
|
|
|
|
|
|
|
|
products.push(new Product(product.productType, product.furniClassId, product.extraParam, product.productCount, productData, furnitureData, product.uniqueLimitedItem, product.uniqueLimitedSeriesSize, product.uniqueLimitedItemsLeft));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!products.length) continue;
|
|
|
|
|
|
|
|
const purchasableOffer = new Offer(offer.offerId, offer.localizationId, offer.rent, offer.priceCredits, offer.priceActivityPoints, offer.priceActivityPointsType, offer.giftable, offer.clubLevel, products, offer.bundlePurchaseAllowed);
|
|
|
|
|
|
|
|
if((currentType === CatalogType.NORMAL) || ((purchasableOffer.pricingModel !== Offer.PRICING_MODEL_BUNDLE) && (purchasableOffer.pricingModel !== Offer.PRICING_MODEL_MULTI))) purchasableOffers.push(purchasableOffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
BatchUpdates(() =>
|
|
|
|
{
|
|
|
|
if(parser.frontPageItems && parser.frontPageItems.length) setFrontPageItems(parser.frontPageItems);
|
|
|
|
|
|
|
|
setIsBusy(false);
|
|
|
|
|
|
|
|
if(pageId === parser.pageId)
|
|
|
|
{
|
|
|
|
showCatalogPage(parser.pageId, parser.layoutCode, new PageLocalization(parser.localization.images.concat(), parser.localization.texts.concat()), purchasableOffers, parser.offerId, parser.acceptSeasonCurrencyAsCredits);
|
2021-05-05 09:14:54 +02:00
|
|
|
}
|
|
|
|
});
|
2022-01-16 05:56:31 +01:00
|
|
|
}, [ currentType, pageId, setFrontPageItems, setIsBusy, showCatalogPage ]);
|
2021-05-05 09:14:54 +02:00
|
|
|
|
2021-09-01 00:18:53 +02:00
|
|
|
const onPurchaseOKMessageEvent = useCallback((event: PurchaseOKMessageEvent) =>
|
2021-05-10 19:11:16 +02:00
|
|
|
{
|
|
|
|
const parser = event.getParser();
|
|
|
|
|
|
|
|
dispatchUiEvent(new CatalogPurchasedEvent(parser.offer));
|
|
|
|
}, []);
|
|
|
|
|
2021-09-01 00:18:53 +02:00
|
|
|
const onPurchaseErrorMessageEvent = useCallback((event: PurchaseErrorMessageEvent) =>
|
2021-05-10 19:11:16 +02:00
|
|
|
{
|
|
|
|
const parser = event.getParser();
|
|
|
|
|
|
|
|
dispatchUiEvent(new CatalogPurchaseFailureEvent(parser.code));
|
|
|
|
}, []);
|
|
|
|
|
2021-09-01 00:18:53 +02:00
|
|
|
const onPurchaseNotAllowedMessageEvent = useCallback((event: PurchaseNotAllowedMessageEvent) =>
|
2021-05-10 19:11:16 +02:00
|
|
|
{
|
|
|
|
const parser = event.getParser();
|
|
|
|
}, []);
|
|
|
|
|
2021-09-01 00:18:53 +02:00
|
|
|
const onLimitedEditionSoldOutEvent = useCallback((event: LimitedEditionSoldOutEvent) =>
|
2021-05-10 19:11:16 +02:00
|
|
|
{
|
|
|
|
const parser = event.getParser();
|
|
|
|
|
|
|
|
dispatchUiEvent(new CatalogPurchaseSoldOutEvent());
|
|
|
|
}, []);
|
|
|
|
|
2021-09-01 00:18:53 +02:00
|
|
|
const onProductOfferEvent = useCallback((event: ProductOfferEvent) =>
|
2021-05-10 19:11:16 +02:00
|
|
|
{
|
|
|
|
const parser = event.getParser();
|
2022-01-16 05:56:31 +01:00
|
|
|
const offerData = parser.offer;
|
2021-05-10 19:11:16 +02:00
|
|
|
|
2022-01-16 05:56:31 +01:00
|
|
|
if(!offerData || !offerData.products.length) return;
|
|
|
|
|
|
|
|
const offerProductData = offerData.products[0];
|
|
|
|
|
|
|
|
if(offerProductData.uniqueLimitedItem)
|
|
|
|
{
|
|
|
|
// update unique
|
|
|
|
}
|
|
|
|
|
|
|
|
const products: IProduct[] = [];
|
|
|
|
const productData = GetProductDataForLocalization(offerData.localizationId);
|
|
|
|
|
|
|
|
for(const product of offerData.products)
|
|
|
|
{
|
|
|
|
const furnitureData = GetFurnitureData(product.furniClassId, product.productType);
|
|
|
|
|
|
|
|
products.push(new Product(product.productType, product.furniClassId, product.extraParam, product.productCount, productData, furnitureData, product.uniqueLimitedItem, product.uniqueLimitedSeriesSize, product.uniqueLimitedItemsLeft));
|
|
|
|
}
|
|
|
|
|
|
|
|
const offer = new Offer(offerData.offerId, offerData.localizationId, offerData.rent, offerData.priceCredits, offerData.priceActivityPoints, offerData.priceActivityPointsType, offerData.giftable, offerData.clubLevel, products, offerData.bundlePurchaseAllowed);
|
|
|
|
|
|
|
|
if(!((currentType === CatalogType.NORMAL) || ((offer.pricingModel !== Offer.PRICING_MODEL_BUNDLE) && (offer.pricingModel !== Offer.PRICING_MODEL_MULTI)))) return;
|
|
|
|
|
|
|
|
offer.page = currentPage;
|
|
|
|
|
|
|
|
dispatchUiEvent(new CatalogSelectProductEvent(offer));
|
|
|
|
|
|
|
|
BatchUpdates(() =>
|
|
|
|
{
|
|
|
|
setCurrentOffer(offer);
|
|
|
|
setPurchasableOffer(offer);
|
2021-05-10 19:11:16 +02:00
|
|
|
});
|
2022-01-16 05:56:31 +01:00
|
|
|
}, [ currentType, currentPage, setCurrentOffer, setPurchasableOffer ]);
|
2021-05-10 19:11:16 +02:00
|
|
|
|
2021-09-01 00:18:53 +02:00
|
|
|
const onSellablePetPalettesMessageEvent = useCallback((event: SellablePetPalettesMessageEvent) =>
|
2021-05-22 19:27:39 +02:00
|
|
|
{
|
|
|
|
const parser = event.getParser();
|
|
|
|
const petPalette = new CatalogPetPalette(parser.productCode, parser.palettes.slice());
|
|
|
|
|
|
|
|
dispatchCatalogState({
|
|
|
|
type: CatalogActions.SET_PET_PALETTE,
|
|
|
|
payload: { petPalette }
|
|
|
|
});
|
|
|
|
}, [ dispatchCatalogState ]);
|
|
|
|
|
2021-09-01 00:18:53 +02:00
|
|
|
const onApproveNameMessageEvent = useCallback((event: ApproveNameMessageEvent) =>
|
2021-05-22 19:27:39 +02:00
|
|
|
{
|
|
|
|
const parser = event.getParser();
|
|
|
|
|
|
|
|
dispatchUiEvent(new CatalogNameResultEvent(parser.result, parser.validationInfo));
|
|
|
|
}, []);
|
|
|
|
|
2021-09-14 21:34:13 +02:00
|
|
|
const onGiftReceiverNotFoundEvent = useCallback(() =>
|
|
|
|
{
|
|
|
|
dispatchUiEvent(new CatalogGiftReceiverNotFoundEvent());
|
|
|
|
}, []);
|
|
|
|
|
2021-09-01 00:18:53 +02:00
|
|
|
const onHabboClubOffersMessageEvent = useCallback((event: HabboClubOffersMessageEvent) =>
|
2021-05-24 07:28:37 +02:00
|
|
|
{
|
|
|
|
const parser = event.getParser();
|
|
|
|
|
|
|
|
dispatchCatalogState({
|
|
|
|
type: CatalogActions.SET_CLUB_OFFERS,
|
|
|
|
payload: {
|
|
|
|
clubOffers: parser.offers
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, [ dispatchCatalogState ]);
|
|
|
|
|
2021-09-01 00:18:53 +02:00
|
|
|
const onGuildMembershipsMessageEvent = useCallback((event: GuildMembershipsMessageEvent) =>
|
2021-06-21 11:54:29 +02:00
|
|
|
{
|
|
|
|
const parser = event.getParser();
|
|
|
|
|
|
|
|
dispatchCatalogState({
|
|
|
|
type: CatalogActions.SET_GROUPS,
|
|
|
|
payload: {
|
|
|
|
groups: parser.groups
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, [ dispatchCatalogState ]);
|
|
|
|
|
2021-06-12 04:53:56 +02:00
|
|
|
const onUserSubscriptionEvent = useCallback((event: UserSubscriptionEvent) =>
|
|
|
|
{
|
|
|
|
const parser = event.getParser();
|
|
|
|
|
|
|
|
dispatchCatalogState({
|
|
|
|
type: CatalogActions.SET_SUBSCRIPTION_INFO,
|
|
|
|
payload: {
|
|
|
|
subscriptionInfo: new SubscriptionInfo(
|
2021-07-24 10:04:27 +02:00
|
|
|
Math.max(0, parser.daysToPeriodEnd),
|
|
|
|
Math.max(0, parser.periodsSubscribedAhead),
|
2021-06-12 04:53:56 +02:00
|
|
|
parser.isVip,
|
|
|
|
parser.pastClubDays,
|
2021-07-24 10:04:27 +02:00
|
|
|
parser.pastVipDays
|
2021-06-12 04:53:56 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, [ dispatchCatalogState ]);
|
|
|
|
|
2021-09-01 00:18:53 +02:00
|
|
|
const onCatalogPublishedMessageEvent = useCallback((event: CatalogPublishedMessageEvent) =>
|
2021-06-12 04:53:56 +02:00
|
|
|
{
|
|
|
|
dispatchCatalogState({
|
|
|
|
type: CatalogActions.RESET_STATE,
|
|
|
|
payload: {}
|
|
|
|
});
|
|
|
|
}, [ dispatchCatalogState ]);
|
|
|
|
|
2021-09-01 00:18:53 +02:00
|
|
|
const onGiftWrappingConfigurationEvent = useCallback((event: GiftWrappingConfigurationEvent) =>
|
2021-07-17 19:11:47 +02:00
|
|
|
{
|
|
|
|
const parser = event.getParser();
|
|
|
|
|
|
|
|
dispatchCatalogState({
|
|
|
|
type: CatalogActions.SET_GIFT_CONFIGURATION,
|
|
|
|
payload: {
|
|
|
|
giftConfiguration: parser
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, [ dispatchCatalogState ]);
|
|
|
|
|
2022-01-05 18:56:39 +01:00
|
|
|
const onMarketplaceMakeOfferResult = useCallback((event: MarketplaceMakeOfferResult) =>
|
|
|
|
{
|
|
|
|
const parser = event.getParser();
|
|
|
|
|
|
|
|
if(!parser) return;
|
|
|
|
|
|
|
|
let title = '';
|
|
|
|
if(parser.result === 1)
|
|
|
|
{
|
|
|
|
title = LocalizeText('inventory.marketplace.result.title.success');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
title = LocalizeText('inventory.marketplace.result.title.failure');
|
|
|
|
}
|
|
|
|
|
|
|
|
const message = LocalizeText(`inventory.marketplace.result.${parser.result}`);
|
|
|
|
|
|
|
|
NotificationUtilities.simpleAlert(message, NotificationAlertType.DEFAULT, null, null, title);
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
const onMarketplaceConfigurationEvent = useCallback((event: MarketplaceConfigurationEvent) =>
|
|
|
|
{
|
|
|
|
const parser = event.getParser();
|
|
|
|
|
|
|
|
if(!parser) return;
|
|
|
|
|
|
|
|
console.log(parser);
|
|
|
|
|
|
|
|
dispatchCatalogState({
|
|
|
|
type: CatalogActions.SET_MARKETPLACE_CONFIGURATION,
|
|
|
|
payload: {
|
|
|
|
marketplaceConfiguration: parser
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, [dispatchCatalogState]);
|
|
|
|
|
2022-01-05 22:12:29 +01:00
|
|
|
const onClubGiftInfoEvent = useCallback((event: ClubGiftInfoEvent) =>
|
|
|
|
{
|
|
|
|
const parser = event.getParser();
|
|
|
|
|
|
|
|
if(!parser) return;
|
|
|
|
|
|
|
|
dispatchCatalogState({
|
|
|
|
type: CatalogActions.SET_CLUB_GIFTS,
|
|
|
|
payload: {
|
|
|
|
clubGifts: parser
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, [dispatchCatalogState]);
|
|
|
|
|
2021-09-01 00:18:53 +02:00
|
|
|
CreateMessageHook(CatalogPagesListEvent, onCatalogPagesListEvent);
|
|
|
|
CreateMessageHook(CatalogPageMessageEvent, onCatalogPageMessageEvent);
|
|
|
|
CreateMessageHook(PurchaseOKMessageEvent, onPurchaseOKMessageEvent);
|
|
|
|
CreateMessageHook(PurchaseErrorMessageEvent, onPurchaseErrorMessageEvent);
|
|
|
|
CreateMessageHook(PurchaseNotAllowedMessageEvent, onPurchaseNotAllowedMessageEvent);
|
|
|
|
CreateMessageHook(LimitedEditionSoldOutEvent, onLimitedEditionSoldOutEvent);
|
|
|
|
CreateMessageHook(ProductOfferEvent, onProductOfferEvent);
|
|
|
|
CreateMessageHook(GuildMembershipsMessageEvent, onGuildMembershipsMessageEvent);
|
|
|
|
CreateMessageHook(SellablePetPalettesMessageEvent, onSellablePetPalettesMessageEvent);
|
|
|
|
CreateMessageHook(ApproveNameMessageEvent, onApproveNameMessageEvent);
|
2021-09-14 21:34:13 +02:00
|
|
|
CreateMessageHook(GiftReceiverNotFoundEvent, onGiftReceiverNotFoundEvent);
|
2021-09-01 00:18:53 +02:00
|
|
|
CreateMessageHook(HabboClubOffersMessageEvent, onHabboClubOffersMessageEvent);
|
2021-06-12 04:53:56 +02:00
|
|
|
CreateMessageHook(UserSubscriptionEvent, onUserSubscriptionEvent);
|
2021-09-01 00:18:53 +02:00
|
|
|
CreateMessageHook(CatalogPublishedMessageEvent, onCatalogPublishedMessageEvent);
|
|
|
|
CreateMessageHook(GiftWrappingConfigurationEvent, onGiftWrappingConfigurationEvent);
|
2022-01-05 22:12:29 +01:00
|
|
|
CreateMessageHook(ClubGiftInfoEvent, onClubGiftInfoEvent);
|
2022-01-05 18:56:39 +01:00
|
|
|
CreateMessageHook(MarketplaceMakeOfferResult, onMarketplaceMakeOfferResult);
|
|
|
|
CreateMessageHook(MarketplaceConfigurationEvent, onMarketplaceConfigurationEvent);
|
2021-05-05 09:14:54 +02:00
|
|
|
|
|
|
|
return null;
|
2021-04-22 05:26:30 +02:00
|
|
|
}
|