Skip to content

Commit

Permalink
fix(federation): Translate federated users from the own instance to l…
Browse files Browse the repository at this point in the history
…ocal users

Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Feb 15, 2024
1 parent a1f3d25 commit 066f395
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
16 changes: 16 additions & 0 deletions lib/Federation/Proxy/TalkV1/ChatService.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@
use OCA\Talk\Participant;
use OCA\Talk\ResponseDefinitions;
use OCA\Talk\Room;
use OCP\Federation\ICloudIdManager;
use OCP\Http\Client\IClientService;
use OCP\IConfig;
use OCP\IUserManager;
use OCP\Security\ITrustedDomainHelper;

/**
* @psalm-import-type TalkChatMentionSuggestion from ResponseDefinitions
Expand All @@ -42,6 +45,9 @@ class ChatService {
public function __construct(
protected IConfig $config,
protected IClientService $clientService,
protected ICloudIdManager $cloudIdManager,
protected IUserManager $userManager,
protected ITrustedDomainHelper $trustedDomainHelper,
) {
}

Expand Down Expand Up @@ -88,6 +94,16 @@ protected function flipLocalAndRemoteSuggestions(array $suggestion): array {
if ($suggestion['source'] === Attendee::ACTOR_USERS) {
$suggestion['source'] = Attendee::ACTOR_FEDERATED_USERS;
$suggestion['id'] .= '@' . $this->room->getRemoteServer();
} elseif ($suggestion['source'] === Attendee::ACTOR_FEDERATED_USERS) {
try {
$cloudId = $this->cloudIdManager->resolveCloudId($suggestion['id']);
if ($this->trustedDomainHelper->isTrustedUrl($cloudId->getRemote())) {
$suggestion['source'] = Attendee::ACTOR_USERS;
$suggestion['id'] = $cloudId->getUser();
$suggestion['label'] = $this->userManager->getDisplayName($cloudId->getUser());
}
} catch (\InvalidArgumentException) {
}
}

return $suggestion;
Expand Down
36 changes: 35 additions & 1 deletion tests/integration/features/federation/chat.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Feature: federation/chat
Given user "participant2" exists
Given user "participant3" exists

Scenario: Get mention suggestions
Scenario: Get mention suggestions (translating local users to federated users)
Given the following "spreed" app config is set
| federation_enabled | yes |
Given user "participant1" creates room "room" (v4)
Expand All @@ -31,3 +31,37 @@ Feature: federation/chat
| calls | all | room |
| federated_users | participant1@{$BASE_URL} | participant1-displayname |
| federated_users | participant3@{$BASE_URL} | participant3-displayname |

Scenario: Get mention suggestions (translating federated users of the same server to local users)
Given the following "spreed" app config is set
| federation_enabled | yes |
Given user "participant1" creates room "room" (v4)
| roomType | 2 |
| roomName | room |
And user "participant1" adds federated_user "participant2" to room "room" with 200 (v4)
And user "participant1" adds federated_user "participant3" to room "room" with 200 (v4)
And user "participant2" has the following invitations (v1)
| remoteServerUrl | remoteToken | state | inviterCloudId | inviterDisplayName |
| LOCAL | room | 0 | participant1@http://localhost:8080 | participant1-displayname |
And user "participant2" accepts invite to room "room" of server "LOCAL" with 200 (v1)
| id | name | type | remoteServer | remoteToken |
| room | room | 2 | LOCAL | room |
And user "participant3" has the following invitations (v1)
| remoteServerUrl | remoteToken | state | inviterCloudId | inviterDisplayName |
| LOCAL | room | 0 | participant1@http://localhost:8080 | participant1-displayname |
And user "participant3" accepts invite to room "room" of server "LOCAL" with 200 (v1)
| id | name | type | remoteServer | remoteToken |
| room | room | 2 | LOCAL | room |
Then user "participant2" is participant of the following rooms (v4)
| id | type |
| room | 2 |
And user "participant1" gets the following candidate mentions in room "room" for "" with 200
| source | id | label |
| calls | all | room |
| federated_users | participant2@{$REMOTE_URL} | participant2@localhost:8180 |
| federated_users | participant3@{$REMOTE_URL} | participant3@localhost:8180 |
And user "participant2" gets the following candidate mentions in room "LOCAL::room" for "" with 200
| source | id | label |
| calls | all | room |
| federated_users | participant1@{$BASE_URL} | participant1-displayname |
| users | participant3 | participant3-displayname |

0 comments on commit 066f395

Please sign in to comment.