Skip to content

Commit 6ba500d

Browse files
committed
New users can only chat in the games they play
1 parent 8e556a1 commit 6ba500d

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

src/components/Chat.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,13 @@ function Chat({
103103
history,
104104
gameMode,
105105
startedAt,
106+
isPlaying = false,
106107
}) {
107108
const user = useContext(UserContext);
108109
const classes = useStyles();
109-
const [stats, loadingStats] = useStats(gameId ? null : user.id);
110+
const [stats, loadingStats] = useStats(isPlaying ? null : user.id);
110111
const chatDisabled =
111-
!gameId && !isDev && (loadingStats || stats.all.all.totalSets < 55);
112+
!isPlaying && !isDev && (loadingStats || stats.all.all.totalSets < 67);
112113

113114
const chatEl = useRef();
114115
useEffect(() => {
@@ -187,7 +188,7 @@ function Chat({
187188
};
188189

189190
const items = messages;
190-
if (gameId && history) {
191+
if (history) {
191192
for (let i = 0; i < history.length; i++) {
192193
items[`card@${i}`] = history[i];
193194
}
@@ -290,7 +291,7 @@ function Chat({
290291
arrow
291292
title={
292293
chatDisabled
293-
? "New users cannot chat. Play a couple games first!"
294+
? "New users can only chat when playing. Play a couple games first!"
294295
: ""
295296
}
296297
>

src/pages/GamePage.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,9 @@ function GamePage({ match }) {
124124

125125
const [game, loadingGame] = useFirebaseRef(`games/${gameId}`);
126126
const [gameData, loadingGameData] = useFirebaseRef(`gameData/${gameId}`);
127+
const spectating = !(game?.users && user.id in game.users);
127128
const [hasNextGame] = useFirebaseRef(
128-
game?.status === "done" && (!game.users || !(user.id in game.users))
129-
? `games/${nextGameId}/status`
130-
: null
129+
game?.status === "done" && spectating ? `games/${nextGameId}/status` : null
131130
);
132131
const [playSuccess] = useSound(foundSfx);
133132
const [playFail1] = useSound(failSfx1);
@@ -241,7 +240,6 @@ function GamePage({ match }) {
241240

242241
const numHints = gameData.hints ?? 0;
243242
const paused = gameData.pause?.start && !gameData.pause.end;
244-
const spectating = !game.users || !(user.id in game.users);
245243
const leaderboard = Object.keys(game.users).sort(
246244
(u1, u2) =>
247245
(scores[u2] || 0) - (scores[u1] || 0) ||
@@ -268,8 +266,7 @@ function GamePage({ match }) {
268266
const gameEnded = !answer || game.status === "done";
269267
if (
270268
!answer &&
271-
game.users &&
272-
user.id in game.users &&
269+
!spectating &&
273270
game.status === "ingame" &&
274271
finished.gameId !== gameId
275272
) {
@@ -424,6 +421,7 @@ function GamePage({ match }) {
424421
history={history}
425422
startedAt={game.startedAt}
426423
gameMode={gameMode}
424+
isPlaying={!spectating}
427425
/>
428426
</Paper>
429427
)}

src/pages/RoomPage.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ function RoomPage({ match, location }) {
144144
title="Game Chat"
145145
messageLimit={200}
146146
gameId={gameId}
147+
isPlaying={true}
147148
showMessageTimes
148149
/>
149150
</Paper>

0 commit comments

Comments
 (0)