Skip to content
Merged
Show file tree
Hide file tree
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
Rename some parameters and methods to make the API more clear
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Mar 10, 2021
commit 61ed57b757201541b2038ccab10b092a77c4fb64
2 changes: 1 addition & 1 deletion apps/provisioning_api/lib/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ public function editUser(string $userId, string $key, string $value): DataRespon
$this->accountManager->updateUser($targetUser, $userAccount, true);

if ($key === IAccountManager::PROPERTY_PHONE) {
$this->knownUserService->deleteKnownUser($targetUser->getUID());
$this->knownUserService->deleteByContactUserId($targetUser->getUID());
}
} catch (\InvalidArgumentException $e) {
throw new OCSException('Invalid ' . $e->getMessage(), 102);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ public function handle(Event $event): void {
$this->service->deleteKnownTo($user->getUID());

// Delete all entries that other users know this user
$this->service->deleteKnownUser($user->getUID());
$this->service->deleteByContactUserId($user->getUID());
}
}
2 changes: 1 addition & 1 deletion apps/settings/lib/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ public function setUserSettings(?string $avatarScope = null,
try {
$data = $this->saveUserSettings($user, $data);
if ($beforeData[IAccountManager::PROPERTY_PHONE]['value'] !== $data[IAccountManager::PROPERTY_PHONE]['value']) {
$this->knownUserService->deleteKnownUser($user->getUID());
$this->knownUserService->deleteByContactUserId($user->getUID());
}
return new DataResponse(
[
Expand Down
4 changes: 3 additions & 1 deletion lib/private/KnownUser/KnownUserMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ public function deleteKnownUser(string $knownUser): int {
}

/**
* Returns all "known users" for the given "known to" user
*
* @param string $knownTo
* @return KnownUser[]
*/
public function getKnownTo(string $knownTo): array {
public function getKnownUsers(string $knownTo): array {
$query = $this->db->getQueryBuilder();
$query->select('*')
->from($this->getTableName())
Expand Down
39 changes: 32 additions & 7 deletions lib/private/KnownUser/KnownUserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,55 @@ public function __construct(KnownUserMapper $mapper) {
$this->mapper = $mapper;
}

/**
* Delete all matches where the given user is the owner of the phonebook
*
* @param string $knownTo
* @return int Number of deleted matches
*/
public function deleteKnownTo(string $knownTo): int {
return $this->mapper->deleteKnownTo($knownTo);
}

public function deleteKnownUser(string $knownUser): int {
return $this->mapper->deleteKnownUser($knownUser);
/**
* Delete all matches where the given user is the one in the phonebook
*
* @param string $contactUserId
* @return int Number of deleted matches
*/
public function deleteByContactUserId(string $contactUserId): int {
return $this->mapper->deleteKnownUser($contactUserId);
}

public function storeIsKnownToUser(string $knownTo, string $knownUser): void {
/**
* Store a match because $knownTo has $contactUserId in his phonebook
*
* @param string $knownTo User id of the owner of the phonebook
* @param string $contactUserId User id of the contact in the phonebook
*/
public function storeIsKnownToUser(string $knownTo, string $contactUserId): void {
$entity = new KnownUser();
$entity->setKnownTo($knownTo);
$entity->setKnownUser($knownUser);
$entity->setKnownUser($contactUserId);
$this->mapper->insert($entity);
}

public function isKnownToUser(string $knownTo, string $user): bool {
/**
* Check if $contactUserId is in the phonebook of $knownTo
*
* @param string $knownTo User id of the owner of the phonebook
* @param string $contactUserId User id of the contact in the phonebook
* @return bool
*/
public function isKnownToUser(string $knownTo, string $contactUserId): bool {
if (!isset($this->knownUsers[$knownTo])) {
$entities = $this->mapper->getKnownTo($knownTo);
$entities = $this->mapper->getKnownUsers($knownTo);
$this->knownUsers[$knownTo] = [];
foreach ($entities as $entity) {
$this->knownUsers[$knownTo][$entity->getKnownUser()] = true;
}
}

return isset($this->knownUsers[$knownTo][$user]);
return isset($this->knownUsers[$knownTo][$contactUserId]);
}
}