From 334f1f179067366023a81d5f0acba65cb45c86f0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 23 Jul 2024 16:15:59 +0200 Subject: [PATCH] feat(openapi): Add more type/int limitations Signed-off-by: Joas Schilling --- lib/ResponseDefinitions.php | 83 ++++++++++++++++++++----------------- lib/Room.php | 3 ++ lib/Service/RoomService.php | 3 ++ 3 files changed, 50 insertions(+), 39 deletions(-) diff --git a/lib/ResponseDefinitions.php b/lib/ResponseDefinitions.php index 0439896a6a0a..336ceeca7f96 100644 --- a/lib/ResponseDefinitions.php +++ b/lib/ResponseDefinitions.php @@ -10,6 +10,11 @@ namespace OCA\Talk; /** + * @psalm-type TalkRoomTypes = 1|2|3|4|5|6 + * @psalm-type TalkParticipantTypes = 1|2|3|4|5|6 + * @psalm-type TalkCallFlags = int<0, 15> + * @psalm-type TalkPermissions = int<0, 255> + * * @psalm-type TalkBan = array{ * id: int, * moderatorActorType: string, @@ -26,12 +31,12 @@ * description: ?string, * id: int, * name: string, - * state: int, + * state: 0|1|2, * } * * @psalm-type TalkBotWithDetails = TalkBot&array{ * error_count: int, - * features: int, + * features: 0|1|2|3, * last_error_date: int, * last_error_message: string, * url: string, @@ -56,11 +61,11 @@ * label: string, * source: string, * mentionId: string, - * details: ?string, - * status: ?string, - * statusClearAt: ?int, - * statusIcon: ?string, - * statusMessage: ?string, + * details?: string, + * status?: 'online'|'away'|'dnd'|'busy'|'offline'|'invisible', + * statusClearAt?: ?int, + * statusIcon?: ?string, + * statusMessage?: ?string, * } * * @psalm-type TalkRichObjectParameter = array{ @@ -136,7 +141,7 @@ * * @psalm-type TalkFederationInvite = array{ * id: int, - * state: int, + * state: 0|1, * localCloudId: string, * localToken: string, * remoteAttendeeId: int, @@ -167,16 +172,16 @@ * actorId: string, * actorType: string, * attendeeId: int, - * attendeePermissions: int, + * attendeePermissions: TalkPermissions, * attendeePin: string, * displayName: string, - * inCall: int, + * inCall: TalkCallFlags, * lastPing: int, - * participantType: int, - * permissions: int, + * participantType: TalkParticipantTypes, + * permissions: TalkPermissions, * roomToken: string, * sessionIds: string[], - * status?: string, + * status?: 'online'|'away'|'dnd'|'busy'|'offline'|'invisible', * statusClearAt?: ?int, * statusIcon?: ?string, * statusMessage?: ?string, @@ -201,8 +206,8 @@ * numVoters?: int, * options: string[], * question: string, - * resultMode: int, - * status: int, + * resultMode: 0|1, + * status: 0|1, * votedSelf?: int[], * votes?: array, * } @@ -218,20 +223,20 @@ * actorId: string, * actorType: string, * attendeeId: int, - * attendeePermissions: int, + * attendeePermissions: TalkPermissions, * attendeePin: ?string, * avatarVersion: string, - * breakoutRoomMode: int, - * breakoutRoomStatus: int, - * callFlag: int, - * callPermissions: int, - * callRecording: int, + * breakoutRoomMode: 0|1|2|3, + * breakoutRoomStatus: 0|1|2, + * callFlag: TalkCallFlags, + * callPermissions: TalkPermissions, + * callRecording: int<0, 5>, * callStartTime: int, * canDeleteConversation: bool, * canEnableSIP: bool, * canLeaveConversation: bool, * canStartCall: bool, - * defaultPermissions: int, + * defaultPermissions: TalkPermissions, * description: string, * displayName: string, * hasCall: bool, @@ -244,38 +249,38 @@ * lastMessage: TalkRoomLastMessage|array, * lastPing: int, * lastReadMessage: int, - * listable: int, - * lobbyState: int, + * listable: 0|1|2, + * lobbyState: 0|1, * lobbyTimer: int, - * mentionPermissions: int, + * mentionPermissions: 0|1, * messageExpiration: int, * name: string, - * notificationCalls: int, - * notificationLevel: int, + * notificationCalls: 0|1, + * notificationLevel: 0|1|2|3, * objectId: string, * objectType: string, - * participantFlags: int, - * participantType: int, - * permissions: int, - * readOnly: int, - * recordingConsent: int, + * participantFlags: TalkCallFlags, + * participantType: TalkParticipantTypes, + * permissions: TalkPermissions, + * readOnly: 0|1, + * recordingConsent: 0|1|2, * sessionId: string, - * sipEnabled: int, - * status?: string, + * sipEnabled: 0|1|2, + * status?: 'online'|'away'|'dnd'|'busy'|'offline'|'invisible', * statusClearAt?: ?int, * statusIcon?: ?string, * statusMessage?: ?string, * token: string, - * type: int, + * type: TalkRoomTypes, * unreadMention: bool, * unreadMentionDirect: bool, * unreadMessages: int, * } * * @psalm-type TalkSignalingSession = array{ - * inCall: int, + * inCall: TalkCallFlags, * lastPing: int, - * participantPermissions: int, + * participantPermissions: TalkPermissions, * roomId: int, * sessionId: string, * userId: string, @@ -323,9 +328,9 @@ * }, * chat: array{ * max-length: int, - * read-privacy: int, + * read-privacy: 0|1, * has-translation-providers: bool, - * typing-privacy: int, + * typing-privacy: 0|1, * }, * conversations: array{ * can-create: bool, diff --git a/lib/Room.php b/lib/Room.php index bba1c88c6a93..a8eed1d0389a 100644 --- a/lib/Room.php +++ b/lib/Room.php @@ -568,6 +568,9 @@ public function getMentionPermissions(): int { return $this->mentionPermissions; } + /** + * @psalm-param self::MENTION_PERMISSIONS_* $mentionPermissions + */ public function setMentionPermissions(int $mentionPermissions): void { $this->mentionPermissions = $mentionPermissions; } diff --git a/lib/Service/RoomService.php b/lib/Service/RoomService.php index 2ad9a904394b..95a47377bce8 100644 --- a/lib/Service/RoomService.php +++ b/lib/Service/RoomService.php @@ -223,6 +223,9 @@ public function setPermissions(Room $room, string $level, string $method, int $p return true; } + /** + * @psalm-param Webinary::SIP_* $newSipEnabled + */ public function setSIPEnabled(Room $room, int $newSipEnabled): bool { $oldSipEnabled = $room->getSIPEnabled();