Skip to content
Draft
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
29 changes: 25 additions & 4 deletions lib/Controller/RoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2582,12 +2582,26 @@ public function directDialIn(string $phoneNumber, string $caller): DataResponse
try {
$entity = $this->phoneService->getAccountToCallForPhoneNumber($phoneNumber);
} catch (DoesNotExistException) {
$this->logger->info('No account found for direct dial-in with number: ' . $phoneNumber);
return new DataResponse(null, Http::STATUS_NOT_FOUND);
$dialoutPrefix = $this->appConfig->getAppValueString('sip_bridge_dialout_prefix', '+');

if ($dialoutPrefix === '') {
$this->logger->info('No account found for direct dial-in with number: ' . $phoneNumber);
return new DataResponse(null, Http::STATUS_NOT_FOUND);
}

try {
// Try to find the number with added dialout prefix as a fallback for old sip-bridges
// TODO: Log as error in 26, remove fallback and dialout prefix with 27
$entity = $this->phoneService->getAccountToCallForPhoneNumber($dialoutPrefix . $phoneNumber);
} catch (DoesNotExistException) {
$this->logger->info('No account found for direct dial-in with number: ' . $phoneNumber);
return new DataResponse(null, Http::STATUS_NOT_FOUND);
}

$this->logger->warning('Found account for direct dial-in only by adding the dial-out prefix. Please adjust the mapping for number: ' . $phoneNumber);
}

$caller = trim($caller);
// TODO: Use later and get name from addressbook? $cleanedCaller = $this->phoneNumberUtil->convertToStandardFormat($caller);
$user = $this->userManager->get($entity->getActorId());
try {
$room = $this->roomService->createConversation(
Expand All @@ -2603,7 +2617,14 @@ public function directDialIn(string $phoneNumber, string $caller): DataResponse
return new DataResponse(null, Http::STATUS_INTERNAL_SERVER_ERROR);
}

$participant = $this->participantService->joinRoomAsNewGuest($this->roomService, $room, '', true, displayName: $caller);
$participant = $this->participantService->joinRoomAsNewGuest(
$this->roomService,
$room,
'',
true,
displayName: $caller,
phoneNumber: $caller,
);
return new DataResponse($this->formatRoom($room, $participant));
}

Expand Down
55 changes: 55 additions & 0 deletions lib/Migration/Version25000Date20260918142246.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Talk\Migration;

use Closure;
use OCP\AppFramework\Services\IAppConfig;
use OCP\DB\ISchemaWrapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
use Override;

class Version25000Date20260918142246 extends SimpleMigrationStep {

public function __construct(
private readonly IDBConnection $connection,
private readonly IAppConfig $appConfig,
) {
}

/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
*/
#[Override]
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
$dialoutPrefix = $this->appConfig->getAppValueString('sip_bridge_dialout_prefix', '+');

if ($dialoutPrefix === '') {
return;
}

$update = $this->connection->getQueryBuilder();
$update->update('talk_phone_numbers')
->set('phone_number', $update->func()->concat(
$update->createNamedParameter($dialoutPrefix, IQueryBuilder::PARAM_STR),
'phone_number',
))
->where($update->expr()->gte(
$update->func()->charLength('phone_number'),
$update->createNamedParameter(6, IQueryBuilder::PARAM_INT))
);

$update->executeStatement();
}
}
6 changes: 5 additions & 1 deletion lib/Service/ParticipantService.php
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ public function joinRoomAsFederatedUser(Room $room, string $actorType, string $a
* @throws InvalidPasswordException
* @throws UnauthorizedException
*/
public function joinRoomAsNewGuest(RoomService $roomService, Room $room, string $password, bool $passedPasswordProtection = false, ?Participant $previousParticipant = null, ?string $displayName = null): Participant {
public function joinRoomAsNewGuest(RoomService $roomService, Room $room, string $password, bool $passedPasswordProtection = false, ?Participant $previousParticipant = null, ?string $displayName = null, ?string $phoneNumber = null): Participant {
$event = new BeforeGuestJoinedRoomEvent($room, $password, $passedPasswordProtection);
$this->dispatcher->dispatchTyped($event);

Expand Down Expand Up @@ -635,6 +635,10 @@ public function joinRoomAsNewGuest(RoomService $roomService, Room $room, string
if ($displayName !== null && $displayName !== '') {
$attendee->setDisplayName($displayName);
}
if ($phoneNumber !== null && $phoneNumber !== '') {
$attendee->setPhoneNumber($phoneNumber);
$attendee->setActorType(Attendee::ACTOR_PHONES);
}

$this->attendeeMapper->insert($attendee);

Expand Down
10 changes: 2 additions & 8 deletions lib/Service/PhoneNumberValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ public function __construct(
* Validate input as a phone number
*
* - Local number: allow
* - International number
* a. If valid, strip + and allow
* b. If invalid, throw
* - International number: If invalid, throw
* @throws \InvalidArgumentException When the number is invalid
*/
public function validateNumber(string $phoneNumber): string {
Expand All @@ -46,10 +44,6 @@ public function validateNumber(string $phoneNumber): string {
throw new \InvalidArgumentException();
}

if (str_starts_with($standardPhoneNumber, '+')) {
return substr($standardPhoneNumber, 1);
}

throw new \InvalidArgumentException();
return $standardPhoneNumber;
}
}
8 changes: 5 additions & 3 deletions lib/SetupCheck/SIPConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ public function run(): SetupResult {
$query->select('phone_number')
->from('talk_phone_numbers')
->where($query->expr()->like('phone_number', $query->createNamedParameter(
$this->connection->escapeLikeParameter('+') . '%'
)))
->orWhere($query->expr()->like('phone_number', $query->createNamedParameter(
// TODO: Temporary disabled while we migrate to leading `+` for international numbers
// TODO: Either to be deleted later or should complain for numbers without it
// $this->connection->escapeLikeParameter('+') . '%'
// )))
// ->orWhere($query->expr()->like('phone_number', $query->createNamedParameter(
$this->connection->escapeLikeParameter('0') . '%'
)));

Expand Down
Loading