Skip to content

Commit

Permalink
TEmp
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Nov 27, 2024
1 parent 8bc276e commit db15364
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 39 deletions.
77 changes: 40 additions & 37 deletions lib/Controller/RoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public function getRooms(int $noStatusUpdate = 0, bool $includeStatus = false, i
* Get listed rooms with optional search term
*
* @param string $searchTerm search term
* @return DataResponse<Http::STATUS_OK, TalkRoom[], array{}>
* @return DataResponse<Http::STATUS_OK, list<TalkRoom>, array{}>
*
* 200: Return list of matching rooms
*/
Expand All @@ -307,7 +307,7 @@ public function getListedRooms(string $searchTerm = ''): DataResponse {
*
* All for moderators and in case of "free selection", or the assigned breakout room for other participants
*
* @return DataResponse<Http::STATUS_OK, TalkRoom[], array{}>|DataResponse<Http::STATUS_BAD_REQUEST, array{error: string}, array{}>
* @return DataResponse<Http::STATUS_OK, list<TalkRoom>, array{}>|DataResponse<Http::STATUS_BAD_REQUEST, array{error: string}, array{}>
*
* 200: Breakout rooms returned
* 400: Getting breakout rooms is not possible
Expand Down Expand Up @@ -714,7 +714,7 @@ protected function createEmptyRoom(string $roomName, bool $public = true, string
/**
* Add a room to the favorites
*
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>
* @return DataResponse<Http::STATUS_OK, TalkRoom, array{}>
*
* 200: Successfully added room to favorites
*/
Expand All @@ -723,13 +723,13 @@ protected function createEmptyRoom(string $roomName, bool $public = true, string
#[RequireLoggedInParticipant]
public function addToFavorites(): DataResponse {
$this->participantService->updateFavoriteStatus($this->participant, true);
return new DataResponse([]);
return new DataResponse($this->formatRoom($this->room, $this->participant));
}

/**
* Remove a room from the favorites
*
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>
* @return DataResponse<Http::STATUS_OK, TalkRoom, array{}>
*
* 200: Successfully removed room from favorites
*/
Expand All @@ -738,15 +738,15 @@ public function addToFavorites(): DataResponse {
#[RequireLoggedInParticipant]
public function removeFromFavorites(): DataResponse {
$this->participantService->updateFavoriteStatus($this->participant, false);
return new DataResponse([]);
return new DataResponse($this->formatRoom($this->room, $this->participant));
}

/**
* Update the notification level for a room
*
* @param int $level New level
* @psalm-param Participant::NOTIFY_* $level
* @return DataResponse<Http::STATUS_OK|Http::STATUS_BAD_REQUEST, array<empty>, array{}>
* @return DataResponse<Http::STATUS_OK, TalkRoom, array{}>|DataResponse<Http::STATUS_BAD_REQUEST, array{error: 'level'}, array{}>
*
* 200: Notification level updated successfully
* 400: Updating notification level is not possible
Expand All @@ -757,19 +757,19 @@ public function removeFromFavorites(): DataResponse {
public function setNotificationLevel(int $level): DataResponse {
try {
$this->participantService->updateNotificationLevel($this->participant, $level);
} catch (\InvalidArgumentException $e) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
} catch (\InvalidArgumentException) {
return new DataResponse(['error' => 'level'], Http::STATUS_BAD_REQUEST);
}

return new DataResponse();
return new DataResponse($this->formatRoom($this->room, $this->participant));
}

/**
* Update call notifications
*
* @param int $level New level
* @psalm-param Participant::NOTIFY_CALLS_* $level
* @return DataResponse<Http::STATUS_OK|Http::STATUS_BAD_REQUEST, array<empty>, array{}>
* @return DataResponse<Http::STATUS_OK, TalkRoom, array{}>|DataResponse<Http::STATUS_BAD_REQUEST, array{error: 'level'}, array{}>
*
* 200: Call notification level updated successfully
* 400: Updating call notification level is not possible
Expand All @@ -779,11 +779,11 @@ public function setNotificationLevel(int $level): DataResponse {
public function setNotificationCalls(int $level): DataResponse {
try {
$this->participantService->updateNotificationCalls($this->participant, $level);
} catch (\InvalidArgumentException $e) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
} catch (\InvalidArgumentException) {
return new DataResponse(['error' => 'level'], Http::STATUS_BAD_REQUEST);
}

return new DataResponse();
return new DataResponse($this->formatRoom($this->room, $this->participant));
}

/**
Expand Down Expand Up @@ -2079,7 +2079,7 @@ public function leaveFederatedRoom(string $token, string $sessionId): DataRespon
*
* @param int $attendeeId ID of the attendee
* @psalm-param non-negative-int $attendeeId
* @return DataResponse<Http::STATUS_OK|Http::STATUS_BAD_REQUEST|Http::STATUS_FORBIDDEN|Http::STATUS_NOT_FOUND, array<empty>, array{}>
* @return DataResponse<Http::STATUS_OK|Http::STATUS_BAD_REQUEST|Http::STATUS_FORBIDDEN|Http::STATUS_NOT_FOUND, null, array{}>
*
* 200: Attendee promoted to moderator successfully
* 400: Promoting attendee to moderator is not possible
Expand All @@ -2097,7 +2097,7 @@ public function promoteModerator(int $attendeeId): DataResponse {
*
* @param int $attendeeId ID of the attendee
* @psalm-param non-negative-int $attendeeId
* @return DataResponse<Http::STATUS_OK|Http::STATUS_BAD_REQUEST|Http::STATUS_FORBIDDEN|Http::STATUS_NOT_FOUND, array<empty>, array{}>
* @return DataResponse<Http::STATUS_OK|Http::STATUS_BAD_REQUEST|Http::STATUS_FORBIDDEN|Http::STATUS_NOT_FOUND, null, array{}>
*
* 200: Attendee demoted from moderator successfully
* 400: Demoting attendee from moderator is not possible
Expand All @@ -2117,35 +2117,35 @@ public function demoteModerator(int $attendeeId): DataResponse {
* @param int $attendeeId
* @psalm-param non-negative-int $attendeeId
* @param bool $promote Shall the attendee be promoted or demoted
* @return DataResponse<Http::STATUS_OK|Http::STATUS_BAD_REQUEST|Http::STATUS_FORBIDDEN|Http::STATUS_NOT_FOUND, array<empty>, array{}>
* @return DataResponse<Http::STATUS_OK|Http::STATUS_BAD_REQUEST|Http::STATUS_FORBIDDEN|Http::STATUS_NOT_FOUND, null, array{}>
*/
protected function changeParticipantType(int $attendeeId, bool $promote): DataResponse {
try {
$targetParticipant = $this->participantService->getParticipantByAttendeeId($this->room, $attendeeId);
} catch (ParticipantNotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
return new DataResponse(null, Http::STATUS_NOT_FOUND);
}

$attendee = $targetParticipant->getAttendee();

if ($attendee->getActorType() === Attendee::ACTOR_USERS
&& $attendee->getActorId() === MatterbridgeManager::BRIDGE_BOT_USERID) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
return new DataResponse(null, Http::STATUS_NOT_FOUND);
}

// Prevent users/moderators modifying themselves
if ($attendee->getActorType() === $this->participant->getAttendee()->getActorType()) {
if ($attendee->getActorId() === $this->participant->getAttendee()->getActorId()) {
return new DataResponse([], Http::STATUS_FORBIDDEN);
return new DataResponse(null, Http::STATUS_FORBIDDEN);
}
} elseif ($attendee->getActorType() === Attendee::ACTOR_GROUPS) {
// Can not promote/demote groups
return new DataResponse([], Http::STATUS_BAD_REQUEST);
return new DataResponse(null, Http::STATUS_BAD_REQUEST);
}

if ($promote === $targetParticipant->hasModeratorPermissions()) {
// Prevent concurrent changes
return new DataResponse([], Http::STATUS_BAD_REQUEST);
return new DataResponse(null, Http::STATUS_BAD_REQUEST);
}

if ($attendee->getParticipantType() === Participant::USER) {
Expand All @@ -2157,12 +2157,12 @@ protected function changeParticipantType(int $attendeeId, bool $promote): DataRe
} elseif ($attendee->getParticipantType() === Participant::GUEST_MODERATOR) {
$newType = Participant::GUEST;
} else {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
return new DataResponse(null, Http::STATUS_BAD_REQUEST);
}

$this->participantService->updateParticipantType($this->room, $targetParticipant, $newType);

return new DataResponse();
return new DataResponse(null);
}

/**
Expand Down Expand Up @@ -2307,7 +2307,7 @@ public function setLobby(int $state, ?int $timer = null): DataResponse {
*
* @param 0|1|2 $state New state
* @psalm-param Webinary::SIP_* $state
* @return DataResponse<Http::STATUS_OK, TalkRoom, array{}>|DataResponse<Http::STATUS_UNAUTHORIZED|Http::STATUS_FORBIDDEN|Http::STATUS_PRECONDITION_FAILED, array<empty>, array{}>|DataResponse<Http::STATUS_BAD_REQUEST, array{error: 'breakout-room'|'token'|'type'|'value'}, array{}>
* @return DataResponse<Http::STATUS_OK, TalkRoom, array{}>|DataResponse<Http::STATUS_UNAUTHORIZED|Http::STATUS_FORBIDDEN|Http::STATUS_PRECONDITION_FAILED, array{error: 'config'}, array{}>|DataResponse<Http::STATUS_BAD_REQUEST, array{error: 'breakout-room'|'token'|'type'|'value'}, array{}>
*
* 200: SIP enabled state updated successfully
* 400: Updating SIP enabled state is not possible
Expand All @@ -2320,15 +2320,15 @@ public function setLobby(int $state, ?int $timer = null): DataResponse {
public function setSIPEnabled(int $state): DataResponse {
$user = $this->userManager->get($this->userId);
if (!$user instanceof IUser) {
return new DataResponse([], Http::STATUS_UNAUTHORIZED);
return new DataResponse(['error' => 'config'], Http::STATUS_UNAUTHORIZED);
}

if (!$this->talkConfig->canUserEnableSIP($user)) {
return new DataResponse([], Http::STATUS_FORBIDDEN);
return new DataResponse(['error' => 'config'], Http::STATUS_FORBIDDEN);
}

if (!$this->talkConfig->isSIPConfigured()) {
return new DataResponse([], Http::STATUS_PRECONDITION_FAILED);
return new DataResponse(['error' => 'config'], Http::STATUS_PRECONDITION_FAILED);
}

try {
Expand All @@ -2346,7 +2346,7 @@ public function setSIPEnabled(int $state): DataResponse {
* @param int $recordingConsent New consent setting for the conversation
* (Only {@see RecordingService::CONSENT_REQUIRED_NO} and {@see RecordingService::CONSENT_REQUIRED_YES} are allowed here.)
* @psalm-param RecordingService::CONSENT_REQUIRED_NO|RecordingService::CONSENT_REQUIRED_YES $recordingConsent
* @return DataResponse<Http::STATUS_OK, TalkRoom, array{}>|DataResponse<Http::STATUS_BAD_REQUEST, array{error: 'breakout-room'|'call'|'value'}, array{}>|DataResponse<Http::STATUS_PRECONDITION_FAILED, array<empty>, array{}>
* @return DataResponse<Http::STATUS_OK, TalkRoom, array{}>|DataResponse<Http::STATUS_BAD_REQUEST, array{error: 'breakout-room'|'call'|'value'}, array{}>|DataResponse<Http::STATUS_PRECONDITION_FAILED, array{error: 'config'}, array{}>
*
* 200: Recording consent requirement set successfully
* 400: Setting recording consent requirement is not possible
Expand All @@ -2356,7 +2356,7 @@ public function setSIPEnabled(int $state): DataResponse {
#[RequireLoggedInModeratorParticipant]
public function setRecordingConsent(int $recordingConsent): DataResponse {
if (!$this->talkConfig->isRecordingEnabled()) {
return new DataResponse([], Http::STATUS_PRECONDITION_FAILED);
return new DataResponse(['error' => 'config'], Http::STATUS_PRECONDITION_FAILED);
}

try {
Expand All @@ -2373,7 +2373,7 @@ public function setRecordingConsent(int $recordingConsent): DataResponse {
*
* @param int|null $attendeeId ID of the attendee
* @psalm-param non-negative-int|null $attendeeId
* @return DataResponse<Http::STATUS_OK|Http::STATUS_NOT_FOUND, array<empty>, array{}>
* @return DataResponse<Http::STATUS_OK|Http::STATUS_NOT_FOUND, null, array{}>
*
* 200: Invitation resent successfully
* 404: Attendee not found
Expand All @@ -2389,7 +2389,7 @@ public function resendInvitations(?int $attendeeId): DataResponse {
try {
$participants[] = $this->participantService->getParticipantByAttendeeId($this->room, $attendeeId);
} catch (ParticipantNotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
return new DataResponse(null, Http::STATUS_NOT_FOUND);
}
} else {
$participants = $this->participantService->getParticipantsByActorType($this->room, Attendee::ACTOR_EMAILS);
Expand All @@ -2402,15 +2402,15 @@ public function resendInvitations(?int $attendeeId): DataResponse {
$this->guestManager->sendEmailInvitation($this->room, $participant);
}
}
return new DataResponse();
return new DataResponse(null);
}

/**
* Update message expiration time
*
* @param int $seconds New time
* @psalm-param non-negative-int $seconds
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>|DataResponse<Http::STATUS_BAD_REQUEST, array{error: 'breakout-room'|'type'|'value'}, array{}>
* @return DataResponse<Http::STATUS_OK, TalkRoom, array{}>|DataResponse<Http::STATUS_BAD_REQUEST, array{error: 'breakout-room'|'type'|'value'}, array{}>
*
* 200: Message expiration time updated successfully
* 400: Updating message expiration time is not possible
Expand All @@ -2424,7 +2424,7 @@ public function setMessageExpiration(int $seconds): DataResponse {
return new DataResponse(['error' => $e->getReason()], Http::STATUS_BAD_REQUEST);
}

return new DataResponse();
return new DataResponse($this->formatRoom($this->room, $this->participant));
}

/**
Expand Down Expand Up @@ -2475,7 +2475,7 @@ public function importEmailsAsParticipants(bool $testRun = false): DataResponse
* See "Capability handling in federated conversations" in https://github.com/nextcloud/spreed/issues/10680
* to learn which capabilities should be considered from the local server or from the remote server.
*
* @return DataResponse<Http::STATUS_OK, TalkCapabilities|array<empty>, array{X-Nextcloud-Talk-Hash?: string, X-Nextcloud-Talk-Proxy-Hash?: string}>
* @return DataResponse<Http::STATUS_OK, TalkCapabilities|\stdClass, array{X-Nextcloud-Talk-Hash?: string, X-Nextcloud-Talk-Proxy-Hash?: string}>
*
* 200: Get capabilities successfully
*/
Expand Down Expand Up @@ -2514,9 +2514,12 @@ public function getCapabilities(): DataResponse {
if ($response->getHeaders()['X-Nextcloud-Talk-Hash']) {
$headers['X-Nextcloud-Talk-Proxy-Hash'] = $response->getHeaders()['X-Nextcloud-Talk-Hash'];
}

/** @var TalkCapabilities|\stdClass $data */
$data = !empty($data) ? $data : new \stdClass();
} else {
$capabilities = $this->capabilities->getCapabilities();
$data = $capabilities['spreed'] ?? [];
$data = $capabilities['spreed'] ?? new \stdClass();
$headers['X-Nextcloud-Talk-Hash'] = sha1(json_encode($capabilities));
}

Expand Down
9 changes: 9 additions & 0 deletions lib/Federation/Proxy/TalkV1/Controller/RoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,13 @@ public function getCapabilities(Room $room, Participant $participant): DataRespo

return new DataResponse($data, Http::STATUS_OK, $headers);
}

/**
* @return array<string, mixed>|\stdClass
*/
protected function emptyArray(): array|\stdClass {
// Cheating here to make sure the array is always a
// JSON object on the API, even when there is no entry at all.
return new \stdClass();
}
}
5 changes: 3 additions & 2 deletions lib/Service/ParticipantService.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public function updateNotificationLevel(Participant $participant, int $level): v
Participant::NOTIFY_MENTION,
Participant::NOTIFY_NEVER
], true)) {
throw new \InvalidArgumentException('Invalid notification level');
throw new \InvalidArgumentException('level');
}

$attendee = $participant->getAttendee();
Expand All @@ -283,13 +283,14 @@ public function updateNotificationLevel(Participant $participant, int $level): v
/**
* @param Participant $participant
* @param int $level
* @throws \InvalidArgumentException
*/
public function updateNotificationCalls(Participant $participant, int $level): void {
if (!\in_array($level, [
Participant::NOTIFY_CALLS_OFF,
Participant::NOTIFY_CALLS_ON,
], true)) {
throw new \InvalidArgumentException('Invalid notification level');
throw new \InvalidArgumentException('level');
}

$attendee = $participant->getAttendee();
Expand Down

0 comments on commit db15364

Please sign in to comment.