aboutsummaryrefslogtreecommitdiffstats
path: root/lib/public/Contacts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/public/Contacts')
-rw-r--r--lib/public/Contacts/ContactsMenu/IAction.php58
-rw-r--r--lib/public/Contacts/ContactsMenu/IActionFactory.php38
-rw-r--r--lib/public/Contacts/ContactsMenu/IBulkProvider.php23
-rw-r--r--lib/public/Contacts/ContactsMenu/IContactsStore.php30
-rw-r--r--lib/public/Contacts/ContactsMenu/IEntry.php61
-rw-r--r--lib/public/Contacts/ContactsMenu/ILinkAction.php24
-rw-r--r--lib/public/Contacts/ContactsMenu/IProvider.php25
-rw-r--r--lib/public/Contacts/Events/ContactInteractedWithEvent.php117
-rw-r--r--lib/public/Contacts/IManager.php156
9 files changed, 532 insertions, 0 deletions
diff --git a/lib/public/Contacts/ContactsMenu/IAction.php b/lib/public/Contacts/ContactsMenu/IAction.php
new file mode 100644
index 00000000000..00fe8ba35c4
--- /dev/null
+++ b/lib/public/Contacts/ContactsMenu/IAction.php
@@ -0,0 +1,58 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCP\Contacts\ContactsMenu;
+
+use JsonSerializable;
+
+/**
+ * Apps should use the IActionFactory to create new action objects
+ *
+ * @since 12.0
+ */
+interface IAction extends JsonSerializable {
+ /**
+ * @param string $icon absolute URI to an icon
+ * @since 12.0
+ */
+ public function setIcon(string $icon);
+
+ /**
+ * @return string localized action name, e.g. 'Call'
+ * @since 12.0
+ */
+ public function getName(): string;
+
+ /**
+ * @param string $name localized action name, e.g. 'Call'
+ * @since 12.0
+ */
+ public function setName(string $name);
+
+ /**
+ * @param int $priority priorize actions, high order ones are shown on top
+ * @since 12.0
+ */
+ public function setPriority(int $priority);
+
+ /**
+ * @return int priority to priorize actions, high order ones are shown on top
+ * @since 12.0
+ */
+ public function getPriority(): int;
+
+ /**
+ * @param string $appId
+ * @since 23.0.0
+ */
+ public function setAppId(string $appId);
+
+ /**
+ * @return string
+ * @since 23.0.0
+ */
+ public function getAppId(): string;
+}
diff --git a/lib/public/Contacts/ContactsMenu/IActionFactory.php b/lib/public/Contacts/ContactsMenu/IActionFactory.php
new file mode 100644
index 00000000000..69e6030e95b
--- /dev/null
+++ b/lib/public/Contacts/ContactsMenu/IActionFactory.php
@@ -0,0 +1,38 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCP\Contacts\ContactsMenu;
+
+/**
+ * @since 12.0
+ */
+interface IActionFactory {
+ /**
+ * Construct and return a new link action for the contacts menu
+ *
+ * @since 12.0
+ *
+ * @param string $icon full path to the action's icon
+ * @param string $name localized name of the action
+ * @param string $href target URL
+ * @param string $appId the app ID registering the action
+ * @return ILinkAction
+ */
+ public function newLinkAction(string $icon, string $name, string $href, string $appId = ''): ILinkAction;
+
+ /**
+ * Construct and return a new email action for the contacts menu
+ *
+ * @since 12.0
+ *
+ * @param string $icon full path to the action's icon
+ * @param string $name localized name of the action
+ * @param string $email target e-mail address
+ * @param string $appId the appName registering the action
+ * @return ILinkAction
+ */
+ public function newEMailAction(string $icon, string $name, string $email, string $appId = ''): ILinkAction;
+}
diff --git a/lib/public/Contacts/ContactsMenu/IBulkProvider.php b/lib/public/Contacts/ContactsMenu/IBulkProvider.php
new file mode 100644
index 00000000000..b817b8cbcdc
--- /dev/null
+++ b/lib/public/Contacts/ContactsMenu/IBulkProvider.php
@@ -0,0 +1,23 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCP\Contacts\ContactsMenu;
+
+/**
+ * Process contacts menu entries in bulk
+ *
+ * @since 28.0
+ */
+interface IBulkProvider {
+ /**
+ * @since 28.0
+ * @param list<IEntry> $entries
+ * @return void
+ */
+ public function process(array $entries): void;
+}
diff --git a/lib/public/Contacts/ContactsMenu/IContactsStore.php b/lib/public/Contacts/ContactsMenu/IContactsStore.php
new file mode 100644
index 00000000000..67913a2d919
--- /dev/null
+++ b/lib/public/Contacts/ContactsMenu/IContactsStore.php
@@ -0,0 +1,30 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCP\Contacts\ContactsMenu;
+
+use OCP\IUser;
+
+/**
+ * @since 13.0.0
+ */
+interface IContactsStore {
+ /**
+ * @param IUser $user
+ * @param string|null $filter
+ * @param int|null $limit added 19.0.2
+ * @param int|null $offset added 19.0.2
+ * @return IEntry[]
+ * @since 13.0.0
+ */
+ public function getContacts(IUser $user, ?string $filter, ?int $limit = null, ?int $offset = null): array;
+
+ /**
+ * @brief finds a contact by specifying the property to search on ($shareType) and the value ($shareWith)
+ * @since 13.0.0
+ */
+ public function findOne(IUser $user, int $shareType, string $shareWith): ?IEntry;
+}
diff --git a/lib/public/Contacts/ContactsMenu/IEntry.php b/lib/public/Contacts/ContactsMenu/IEntry.php
new file mode 100644
index 00000000000..9ae8a207297
--- /dev/null
+++ b/lib/public/Contacts/ContactsMenu/IEntry.php
@@ -0,0 +1,61 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCP\Contacts\ContactsMenu;
+
+use JsonSerializable;
+
+/**
+ * @since 12.0
+ */
+interface IEntry extends JsonSerializable {
+ /**
+ * @since 12.0
+ * @return string
+ */
+ public function getFullName(): string;
+
+ /**
+ * @since 12.0
+ * @return string[]
+ */
+ public function getEMailAddresses(): array;
+
+ /**
+ * @since 12.0
+ * @return string|null image URI
+ */
+ public function getAvatar(): ?string;
+
+ /**
+ * @since 12.0
+ * @param IAction $action an action to show in the contacts menu
+ */
+ public function addAction(IAction $action): void;
+
+ /**
+ * Set the (system) contact's user status
+ *
+ * @since 28.0
+ * @param string $status
+ * @param string $statusMessage
+ * @param string|null $icon
+ * @return void
+ */
+ public function setStatus(string $status,
+ ?string $statusMessage = null,
+ ?int $statusMessageTimestamp = null,
+ ?string $icon = null): void;
+
+ /**
+ * Get an arbitrary property from the contact
+ *
+ * @since 12.0
+ * @param string $key
+ * @return mixed the value of the property or null
+ */
+ public function getProperty(string $key);
+}
diff --git a/lib/public/Contacts/ContactsMenu/ILinkAction.php b/lib/public/Contacts/ContactsMenu/ILinkAction.php
new file mode 100644
index 00000000000..559e04885c5
--- /dev/null
+++ b/lib/public/Contacts/ContactsMenu/ILinkAction.php
@@ -0,0 +1,24 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCP\Contacts\ContactsMenu;
+
+/**
+ * @since 12.0
+ */
+interface ILinkAction extends IAction {
+ /**
+ * @param string $href the target URL of the action
+ * @since 12.0
+ */
+ public function setHref(string $href);
+
+ /**
+ * @since 12.0
+ * @return string
+ */
+ public function getHref(): string;
+}
diff --git a/lib/public/Contacts/ContactsMenu/IProvider.php b/lib/public/Contacts/ContactsMenu/IProvider.php
new file mode 100644
index 00000000000..e462b0133b8
--- /dev/null
+++ b/lib/public/Contacts/ContactsMenu/IProvider.php
@@ -0,0 +1,25 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCP\Contacts\ContactsMenu;
+
+/**
+ * Process contacts menu entries
+ *
+ * @see IBulkProvider for providers that work with the full dataset at once
+ *
+ * @since 12.0
+ */
+interface IProvider {
+ /**
+ * @since 12.0
+ * @param IEntry $entry
+ * @return void
+ */
+ public function process(IEntry $entry);
+}
diff --git a/lib/public/Contacts/Events/ContactInteractedWithEvent.php b/lib/public/Contacts/Events/ContactInteractedWithEvent.php
new file mode 100644
index 00000000000..6f37cee7dba
--- /dev/null
+++ b/lib/public/Contacts/Events/ContactInteractedWithEvent.php
@@ -0,0 +1,117 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCP\Contacts\Events;
+
+use OCP\EventDispatcher\Event;
+use OCP\IUser;
+
+/**
+ * An event that allows apps to notify other components about an interaction
+ * between two users. This can be used to build better recommendations and
+ * suggestions in user interfaces.
+ *
+ * Emitters should add at least one identifier (uid, email, federated cloud ID)
+ * of the recipient of the interaction.
+ *
+ * @since 19.0.0
+ */
+class ContactInteractedWithEvent extends Event {
+ /** @var IUser */
+ private $actor;
+
+ /** @var string|null */
+ private $uid;
+
+ /** @var string|null */
+ private $email;
+
+ /** @var string|null */
+ private $federatedCloudId;
+
+ /**
+ * @param IUser $actor the user who started the interaction
+ *
+ * @since 19.0.0
+ */
+ public function __construct(IUser $actor) {
+ parent::__construct();
+ $this->actor = $actor;
+ }
+
+ /**
+ * @return IUser
+ * @since 19.0.0
+ */
+ public function getActor(): IUser {
+ return $this->actor;
+ }
+
+ /**
+ * @return string|null
+ * @since 19.0.0
+ */
+ public function getUid(): ?string {
+ return $this->uid;
+ }
+
+ /**
+ * Set the uid of the person interacted with, if known
+ *
+ * @param string $uid
+ *
+ * @return self
+ * @since 19.0.0
+ */
+ public function setUid(string $uid): self {
+ $this->uid = $uid;
+ return $this;
+ }
+
+ /**
+ * @return string|null
+ * @since 19.0.0
+ */
+ public function getEmail(): ?string {
+ return $this->email;
+ }
+
+ /**
+ * Set the email of the person interacted with, if known
+ *
+ * @param string $email
+ *
+ * @return self
+ * @since 19.0.0
+ */
+ public function setEmail(string $email): self {
+ $this->email = $email;
+ return $this;
+ }
+
+ /**
+ * @return string|null
+ * @since 19.0.0
+ */
+ public function getFederatedCloudId(): ?string {
+ return $this->federatedCloudId;
+ }
+
+ /**
+ * Set the federated cloud of the person interacted with, if known
+ *
+ * @param string $federatedCloudId
+ *
+ * @return self
+ * @since 19.0.0
+ */
+ public function setFederatedCloudId(string $federatedCloudId): self {
+ $this->federatedCloudId = $federatedCloudId;
+ return $this;
+ }
+}
diff --git a/lib/public/Contacts/IManager.php b/lib/public/Contacts/IManager.php
new file mode 100644
index 00000000000..60abb18b382
--- /dev/null
+++ b/lib/public/Contacts/IManager.php
@@ -0,0 +1,156 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+// use OCP namespace for all classes that are considered public.
+// This means that they should be used by apps instead of the internal Nextcloud classes
+
+namespace OCP\Contacts;
+
+/**
+ * This class provides access to the contacts app. Use this class exclusively if you want to access contacts.
+ *
+ * Contacts in general will be expressed as an array of key-value-pairs.
+ * The keys will match the property names defined in https://tools.ietf.org/html/rfc2426#section-1
+ *
+ * Proposed workflow for working with contacts:
+ * - search for the contacts
+ * - manipulate the results array
+ * - createOrUpdate will save the given contacts overwriting the existing data
+ *
+ * For updating it is mandatory to keep the id.
+ * Without an id a new contact will be created.
+ *
+ * @since 6.0.0
+ */
+interface IManager {
+ /**
+ * This function is used to search and find contacts within the users address books.
+ * In case $pattern is empty all contacts will be returned.
+ *
+ * Example:
+ * Following function shows how to search for contacts for the name and the email address.
+ *
+ * public static function getMatchingRecipient($term) {
+ * $cm = \OCP\Server::get(\OCP\Contacts\IManager::class);
+ * // The API is not active -> nothing to do
+ * if (!$cm->isEnabled()) {
+ * return array();
+ * }
+ *
+ * $result = $cm->search($term, array('FN', 'EMAIL'));
+ * $receivers = array();
+ * foreach ($result as $r) {
+ * $id = $r['id'];
+ * $fn = $r['FN'];
+ * $email = $r['EMAIL'];
+ * if (!is_array($email)) {
+ * $email = array($email);
+ * }
+ *
+ * // loop through all email addresses of this contact
+ * foreach ($email as $e) {
+ * $displayName = $fn . " <$e>";
+ * $receivers[] = array(
+ * 'id' => $id,
+ * 'label' => $displayName,
+ * 'value' => $displayName);
+ * }
+ * }
+ *
+ * return $receivers;
+ * }
+ *
+ *
+ * @param string $pattern which should match within the $searchProperties
+ * @param array $searchProperties defines the properties within the query pattern should match
+ * @param array $options = array() to define the search behavior
+ * - 'types' boolean (since 15.0.0) If set to true, fields that come with a TYPE property will be an array
+ * example: ['id' => 5, 'FN' => 'Thomas Tanghus', 'EMAIL' => ['type => 'HOME', 'value' => 'g@h.i']]
+ * - 'escape_like_param' - If set to false wildcards _ and % are not escaped
+ * - 'limit' - Set a numeric limit for the search results
+ * - 'offset' - Set the offset for the limited search results
+ * - 'enumeration' - (since 23.0.0) Whether user enumeration on system address book is allowed
+ * - 'fullmatch' - (since 23.0.0) Whether matching on full detail in system address book is allowed
+ * - 'strict_search' - (since 23.0.0) Whether the search pattern is full string or partial search
+ * @psalm-param array{types?: bool, escape_like_param?: bool, limit?: int, offset?: int, enumeration?: bool, fullmatch?: bool, strict_search?: bool} $options
+ * @return array an array of contacts which are arrays of key-value-pairs
+ * @since 6.0.0
+ */
+ public function search($pattern, $searchProperties = [], $options = []);
+
+ /**
+ * This function can be used to delete the contact identified by the given id
+ *
+ * @param int $id the unique identifier to a contact
+ * @param string $addressBookKey identifier of the address book in which the contact shall be deleted
+ * @return bool successful or not
+ * @since 6.0.0
+ */
+ public function delete($id, $addressBookKey);
+
+ /**
+ * This function is used to create a new contact if 'id' is not given or not present.
+ * Otherwise the contact will be updated by replacing the entire data set.
+ *
+ * @param array $properties this array if key-value-pairs defines a contact
+ * @param string $addressBookKey identifier of the address book in which the contact shall be created or updated
+ * @return ?array an array representing the contact just created or updated
+ * @since 6.0.0
+ */
+ public function createOrUpdate($properties, $addressBookKey);
+
+ /**
+ * Check if contacts are available (e.g. contacts app enabled)
+ *
+ * @return bool true if enabled, false if not
+ * @since 6.0.0
+ */
+ public function isEnabled();
+
+ /**
+ * Registers an address book
+ *
+ * @return void
+ * @since 6.0.0
+ */
+ public function registerAddressBook(\OCP\IAddressBook $addressBook);
+
+ /**
+ * Unregisters an address book
+ *
+ * @param \OCP\IAddressBook $addressBook
+ * @return void
+ * @since 6.0.0
+ */
+ public function unregisterAddressBook(\OCP\IAddressBook $addressBook);
+
+ /**
+ * In order to improve lazy loading a closure can be registered which will be called in case
+ * address books are actually requested
+ *
+ * @param \Closure $callable
+ * @return void
+ * @since 6.0.0
+ */
+ public function register(\Closure $callable);
+
+ /**
+ * Return a list of the user's addressbooks
+ *
+ * @return \OCP\IAddressBook[]
+ * @since 16.0.0
+ */
+ public function getUserAddressBooks();
+
+ /**
+ * removes all registered address book instances
+ *
+ * @return void
+ * @since 6.0.0
+ */
+ public function clear();
+}