This repository has been archived by the owner on Feb 10, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added RoomGuestAccessStateEventDTO for heusalagroup/hghs#22
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
types/event/roomGuestAccess/RoomGuestAccessStateEventDTO.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |