Skip to content

Commit

Permalink
Require playing 3 games before posting in lobby chat (#43)
Browse files Browse the repository at this point in the history
Fixes #41
  • Loading branch information
eltoder authored Nov 28, 2024
1 parent 0990a6e commit 48bdc48
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/components/Chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import firebase from "../firebase";
import { censorText } from "../util";
import autoscroll from "../utils/autoscroll";
import useFirebaseQuery from "../hooks/useFirebaseQuery";
import useMoment from "../hooks/useMoment";
import useStats from "../hooks/useStats";
import useStorage from "../hooks/useStorage";
import { UserContext } from "../context";

Expand Down Expand Up @@ -67,11 +67,8 @@ function Chat({
}) {
const user = useContext(UserContext);
const classes = useStyles();
const isNewUser = useMoment(30000)
.clone()
.subtract(5, "minutes")
.isBefore(user.authUser.metadata.creationTime);
const chatDisabled = !gameId && isNewUser;
const [stats, loadingStats] = useStats(gameId ? null : user.id);
const chatDisabled = !gameId && (loadingStats || stats.all.finishedGames < 3);

const chatEl = useRef();
useEffect(() => {
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/useStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function useStats(userId) {
}

const stats = cloneDeep(value) ?? {};
stats.all = { finishedGames: 0 };
for (const mode of Object.keys(modes)) {
stats[mode] ??= {};
stats[mode].rating ??= BASE_RATING;
Expand All @@ -36,6 +37,7 @@ function useStats(userId) {
fastestTime: Math.min(solo.fastestTime, multiplayer.fastestTime),
totalTime: solo.totalTime + multiplayer.totalTime,
};
stats.all.finishedGames += stats[mode].all.finishedGames;
}

return stats;
Expand Down

0 comments on commit 48bdc48

Please sign in to comment.