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 DTOs for RoomJoinRulesStateEventDTO: heusalagroup/hghs#20
- Loading branch information
Showing
6 changed files
with
186 additions
and
11 deletions.
There are no files selected for viewing
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
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
41 changes: 41 additions & 0 deletions
41
types/event/roomJoinRules/RoomJoinRulesAllowConditionDTO.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,41 @@ | ||
// Copyright (c) 2022. Heusala Group Oy <info@heusalagroup.fi>. All rights reserved. | ||
|
||
import { isRoomMembershipType, RoomMembershipType } from "./RoomMembershipType"; | ||
import { hasNoOtherKeysInDevelopment, isRegularObject } from "../../../../core/modules/lodash"; | ||
import { isMatrixRoomId, MatrixRoomId } from "../../core/MatrixRoomId"; | ||
|
||
export interface RoomJoinRulesAllowConditionDTO { | ||
readonly type : RoomMembershipType; | ||
readonly room_id : MatrixRoomId; | ||
} | ||
|
||
export function createRoomJoinRulesAllowConditionDTO ( | ||
type : RoomMembershipType, | ||
room_id : MatrixRoomId | ||
): RoomJoinRulesAllowConditionDTO { | ||
return { | ||
type, | ||
room_id | ||
}; | ||
} | ||
|
||
export function isRoomJoinRulesAllowConditionDTO (value: any): value is RoomJoinRulesAllowConditionDTO { | ||
return ( | ||
isRegularObject(value) | ||
&& hasNoOtherKeysInDevelopment(value, [ | ||
'type', | ||
'room_id' | ||
]) | ||
&& isRoomMembershipType(value?.type) | ||
&& isMatrixRoomId(value?.room_id) | ||
); | ||
} | ||
|
||
export function stringifyRoomJoinRulesAllowConditionDTO (value: RoomJoinRulesAllowConditionDTO): string { | ||
return `RoomJoinRulesAllowConditionDTO(${value})`; | ||
} | ||
|
||
export function parseRoomJoinRulesAllowConditionDTO (value: any): RoomJoinRulesAllowConditionDTO | undefined { | ||
if ( isRoomJoinRulesAllowConditionDTO(value) ) return value; | ||
return undefined; | ||
} |
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,41 @@ | ||
// Copyright (c) 2022. Heusala Group Oy <info@heusalagroup.fi>. All rights reserved. | ||
|
||
import { isMatrixJoinRule, MatrixJoinRule } from "./MatrixJoinRule"; | ||
import { isRoomJoinRulesAllowConditionDTO, RoomJoinRulesAllowConditionDTO } from "./RoomJoinRulesAllowConditionDTO"; | ||
import { hasNoOtherKeysInDevelopment, isArrayOf, isRegularObject } from "../../../../core/modules/lodash"; | ||
|
||
export interface RoomJoinRulesStateContentDTO { | ||
readonly allow : RoomJoinRulesAllowConditionDTO[]; | ||
readonly join_rule : MatrixJoinRule; | ||
} | ||
|
||
export function createRoomJoinRulesStateContentDTO ( | ||
join_rule : MatrixJoinRule, | ||
allow : RoomJoinRulesAllowConditionDTO[] | ||
): RoomJoinRulesStateContentDTO { | ||
return { | ||
join_rule, | ||
allow | ||
}; | ||
} | ||
|
||
export function isRoomJoinRulesStateContentDTO (value: any): value is RoomJoinRulesStateContentDTO { | ||
return ( | ||
isRegularObject(value) | ||
&& hasNoOtherKeysInDevelopment(value, [ | ||
'allow', | ||
'join_rule' | ||
]) | ||
&& isArrayOf<RoomJoinRulesAllowConditionDTO>(value?.allow, isRoomJoinRulesAllowConditionDTO) | ||
&& isMatrixJoinRule(value?.join_rule) | ||
); | ||
} | ||
|
||
export function stringifyRoomJoinRulesStateContentDTO (value: RoomJoinRulesStateContentDTO): string { | ||
return `RoomJoinRulesStateContentDTO(${value})`; | ||
} | ||
|
||
export function parseRoomJoinRulesStateContentDTO (value: any): RoomJoinRulesStateContentDTO | undefined { | ||
if ( isRoomJoinRulesStateContentDTO(value) ) return value; | ||
return undefined; | ||
} |
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 { hasNoOtherKeysInDevelopment, isRegularObject, isStringOrUndefined } from "../../../../core/modules/lodash"; | ||
import { isRoomJoinRulesStateContentDTO, RoomJoinRulesStateContentDTO } from "./RoomJoinRulesStateContentDTO"; | ||
import { MatrixStateEventOf } from "../../core/MatrixStateEventOf"; | ||
import { MatrixType } from "../../core/MatrixType"; | ||
|
||
/** | ||
* @see https://github.com/heusalagroup/hghs/issues/20 | ||
*/ | ||
export interface RoomJoinRulesStateEventDTO extends MatrixStateEventOf<RoomJoinRulesStateContentDTO> { | ||
readonly type : MatrixType.M_ROOM_JOIN_RULES; | ||
readonly state_key : string; | ||
readonly content : RoomJoinRulesStateContentDTO; | ||
} | ||
|
||
export function createRoomJoinRulesStateEventDTO ( | ||
content : RoomJoinRulesStateContentDTO | ||
): RoomJoinRulesStateEventDTO { | ||
return { | ||
type: MatrixType.M_ROOM_JOIN_RULES, | ||
state_key: '', | ||
content | ||
}; | ||
} | ||
|
||
export function isRoomJoinRulesStateEventDTO (value: any): value is RoomJoinRulesStateEventDTO { | ||
return ( | ||
isRegularObject(value) | ||
&& hasNoOtherKeysInDevelopment(value, [ | ||
'type', | ||
'state_key', | ||
'content' | ||
]) | ||
&& value?.type === MatrixType.M_ROOM_HISTORY_VISIBILITY | ||
&& isStringOrUndefined(value?.state_key) | ||
&& isRoomJoinRulesStateContentDTO(value?.content) | ||
); | ||
} | ||
|
||
export function stringifyRoomJoinRulesStateEventDTO (value: RoomJoinRulesStateEventDTO): string { | ||
return `RoomJoinRulesStateEventDTO(${value})`; | ||
} | ||
|
||
export function parseRoomJoinRulesStateEventDTO (value: any): RoomJoinRulesStateEventDTO | undefined { | ||
if ( isRoomJoinRulesStateEventDTO(value) ) return value; | ||
return undefined; | ||
} |
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,38 @@ | ||
// Copyright (c) 2022. Heusala Group Oy <info@heusalagroup.fi>. All rights reserved. | ||
|
||
export enum RoomMembershipType { | ||
|
||
/** | ||
* There is also MatrixType.M_ROOM_MEMBERSHIP but that should not be used. | ||
*/ | ||
M_ROOM_MEMBERSHIP = "m.room_membership" | ||
|
||
} | ||
|
||
export function isRoomMembershipType (value: any): value is RoomMembershipType { | ||
switch (value) { | ||
case RoomMembershipType.M_ROOM_MEMBERSHIP: | ||
return true; | ||
|
||
default: | ||
return false; | ||
|
||
} | ||
} | ||
|
||
export function stringifyRoomMembershipType (value: RoomMembershipType): string { | ||
switch (value) { | ||
case RoomMembershipType.M_ROOM_MEMBERSHIP : return 'm.room_membership'; | ||
} | ||
throw new TypeError(`Unsupported RoomMembershipType value: ${value}`); | ||
} | ||
|
||
export function parseRoomMembershipType (value: any): RoomMembershipType | undefined { | ||
switch (`${value}`.toLowerCase()) { | ||
|
||
case 'm.room_membership': | ||
case 'room_membership' : return RoomMembershipType.M_ROOM_MEMBERSHIP; | ||
|
||
default : return undefined; | ||
} | ||
} |