Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Store when a user knows another user based on phone number
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Mar 11, 2021
commit 3feca65399d1d4d1183d6c052eae815d5b9cdc77
22 changes: 22 additions & 0 deletions apps/provisioning_api/lib/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
use OC\Accounts\AccountManager;
use OC\Authentication\Token\RemoteWipe;
use OC\HintException;
use OC\KnownUser\KnownUser;
use OC\KnownUser\KnownUserMapper;
use OCA\Provisioning_API\FederatedShareProviderFactory;
use OCA\Settings\Mailer\NewUserMailHelper;
use OCP\Accounts\IAccountManager;
Expand Down Expand Up @@ -89,6 +91,8 @@ class UsersController extends AUserData {
private $secureRandom;
/** @var RemoteWipe */
private $remoteWipe;
/** @var KnownUserMapper */
private $knownUserMapper;
/** @var IEventDispatcher */
private $eventDispatcher;

Expand All @@ -107,6 +111,7 @@ public function __construct(string $appName,
FederatedShareProviderFactory $federatedShareProviderFactory,
ISecureRandom $secureRandom,
RemoteWipe $remoteWipe,
KnownUserMapper $knownUserMapper,
IEventDispatcher $eventDispatcher) {
parent::__construct($appName,
$request,
Expand All @@ -125,6 +130,7 @@ public function __construct(string $appName,
$this->federatedShareProviderFactory = $federatedShareProviderFactory;
$this->secureRandom = $secureRandom;
$this->remoteWipe = $remoteWipe;
$this->knownUserMapper = $knownUserMapper;
$this->eventDispatcher = $eventDispatcher;
}

Expand Down Expand Up @@ -264,9 +270,25 @@ public function searchByPhoneNumbers(string $location, array $search): DataRespo
}

$matches = [];
$knownUsers = [];
foreach ($userMatches as $phone => $userId) {
// Not using the ICloudIdManager as that would run a search for each contact to find the display name in the address book
$matches[$normalizedNumberToKey[$phone]] = $userId . '@' . $cloudUrl;
$knownUsers[] = $userId;
}

/** @var IUser $user */
$user = $this->userSession->getUser();
$knownTo = $user->getUID();

// Cleanup all previous entries and only allow new matches
$this->knownUserMapper->deleteKnownTo($knownTo);

foreach ($knownUsers as $knownUser) {
$entity = new KnownUser();
$entity->setKnownTo($knownTo);
$entity->setKnownUser($knownUser);
$this->knownUserMapper->insert($entity);
}

return new DataResponse($matches);
Expand Down