diff --git a/ServerMessage.ts b/ServerMessage.ts index 23d15a9..100ba9c 100644 --- a/ServerMessage.ts +++ b/ServerMessage.ts @@ -1,6 +1,7 @@ export enum MessageType { ACK = 0, TEXT = 1, + ID_RESPONSE = 3, } export type ServerMessage = { @@ -71,3 +72,18 @@ export type AckMessage = ServerMessage & { export function isAckMessage(obj: unknown): obj is AckMessage { return isServerMessage(obj, MessageType.ACK); } + +export type IdResponseMessage = ServerMessage & { + type: MessageType.ID_RESPONSE; + authorId: string; +}; +export function isIdResponseMessage(obj: unknown): obj is IdResponseMessage { + if (!isServerMessage(obj, MessageType.ID_RESPONSE)) return false; + if ( + !Object.hasOwnProperty.call(obj, "authorId") || + typeof (obj as ServerMessage & { authorId: unknown }).authorId !== "string" + ) { + return false; + } + return true; +}