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

Commit

Permalink
Added RoomGuestAccessStateEventDTO for heusalagroup/hghs#22
Browse files Browse the repository at this point in the history
  • Loading branch information
thejhh committed Apr 24, 2022
1 parent b2a5e10 commit d5d68b7
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions types/event/roomGuestAccess/RoomGuestAccessStateEventDTO.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) 2022. Heusala Group Oy <info@heusalagroup.fi>. All rights reserved.

import {
isRoomGuestAccessContentDTO,
RoomGuestAccessContentDTO
} from "./RoomGuestAccessContentDTO";
import { MatrixStateEventOf } from "../../core/MatrixStateEventOf";
import { MatrixType } from "../../core/MatrixType";
import {
hasNoOtherKeysInDevelopment,
isRegularObject,
isString
} from "../../../../core/modules/lodash";

export type RoomGuestAccessStateEventDTO = MatrixStateEventOf<RoomGuestAccessContentDTO>;

export function createRoomGuestAccessStateEventDTO (
content: RoomGuestAccessContentDTO
): RoomGuestAccessStateEventDTO {
return {
type: MatrixType.M_ROOM_GUEST_ACCESS,
state_key: '',
content
};
}

export function isRoomGuestAccessStateEventDTO (value: any): value is RoomGuestAccessStateEventDTO {
return (
isRegularObject(value)
&& hasNoOtherKeysInDevelopment(value, [
'type',
'state_key',
'content'
])
&& value?.type === MatrixType.M_ROOM_GUEST_ACCESS
&& isString(value?.state_key)
&& isRoomGuestAccessContentDTO(value?.content)
);
}

export function stringifyRoomGuestAccessStateEventDTO (value: RoomGuestAccessStateEventDTO): string {
return `RoomGuestAccessStateEventDTO(${value})`;
}

export function parseRoomGuestAccessStateEventDTO (value: any): RoomGuestAccessStateEventDTO | undefined {
if ( isRoomGuestAccessStateEventDTO(value) ) return value;
return undefined;
}

0 comments on commit d5d68b7

Please sign in to comment.