Add CURRENTLY_TYPING Message
This commit is contained in:
parent
61c9d61229
commit
cde3d62b1c
1 changed files with 28 additions and 1 deletions
|
@ -3,6 +3,7 @@ export enum MessageType {
|
||||||
TEXT = 1,
|
TEXT = 1,
|
||||||
ID_RESPONSE = 3,
|
ID_RESPONSE = 3,
|
||||||
TYPING = 4,
|
TYPING = 4,
|
||||||
|
CURRENTLY_TYPING = 5,
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ServerMessage = {
|
export type ServerMessage = {
|
||||||
|
@ -91,7 +92,33 @@ export function isIdResponseMessage(obj: unknown): obj is IdResponseMessage {
|
||||||
|
|
||||||
export type TypingMessage = ServerMessage & {
|
export type TypingMessage = ServerMessage & {
|
||||||
type: MessageType.TYPING;
|
type: MessageType.TYPING;
|
||||||
}
|
};
|
||||||
export function isTypingMessage(obj: unknown): obj is TypingMessage {
|
export function isTypingMessage(obj: unknown): obj is TypingMessage {
|
||||||
return isServerMessage(obj, MessageType.TYPING);
|
return isServerMessage(obj, MessageType.TYPING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type CurrentlyTypingMessage = ServerMessage & {
|
||||||
|
type: MessageType.CURRENTLY_TYPING;
|
||||||
|
currently: string[];
|
||||||
|
};
|
||||||
|
export function isCurrentlyTypingMessage(
|
||||||
|
obj: unknown
|
||||||
|
): obj is CurrentlyTypingMessage {
|
||||||
|
if (!isServerMessage(obj, MessageType.CURRENTLY_TYPING)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
!Object.hasOwnProperty.call(obj, "currently") ||
|
||||||
|
typeof obj !== "object" ||
|
||||||
|
!(
|
||||||
|
(obj as ServerMessage & { currently: unknown }).currently instanceof Array
|
||||||
|
) ||
|
||||||
|
Array.prototype.some.call(
|
||||||
|
(obj as ServerMessage & { currently: unknown[] }).currently,
|
||||||
|
(element) => typeof element !== "string"
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
Reference in a new issue