Skip to content

Commit

Permalink
Don't show leaving live game banner if you're not a player
Browse files Browse the repository at this point in the history
  • Loading branch information
anoek committed Sep 21, 2023
1 parent 3fb4fbb commit 3e82c3d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/views/Game/AntiGrief.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

import * as React from "react";
import * as data from "data";
import { Card } from "material";
import { pgettext, _ } from "translate";
import { useGoban } from "./goban_context";
Expand All @@ -29,9 +30,11 @@ let live_game = false;
let live_game_id = 0;
let live_game_phase = null;
let last_toast = null;
let was_player = false;

function checkForLeavingLiveGame(pathname: string) {
try {
const user = data.get("user");
const goban = window["global_goban"];
const was_on_page = on_game_page;
const was_live_game = live_game;
Expand All @@ -43,6 +46,9 @@ function checkForLeavingLiveGame(pathname: string) {
live_game = goban.engine.time_control.speed !== "correspondence";
live_game_id = goban.game_id;
live_game_phase = goban.engine?.phase;
was_player =
goban.engine?.config?.black_player_id === user?.id ||
goban.engine?.config?.white_player_id === user?.id;
if (last_toast) {
last_toast.close();
}
Expand All @@ -51,7 +57,13 @@ function checkForLeavingLiveGame(pathname: string) {
}
}

if (was_on_page && !on_game_page && was_live_game && live_game_phase === "play") {
if (
was_on_page &&
was_player &&
!on_game_page &&
was_live_game &&
live_game_phase === "play"
) {
const t = toast(
<div>
{_(
Expand Down

0 comments on commit 3e82c3d

Please sign in to comment.