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 <fenn25.fn@gmail.com>
  • Loading branch information
nfebe committed Apr 22, 2024
1 parent ea1b0a0 commit 70f529c
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 {
return $this->isFederated;
}

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

public function getCloud(): CloudId {
return $this->cloud;
}

/**
* @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 70f529c

Please sign in to comment.