From 4c698768def503209283af5d7a04c0d21c49092f Mon Sep 17 00:00:00 2001 From: Tobias Berger Date: Sat, 8 Jan 2022 17:22:17 +0100 Subject: [PATCH] Add ID_RESPONSE Message, to let users know their authorID This value should be provided when sending messages, but will not be trusted by the server. --- ServerMessage.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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; +}