Skip to content

Commit 654e069

Browse files
author
Thomas Wang
committed
pr feedback
1 parent 7e224ed commit 654e069

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

packages/classic-shared/src/shared.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,5 +189,8 @@ export type GameMode = 'regular' | 'hardcore';
189189
export type PurchasedProductBroadcast = {
190190
payload: {
191191
access: HardcoreAccessStatus;
192+
// user who purchased the product; important because we don't want the broadcast to unlock
193+
// hardcore for all users
194+
userId: string;
192195
};
193196
};

packages/classic/src/main.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { isServerCall, omit } from '@hotandcold/shared/utils';
1212
import {
1313
GameMode,
1414
HardcoreAccessStatus,
15-
PurchasedProductBroadcast as PurchasedProductBroadcastMessage,
15+
PurchasedProductBroadcast,
1616
WebviewToBlocksMessage,
1717
} from '@hotandcold/classic-shared';
1818
import { GuessService } from './core/guess.js';
@@ -76,11 +76,13 @@ Devvit.addCustomPostType({
7676
const purchaseRealtimeChannel = useChannel({
7777
name: PURCHASE_REALTIME_CHANNEL,
7878
onMessage(msg: JSONValue) {
79-
const msgCasted = msg as PurchasedProductBroadcastMessage;
80-
sendMessageToWebview(context, {
81-
type: 'HARDCORE_ACCESS_UPDATE',
82-
payload: msgCasted.payload,
83-
});
79+
const msgCasted = msg as PurchasedProductBroadcast;
80+
if (msgCasted.payload.userId === context.userId) {
81+
sendMessageToWebview(context, {
82+
type: 'HARDCORE_ACCESS_UPDATE',
83+
payload: msgCasted.payload,
84+
});
85+
}
8486
},
8587
onSubscribed: () => {
8688
console.log('listening for purchase success broadcast events');
@@ -103,6 +105,7 @@ Devvit.addCustomPostType({
103105
void purchaseRealtimeChannel.send({
104106
payload: {
105107
access,
108+
userId: context.userId!,
106109
},
107110
});
108111

0 commit comments

Comments
 (0)