Skip to content
This repository has been archived by the owner on Feb 10, 2024. It is now read-only.

Commit

Permalink
Added type methods for heusalagroup/hghs#17
Browse files Browse the repository at this point in the history
  • Loading branch information
thejhh committed Apr 24, 2022
1 parent 60cd128 commit 844408d
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions types/message/textMessage/MatrixTextMessageDTO.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,39 @@
// Copyright (c) 2022. Heusala Group Oy <info@heusalagroup.fi>. All rights reserved.

import { hasNoOtherKeys, isRegularObject, isString } from "../../../../core/modules/lodash";
import { isMatrixType, MatrixType } from "../../core/MatrixType";

export interface MatrixTextMessageDTO {
readonly msgtype : MatrixType;
readonly body : string;
}

export function createMatrixTextMessageDTO (
body: string
): MatrixTextMessageDTO {
return {
msgtype: MatrixType.M_TEXT,
body
};
}

export function isMatrixTextMessageDTO (value: any): value is MatrixTextMessageDTO {
return (
isRegularObject(value)
&& hasNoOtherKeys(value, [
'msgtype',
'body'
])
&& isMatrixType(value?.msgtype)
&& isString(value?.body)
);
}

readonly msgtype: string;
readonly body: string;
export function stringifyMatrixTextMessageDTO (value: MatrixTextMessageDTO): string {
return `MatrixTextMessageDTO(${value})`;
}

export function parseMatrixTextMessageDTO (value: any): MatrixTextMessageDTO | undefined {
if ( isMatrixTextMessageDTO(value) ) return value;
return undefined;
}

0 comments on commit 844408d

Please sign in to comment.