Skip to content

Commit 4f8a35d

Browse files
author
Thomas Wang
committed
pr feedback
1 parent 7e224ed commit 4f8a35d

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-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: 11 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,15 @@ 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: {
84+
access: msgCasted.payload.access,
85+
},
86+
});
87+
}
8488
},
8589
onSubscribed: () => {
8690
console.log('listening for purchase success broadcast events');
@@ -103,6 +107,7 @@ Devvit.addCustomPostType({
103107
void purchaseRealtimeChannel.send({
104108
payload: {
105109
access,
110+
userId: context.userId!,
106111
},
107112
});
108113

0 commit comments

Comments
 (0)