Store when a user knows another user based on phone number
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
ebb9f1d16a
commit
3feca65399
|
@ -49,6 +49,8 @@ use libphonenumber\PhoneNumberUtil;
|
|||
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;
|
||||
|
@ -89,6 +91,8 @@ class UsersController extends AUserData {
|
|||
private $secureRandom;
|
||||
/** @var RemoteWipe */
|
||||
private $remoteWipe;
|
||||
/** @var KnownUserMapper */
|
||||
private $knownUserMapper;
|
||||
/** @var IEventDispatcher */
|
||||
private $eventDispatcher;
|
||||
|
||||
|
@ -107,6 +111,7 @@ class UsersController extends AUserData {
|
|||
FederatedShareProviderFactory $federatedShareProviderFactory,
|
||||
ISecureRandom $secureRandom,
|
||||
RemoteWipe $remoteWipe,
|
||||
KnownUserMapper $knownUserMapper,
|
||||
IEventDispatcher $eventDispatcher) {
|
||||
parent::__construct($appName,
|
||||
$request,
|
||||
|
@ -125,6 +130,7 @@ class UsersController extends AUserData {
|
|||
$this->federatedShareProviderFactory = $federatedShareProviderFactory;
|
||||
$this->secureRandom = $secureRandom;
|
||||
$this->remoteWipe = $remoteWipe;
|
||||
$this->knownUserMapper = $knownUserMapper;
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
}
|
||||
|
||||
|
@ -264,9 +270,25 @@ class UsersController extends AUserData {
|
|||
}
|
||||
|
||||
$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);
|
||||
|
|
Loading…
Reference in New Issue