Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix contact photos after #32057 #36110

Closed
wants to merge 2 commits into from
Closed
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
21 changes: 12 additions & 9 deletions lib/private/Contacts/ContactsMenu/ContactsStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ public function getContacts(IUser $user, ?string $filter, ?int $limit = null, ?i
$userId = $user->getUID();
$contacts = array_filter($allContacts, function ($contact) use ($userId) {
// When searching for multiple results, we strip out the current user
if (array_key_exists('X-NEXTCLOUD-UID', $contact)) {
return $contact['X-NEXTCLOUD-UID'] !== $userId;
}
if (array_key_exists('UID', $contact)) {
return $contact['UID'] !== $userId;
}
Expand Down Expand Up @@ -239,7 +242,7 @@ public function findOne(IUser $user, int $shareType, string $shareWith): ?IEntry
switch ($shareType) {
case 0:
case 6:
$filter = ['UID'];
$filter = ['X-NEXTCLOUD-UID', 'UID'];
break;
case 4:
$filter = ['EMAIL'];
Expand All @@ -262,7 +265,8 @@ public function findOne(IUser $user, int $shareType, string $shareWith): ?IEntry
}
if ($shareType === 0 || $shareType === 6) {
$isLocal = $contact['isLocalSystemBook'] ?? false;
if ($contact['UID'] === $shareWith && $isLocal === true) {
$uid = $contact['X-NEXTCLOUD-UID'] ?? ($contact['UID'] ?? null);
if ($uid === $shareWith && $isLocal === true) {
$match = $contact;
break;
}
Expand All @@ -284,8 +288,8 @@ public function findOne(IUser $user, int $shareType, string $shareWith): ?IEntry
private function contactArrayToEntry(array $contact): Entry {
$entry = new Entry();

if (isset($contact['UID'])) {
$uid = $contact['UID'];
$uid = $contact['X-NEXTCLOUD-UID'] ?? ($contact['UID'] ?? null);
if ($uid !== null) {
$entry->setId($uid);
$avatar = $this->urlGenerator->linkToRouteAbsolute('core.avatar.getAvatar', ['userId' => $uid, 'size' => 64]);
$entry->setAvatar($avatar);
Expand All @@ -307,13 +311,12 @@ private function contactArrayToEntry(array $contact): Entry {
}

// Provide profile parameters for core/src/OC/contactsmenu/contact.handlebars template
if (isset($contact['UID']) && isset($contact['FN'])) {
$targetUserId = $contact['UID'];
$targetUser = $this->userManager->get($targetUserId);
if (!empty($targetUser)) {
if ($uid !== null && isset($contact['FN'])) {
$targetUser = $this->userManager->get($uid);
if ($targetUser instanceof IUser) {
if ($this->profileManager->isProfileEnabled($targetUser)) {
$entry->setProfileTitle($this->l10nFactory->get('lib')->t('View profile'));
$entry->setProfileUrl($this->urlGenerator->linkToRouteAbsolute('core.ProfilePage.index', ['targetUserId' => $targetUserId]));
$entry->setProfileUrl($this->urlGenerator->linkToRouteAbsolute('core.ProfilePage.index', ['targetUserId' => $uid]));
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions lib/private/Contacts/ContactsMenu/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ private function sortActions(): void {
* @param array $contact key-value array containing additional properties
*/
public function setProperties(array $contact): void {
if (isset($contact['X-NEXTCLOUD-UID'])) {
$contact['UID'] = $contact['X-NEXTCLOUD-UID'];
unset($contact['X-NEXTCLOUD-UID']);
}
$this->properties = $contact;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use OCP\IConfig;
use OCP\IDateTimeFormatter;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
use OCP\L10N\IFactory as IL10NFactory;

Expand Down Expand Up @@ -68,8 +69,12 @@ public function __construct(
*/
public function process(IEntry $entry) {
$targetUserId = $entry->getProperty('UID');
if ($targetUserId === null) {
return;
}

$targetUser = $this->userManager->get($targetUserId);
if (!empty($targetUser)) {
if ($targetUser instanceof IUser) {
$timezone = $this->config->getUserValue($targetUser->getUID(), 'core', 'timezone') ?: date_default_timezone_get();
$dateTimeZone = new \DateTimeZone($timezone);
$localTime = $this->dateTimeFormatter->formatTime($this->timeFactory->getDateTime(), 'short', $dateTimeZone);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use OCP\Contacts\ContactsMenu\IEntry;
use OCP\Contacts\ContactsMenu\IProvider;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
use OCP\L10N\IFactory as IL10NFactory;

Expand Down Expand Up @@ -58,8 +59,12 @@ public function __construct(
*/
public function process(IEntry $entry) {
$targetUserId = $entry->getProperty('UID');
if ($targetUserId === null) {
return;
}

$targetUser = $this->userManager->get($targetUserId);
if (!empty($targetUser)) {
if ($targetUser instanceof IUser) {
if ($this->profileManager->isProfileEnabled($targetUser)) {
$iconUrl = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/profile.svg'));
$profileActionText = $this->l10nFactory->get('lib')->t('View profile');
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ public function testFindOneUser() {
$user = $this->createMock(IUser::class);
$this->contactsManager->expects($this->once())
->method('search')
->with($this->equalTo('a567'), $this->equalTo(['UID']))
->with($this->equalTo('a567'), $this->equalTo(['X-NEXTCLOUD-UID', 'UID']))
->willReturn([
[
'UID' => 123,
Expand Down Expand Up @@ -942,7 +942,7 @@ public function testFindOneNoMatches() {
$user = $this->createMock(IUser::class);
$this->contactsManager->expects($this->once())
->method('search')
->with($this->equalTo('a567'), $this->equalTo(['UID']))
->with($this->equalTo('a567'), $this->equalTo(['X-NEXTCLOUD-UID', 'UID']))
->willReturn([
[
'UID' => 123,
Expand Down