Skip to content

Commit

Permalink
Fixed typing for game chat messages
Browse files Browse the repository at this point in the history
  • Loading branch information
anoek committed Dec 16, 2023
1 parent ce9419d commit c620868
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 37 deletions.
46 changes: 14 additions & 32 deletions src/GobanCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,7 @@ import {
import { AdHocClock, AdHocPlayerClock, AdHocPauseControl } from "./AdHocFormat";
import { MessageID } from "./messages";
import { GobanSocket, GobanSocketEvents } from "./GobanSocket";
import {
ServerToClient,
GameChatAnalysisMessage,
GameChatReviewMessage,
GameChatTranslatedMessage,
} from "./protocol";
import { ServerToClient, GameChatMessage, GameChatLine } from "./protocol";
import { EventEmitter } from "eventemitter3";

declare let swal: any;
Expand Down Expand Up @@ -118,23 +113,7 @@ export interface GobanBounds {
bottom: number;
}

export interface GobanChatLogLine {
chat_id: string;
body: string | GameChatAnalysisMessage | GameChatReviewMessage | GameChatTranslatedMessage;
date: number;
move_number: number;
from?: number;
moves?: string;
channel: string;
player_id: number;
username?: string;
}

export type GobanChatLog = Array<{
channel: "main" | "spectator" | "malkovich";
date: number;
lines: Array<GobanChatLogLine>;
}>;
export type GobanChatLog = Array<GameChatLine>;

export interface GobanConfig extends GoEngineConfig, PuzzleConfig {
display_width?: number;
Expand Down Expand Up @@ -1061,20 +1040,23 @@ export abstract class GobanCore extends EventEmitter<Events> {
if (obj.phase) {
this.last_phase = obj.phase;
} else {
console.warn(`Game gameata missing phase`);
console.warn(`Game gamedata missing phase`);
}
this.load(obj);
this.emit("gamedata", obj);
},
);
this._socket_on((prefix + "chat") as keyof GobanSocketEvents, (obj: any): void => {
if (this.disconnectedFromGame) {
return;
}
obj.line.channel = obj.channel;
this.chat_log.push(obj.line);
this.emit("chat", obj.line);
});
this._socket_on(
(prefix + "chat") as keyof GobanSocketEvents,
(obj: GameChatMessage): void => {
if (this.disconnectedFromGame) {
return;
}
obj.line.channel = obj.channel;
this.chat_log.push(obj.line);
this.emit("chat", obj.line);
},
);
this._socket_on((prefix + "reset-chats") as keyof GobanSocketEvents, (): void => {
if (this.disconnectedFromGame) {
return;
Expand Down
12 changes: 7 additions & 5 deletions src/protocol/ServerToClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,7 @@ export interface ServerToClient {
[k: `game/${number}/clear_auto_resign`]: ServerToClient["game/:id/clear_auto_resign"];

/** A game chat message */
"game/:id/chat": (data: {
channel: "main" | "spectator" | "malkovich" | "shadowban" | "hidden" | "personal";
line: GameChatLine;
}) => void;
"game/:id/chat": (data: GameChatMessage) => void;
[k: `game/${number}/chat`]: ServerToClient["game/:id/chat"];

/** Game chat lines should be removed */
Expand Down Expand Up @@ -544,7 +541,7 @@ export interface ServerToClient {
//[k: `game/${number}/rejected`]: (data: any) => void;
}

interface GameChatLine {
export interface GameChatLine {
chat_id: string;
body: string | AnalysisComment | ReviewComment;
date: number;
Expand Down Expand Up @@ -728,3 +725,8 @@ export interface StallingScoreEstimate {
win_rate: number;
ownership: any[];
}

export interface GameChatMessage {
channel: "main" | "spectator" | "malkovich" | "shadowban" | "hidden" | "personal";
line: GameChatLine;
}

0 comments on commit c620868

Please sign in to comment.