Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 61 additions & 2 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Http\Template\PublicTemplateResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Http\TooManyRequestsResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\Collaboration\Reference\RenderReferenceEvent;
use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent;
Expand All @@ -64,9 +65,14 @@
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\Notification\IManager as INotificationManager;
use OCP\Profile\IProfileManager;
use OCP\Security\Bruteforce\IThrottler;
use OCP\Security\RateLimiting\ILimiter;
use OCP\Security\RateLimiting\IRateLimitExceededException;
use Psr\Log\LoggerInterface;

#[IgnoreOpenAPI]
Expand Down Expand Up @@ -95,6 +101,10 @@ public function __construct(
Config $talkConfig,
IConfig $serverConfig,
IGroupManager $groupManager,
protected IUserManager $userManager,
protected IProfileManager $profileManager,
protected ILimiter $limiter,
protected IFactory $l10nFactory,
) {
parent::__construct($appName, $request);
$this->initialState = $initialState;
Expand Down Expand Up @@ -148,7 +158,7 @@ public function duplicateSession(): Response {
/**
* @param string $token
* @param string $callUser
* @return TemplateResponse|RedirectResponse
* @return TemplateResponse|RedirectResponse|TooManyRequestsResponse
* @throws HintException
*/
#[NoCSRFRequired]
Expand All @@ -162,17 +172,66 @@ public function index(string $token = '', string $callUser = ''): Response {
return $this->pageHandler($token, $callUser);
}

/**
* @throws \InvalidArgumentException
*/
protected function createContactRequestRoom(string $targetUserId): Room {
$user = $this->userManager->get($targetUserId);
if (!$user instanceof IUser) {
throw new \InvalidArgumentException('user');
}

if ($this->talkConfig->isNotAllowedToCreateConversations($user)) {
throw new \InvalidArgumentException('config');
}

if (!$this->profileManager->isProfileFieldVisible('talk', $user, null)) {
throw new \InvalidArgumentException('profile');
}

$l = $this->l10nFactory->get('spreed', $this->l10nFactory->getUserLanguage($user));

return $this->roomService->createConversation(
Room::TYPE_PUBLIC,
$l->t('Contact request'),
$user,
);
}

/**
* @param string $token
* @param string $callUser
* @param string $password
* @return TemplateResponse|RedirectResponse
* @return TemplateResponse|RedirectResponse|TooManyRequestsResponse
* @throws HintException
*/
protected function pageHandler(string $token = '', string $callUser = '', string $password = ''): Response {
$bruteForceToken = $token;
$user = $this->userSession->getUser();
if (!$user instanceof IUser) {
if ($token === '') {
try {
$this->limiter->registerAnonRequest(
'create-anonymous-conversation',
5, // Five conversations
60 * 60, // Per hour
$this->request->getRemoteAddress(),
);
} catch (IRateLimitExceededException) {
return new TooManyRequestsResponse();
}

try {
$room = $this->createContactRequestRoom($callUser);
} catch (\InvalidArgumentException) {
$response = new TemplateResponse('core', '404-profile', [], TemplateResponse::RENDER_AS_GUEST);
$response->throttle(['action' => 'callUser', 'callUser' => $callUser]);
return $response;
}

return $this->redirectToConversation($room->getToken());
}

return $this->guestEnterRoom($token, $password);
}

Expand Down
21 changes: 14 additions & 7 deletions lib/Profile/TalkAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ public function getDisplayId(): string {

public function getTitle(): string {
$visitingUser = $this->userSession->getUser();
if (!$visitingUser || $visitingUser === $this->targetUser) {
if ($visitingUser === $this->targetUser) {
return $this->l->t('Open Talk');
}

return $this->l->t('Talk to %s', [$this->targetUser->getDisplayName()]);
}

Expand All @@ -78,17 +79,23 @@ public function getIcon(): string {
}

public function getTarget(): ?string {
$visitingUser = $this->userSession->getUser();
if (
!$visitingUser
|| $this->config->isDisabledForUser($this->targetUser)
|| $this->config->isDisabledForUser($visitingUser)
) {
if ($this->config->isDisabledForUser($this->targetUser)) {
return null;
}

$visitingUser = $this->userSession->getUser();
if ($visitingUser === $this->targetUser) {
return $this->urlGenerator->linkToRouteAbsolute('spreed.Page.index');
}

if ($visitingUser && $this->config->isDisabledForUser($visitingUser)) {
return null;
}

if (!$visitingUser && $this->config->isNotAllowedToCreateConversations($this->targetUser)) {
return null;
}

return $this->urlGenerator->linkToRouteAbsolute('spreed.Page.index') . '?callUser=' . $this->targetUser->getUID();
}
}