Browse Source

Add an endpoint to set the notification level

Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/1230/head
Joas Schilling 7 years ago
parent
commit
e3d985da60
No known key found for this signature in database GPG Key ID: 7076EA9751AACDDA
  1. 9
      appinfo/routes.php
  2. 18
      docs/api-v1.md
  3. 45
      lib/Controller/RoomController.php

9
appinfo/routes.php

@ -307,6 +307,15 @@ return [
'token' => '^[a-z0-9]{4,30}$',
],
],
[
'name' => 'Room#setNotificationLevel',
'url' => '/api/{apiVersion}/room/{token}/notify',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v1',
'token' => '^[a-z0-9]{4,30}$',
],
],
/**

18
docs/api-v1.md

@ -13,6 +13,7 @@
* [Disallow guests in a room (group room)](#disallow-guests-in-a-room-group-room)
* [Add room to favorites](#add-room-to-favorites)
* [Remove room from favorites](#remove-room-from-favorites)
* [Set notification level](#set-notification-level)
- [Participant management](#participant-management)
* [Get list of participants in a room](#get-list-of-participants-in-a-room)
* [Add a participant to a room](#add-a-participant-to-a-room)
@ -140,6 +141,7 @@ Base endpoint is: `/ocs/v2.php/apps/spreed/api/v1`
`hasCall` | bool | Flag if the room has an active call
`lastActivity` | int | Timestamp of the last activity in the room, in seconds and UTC time zone
`isFavorite` | bool | Flag if the room is favorited by the user
`notificationLevel` | int | The notification level for the user (one of `Participant::NOTIFY_*` (1-3))
`unreadMessages` | int | Number of unread chat messages in the room (only available with `chat-v2` capability)
`unreadMention` | bool | Flag if the user was mentioned since their last visit
`lastMessage` | message | Last message in a room if available, otherwise empty
@ -262,6 +264,22 @@ Base endpoint is: `/ocs/v2.php/apps/spreed/api/v1`
+ `200 OK`
+ `404 Not Found` When the room could not be found for the participant or the participant is a guest
### Set notification level
* Method: `POST`
* Endpoint: `/room/{token}/notify`
* Data:
field | type | Description
------|------|------------
`level` | int | The notification level (one of `Participant::NOTIFY_*` (1-3))
* Response:
- Header:
+ `200 OK`
+ `400 Bad Request` When the the given level is invalid
+ `404 Not Found` When the room could not be found for the participant or the participant is a guest
## Participant management
### Get list of participants in a room

45
lib/Controller/RoomController.php

@ -208,23 +208,23 @@ class RoomController extends OCSController {
'unreadMessages' => 0,
'unreadMention' => false,
'isFavorite' => $favorite,
'notificationLevel' => $room->getType() === Room::ONE_TO_ONE_CALL ? Participant::NOTIFY_ALWAYS : Participant::NOTIFY_MENTION,
'lastPing' => 0,
'sessionId' => '0',
'participants' => [],
'numGuests' => 0,
'guestList' => '',
'lastMessage' => [],
];
if (!$participant instanceof Participant) {
// Unauthenticated user without a session (didn't enter password)
$roomData = array_merge($roomData, [
'lastPing' => 0,
'sessionId' => '0',
'participants' => [],
'numGuests' => 0,
'hasCall' => false,
'guestList' => '',
'lastMessage' => [],
]);
return $roomData;
}
if ($participant->getNotificationLevel() !== Participant::NOTIFY_DEFAULT) {
$roomData['notificationLevel'] = $participant->getNotificationLevel();
}
if ($room->getObjectType() === 'share:password') {
// FIXME use an event
$roomData['displayName'] = $this->l10n->t('Password request by %s', [$room->getName()]);
@ -588,6 +588,29 @@ class RoomController extends OCSController {
return new DataResponse([]);
}
/**
* @NoAdminRequired
*
* @param string $token
* @param int $level
* @return DataResponse
*/
public function setNotificationLevel(string $token, int $level): DataResponse {
try {
$room = $this->manager->getRoomForParticipantByToken($token, $this->userId);
$currentParticipant = $room->getParticipant($this->userId);
} catch (RoomNotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
} catch (ParticipantNotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
if (!$currentParticipant->setNotificationLevel($level)) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
return new DataResponse();
}
/**
* @PublicPage

Loading…
Cancel
Save