Skip to content

Commit

Permalink
fix(contactsMenu): Attach user cloud to each contact entry
Browse files Browse the repository at this point in the history
The contact entry should carry cloud information, this can help to fix various issues including:

- Displaying correct avatar links for federated users

This can also lead to UI improvements in the frontend where, it's federated contacts are shown with
a marker or indicator on the UI.

Signed-off-by: fenn-cs <[email protected]>
  • Loading branch information
nfebe committed Apr 22, 2024
1 parent ea1b0a0 commit fe83f91
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 30 deletions.
72 changes: 42 additions & 30 deletions lib/private/Contacts/ContactsMenu/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,29 @@

use OCP\Contacts\ContactsMenu\IAction;
use OCP\Contacts\ContactsMenu\IEntry;
use OC\Federation\CloudId;
use function array_merge;

class Entry implements IEntry {
public const PROPERTY_STATUS_MESSAGE_TIMESTAMP = 'statusMessageTimestamp';

/** @var string|int|null */
private $id = null;
public function __construct(
private ?string $id = null,
private string $fullName = '',
private array $emailAddresses = [],
private ?string $avatar = null,
private ?string $profileTitle = null,
private ?string $profileUrl = null,
private array $actions = [],
private array $properties = [],
private ?string $status = null,
private ?string $statusMessage = null,
private ?int $statusMessageTimestamp = null,
private ?string $statusIcon = null,
private ?bool $isFederated = false,
private ?CloudId $cloud = null
) {}

private string $fullName = '';

/** @var string[] */
private array $emailAddresses = [];

private ?string $avatar = null;

private ?string $profileTitle = null;

private ?string $profileUrl = null;

/** @var IAction[] */
private array $actions = [];

private array $properties = [];

private ?string $status = null;
private ?string $statusMessage = null;
private ?int $statusMessageTimestamp = null;
private ?string $statusIcon = null;

public function setId(string $id): void {
$this->id = $id;
Expand Down Expand Up @@ -163,6 +158,31 @@ public function getProperty(string $key): mixed {
return $this->properties[$key];
}


public function getStatusMessage(): ?string {
return $this->statusMessage;
}

public function getStatusMessageTimestamp(): ?int {
return $this->statusMessageTimestamp;
}

public function setIsFederated(bool $isFed) {
$this->isFederated = $isFed;
}

public function getIsFederated(): bool {

Check failure

Code scanning / Psalm

InvalidNullableReturnType Error

The declared return type 'bool' for OC\Contacts\ContactsMenu\Entry::getIsFederated is not nullable, but 'bool|null' contains null

Check failure on line 174 in lib/private/Contacts/ContactsMenu/Entry.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidNullableReturnType

lib/private/Contacts/ContactsMenu/Entry.php:174:36: InvalidNullableReturnType: The declared return type 'bool' for OC\Contacts\ContactsMenu\Entry::getIsFederated is not nullable, but 'bool|null' contains null (see https://psalm.dev/144)
return $this->isFederated;

Check failure

Code scanning / Psalm

NullableReturnStatement Error

The declared return type 'bool' for OC\Contacts\ContactsMenu\Entry::getIsFederated is not nullable, but the function returns 'bool|null'

Check failure on line 175 in lib/private/Contacts/ContactsMenu/Entry.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

NullableReturnStatement

lib/private/Contacts/ContactsMenu/Entry.php:175:10: NullableReturnStatement: The declared return type 'bool' for OC\Contacts\ContactsMenu\Entry::getIsFederated is not nullable, but the function returns 'bool|null' (see https://psalm.dev/139)
}

public function setCloudId(CloudId $cloudId) {
$this->cloud = $cloudId;
}

public function getCloud(): CloudId {

Check failure

Code scanning / Psalm

InvalidNullableReturnType Error

The declared return type 'OC\Federation\CloudId' for OC\Contacts\ContactsMenu\Entry::getCloud is not nullable, but 'OC\Federation\CloudId|null' contains null

Check failure on line 182 in lib/private/Contacts/ContactsMenu/Entry.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidNullableReturnType

lib/private/Contacts/ContactsMenu/Entry.php:182:30: InvalidNullableReturnType: The declared return type 'OC\Federation\CloudId' for OC\Contacts\ContactsMenu\Entry::getCloud is not nullable, but 'OC\Federation\CloudId|null' contains null (see https://psalm.dev/144)
return $this->cloud;

Check failure

Code scanning / Psalm

NullableReturnStatement Error

The declared return type 'OC\Federation\CloudId' for OC\Contacts\ContactsMenu\Entry::getCloud is not nullable, but the function returns 'OC\Federation\CloudId|null'

Check failure on line 183 in lib/private/Contacts/ContactsMenu/Entry.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

NullableReturnStatement

lib/private/Contacts/ContactsMenu/Entry.php:183:10: NullableReturnStatement: The declared return type 'OC\Federation\CloudId' for OC\Contacts\ContactsMenu\Entry::getCloud is not nullable, but the function returns 'OC\Federation\CloudId|null' (see https://psalm.dev/139)
}

/**
* @return array{id: int|string|null, fullName: string, avatar: string|null, topAction: mixed, actions: array, lastMessage: '', emailAddresses: string[], profileTitle: string|null, profileUrl: string|null, status: string|null, statusMessage: null|string, statusMessageTimestamp: null|int, statusIcon: null|string, isUser: bool, uid: mixed}
*/
Expand Down Expand Up @@ -190,12 +210,4 @@ public function jsonSerialize(): array {
'uid' => $this->getProperty('UID'),
];
}

public function getStatusMessage(): ?string {
return $this->statusMessage;
}

public function getStatusMessageTimestamp(): ?int {
return $this->statusMessageTimestamp;
}
}
1 change: 1 addition & 0 deletions lib/private/ContactsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public function search($pattern, $searchProperties = [], $options = []) {
foreach ($r as $c) {
$c['addressbook-key'] = $addressBook->getKey();
$contacts[] = $c;
$c['test-prop'] = 'ABC';
}
$result = array_merge($result, $contacts);
}
Expand Down

0 comments on commit fe83f91

Please sign in to comment.