Browse Source

Return status of other user on one to one room

Signed-off-by: Vitor Mattos <vitor@php.rio>
pull/8773/head
Vitor Mattos 3 years ago
parent
commit
2cd61fc9d9
  1. 1
      docs/capabilities.md
  2. 1
      lib/Capabilities.php
  3. 19
      lib/Controller/RoomController.php
  4. 23
      tests/integration/features/bootstrap/FeatureContext.php
  5. 17
      tests/integration/features/chat/one-to-one.feature
  6. 1
      tests/php/CapabilitiesTest.php

1
docs/capabilities.md

@ -113,3 +113,4 @@ title: Capabilities
* `chat-get-context` - Whether the message context API endpoint is available
* `config => call => breakout-rooms` - Whether breakout rooms are enabled on this instance
* `config => call => recording` - Whether calls can be recorded (requires the High-performance backend server)
* `single-conversation-status` - When the response of a single consersation return user status populated

1
lib/Capabilities.php

@ -116,6 +116,7 @@ class Capabilities implements IPublicCapability {
'recording-v1',
'avatar',
'chat-get-context',
'single-conversation-status'
],
'config' => [
'attachments' => [

19
lib/Controller/RoomController.php

@ -332,8 +332,25 @@ class RoomController extends AEnvironmentAwareController {
} catch (ParticipantNotFoundException $e) {
}
}
$statuses = [];
if ($this->userId !== null
&& $this->appManager->isEnabledForUser('user_status')) {
$userIds = array_filter(array_map(function (Room $room) {
if ($room->getType() === Room::TYPE_ONE_TO_ONE) {
$participants = json_decode($room->getName(), true);
foreach ($participants as $participant) {
if ($participant !== $this->userId) {
return $participant;
}
}
}
return null;
}, [$room]));
$statuses = $this->statusManager->getUserStatuses($userIds);
}
return new DataResponse($this->formatRoom($room, $participant, [], $isSIPBridgeRequest), Http::STATUS_OK, $this->getTalkHashHeader());
return new DataResponse($this->formatRoom($room, $participant, $statuses, $isSIPBridgeRequest), Http::STATUS_OK, $this->getTalkHashHeader());
} catch (RoomNotFoundException $e) {
$response = new DataResponse([], Http::STATUS_NOT_FOUND);
$response->throttle(['token' => $token]);

23
tests/integration/features/bootstrap/FeatureContext.php

@ -1175,10 +1175,18 @@ class FeatureContext implements Context, SnippetAcceptingContext {
* @param int $statusCode
* @param string $apiVersion
*/
public function userGetsRoom(string $user, string $identifier, int $statusCode, string $apiVersion): void {
public function userGetsRoom(string $user, string $identifier, int $statusCode, string $apiVersion = 'v4', TableNode $formData = null): void {
$this->setCurrentUser($user);
$this->sendRequest('GET', '/apps/spreed/api/' . $apiVersion . '/room/' . self::$identifierToToken[$identifier]);
$this->assertStatusCode($this->response, $statusCode);
if ($formData instanceof TableNode) {
$xpectedAttributes = $formData->getColumnsHash()[0];
$actual = $this->getDataFromResponse($this->response);
foreach ($xpectedAttributes as $attribute => $expectedValue) {
Assert::assertEquals($expectedValue, $actual[$attribute]);
}
}
}
/**
@ -3254,6 +3262,19 @@ class FeatureContext implements Context, SnippetAcceptingContext {
$this->assertStatusCode($this->response, $statusCode);
}
/**
* @When /^user "([^"]*)" set status to "([^"]*)" with (\d+)(?: \((v1)\))?$/
*/
public function setUserStatus(string $user, string $status, int $statusCode, string $apiVersion = 'v1'): void {
$this->setCurrentUser($user);
$this->sendRequest(
'PUT',
'/apps/user_status/api/' . $apiVersion . '/user_status/status',
new TableNode([['statusType', $status]])
);
$this->assertStatusCode($this->response, $statusCode);
}
/**
* @Then the response error matches with :error
*/

17
tests/integration/features/chat/one-to-one.feature

@ -67,3 +67,20 @@ Feature: chat/one-to-one
Then user "participant1" sees the following messages in room "one-to-one room" with 200
| room | actorType | actorId | actorDisplayName | message | messageParameters |
| one-to-one room | users | participant2 | participant2-displayname | Message | [] |
Scenario: Return user status when get single conversation
Given user "participant1" creates room "one-to-one room" (v4)
| roomType | 1 |
| invite | participant2 |
When user "participant2" set status to "online" with 200 (v1)
Then user "participant1" gets room "one-to-one room" with 200 (v4)
| status |
| online |
When user "participant2" set status to "offline" with 200 (v1)
Then user "participant1" gets room "one-to-one room" with 200 (v4)
| status |
| offline |
Then user "participant2" set status to "away" with 200 (v1)
Then user "participant1" gets room "one-to-one room" with 200 (v4)
| status |
| away |

1
tests/php/CapabilitiesTest.php

@ -125,6 +125,7 @@ class CapabilitiesTest extends TestCase {
'recording-v1',
'avatar',
'chat-get-context',
'single-conversation-status',
'message-expiration',
'reactions',
];

Loading…
Cancel
Save