Store when a user knows another user based on phone number

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2021-03-09 20:32:08 +01:00
parent ebb9f1d16a
commit 3feca65399
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
1 changed files with 22 additions and 0 deletions

View File

@ -49,6 +49,8 @@ use libphonenumber\PhoneNumberUtil;
use OC\Accounts\AccountManager; use OC\Accounts\AccountManager;
use OC\Authentication\Token\RemoteWipe; use OC\Authentication\Token\RemoteWipe;
use OC\HintException; use OC\HintException;
use OC\KnownUser\KnownUser;
use OC\KnownUser\KnownUserMapper;
use OCA\Provisioning_API\FederatedShareProviderFactory; use OCA\Provisioning_API\FederatedShareProviderFactory;
use OCA\Settings\Mailer\NewUserMailHelper; use OCA\Settings\Mailer\NewUserMailHelper;
use OCP\Accounts\IAccountManager; use OCP\Accounts\IAccountManager;
@ -89,6 +91,8 @@ class UsersController extends AUserData {
private $secureRandom; private $secureRandom;
/** @var RemoteWipe */ /** @var RemoteWipe */
private $remoteWipe; private $remoteWipe;
/** @var KnownUserMapper */
private $knownUserMapper;
/** @var IEventDispatcher */ /** @var IEventDispatcher */
private $eventDispatcher; private $eventDispatcher;
@ -107,6 +111,7 @@ class UsersController extends AUserData {
FederatedShareProviderFactory $federatedShareProviderFactory, FederatedShareProviderFactory $federatedShareProviderFactory,
ISecureRandom $secureRandom, ISecureRandom $secureRandom,
RemoteWipe $remoteWipe, RemoteWipe $remoteWipe,
KnownUserMapper $knownUserMapper,
IEventDispatcher $eventDispatcher) { IEventDispatcher $eventDispatcher) {
parent::__construct($appName, parent::__construct($appName,
$request, $request,
@ -125,6 +130,7 @@ class UsersController extends AUserData {
$this->federatedShareProviderFactory = $federatedShareProviderFactory; $this->federatedShareProviderFactory = $federatedShareProviderFactory;
$this->secureRandom = $secureRandom; $this->secureRandom = $secureRandom;
$this->remoteWipe = $remoteWipe; $this->remoteWipe = $remoteWipe;
$this->knownUserMapper = $knownUserMapper;
$this->eventDispatcher = $eventDispatcher; $this->eventDispatcher = $eventDispatcher;
} }
@ -264,9 +270,25 @@ class UsersController extends AUserData {
} }
$matches = []; $matches = [];
$knownUsers = [];
foreach ($userMatches as $phone => $userId) { 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 // 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; $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); return new DataResponse($matches);