migrate therinaldos.com data
Build & Deploy to DigitalOcean Space / build (push) Failing after 2m38s

This commit is contained in:
2024-05-05 15:50:45 -04:00
commit ef1ff240d4
23182 changed files with 3801898 additions and 0 deletions
@@ -0,0 +1,48 @@
<?php
/**
* @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
*
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OC\Contacts\ContactsMenu;
use OC\Contacts\ContactsMenu\Actions\LinkAction;
use OCP\Contacts\ContactsMenu\IActionFactory;
use OCP\Contacts\ContactsMenu\ILinkAction;
class ActionFactory implements IActionFactory {
/**
* {@inheritDoc}
*/
public function newLinkAction(string $icon, string $name, string $href, string $appId = ''): ILinkAction {
$action = new LinkAction();
$action->setName($name);
$action->setIcon($icon);
$action->setHref($href);
$action->setAppId($appId);
return $action;
}
/**
* {@inheritDoc}
*/
public function newEMailAction(string $icon, string $name, string $email, string $appId = ''): ILinkAction {
return $this->newLinkAction($icon, $name, 'mailto:' . $email, $appId);
}
}
@@ -0,0 +1,116 @@
<?php
declare(strict_types=1);
/**
* @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
*
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OC\Contacts\ContactsMenu;
use Exception;
use OC\App\AppManager;
use OC\Contacts\ContactsMenu\Providers\EMailProvider;
use OC\Contacts\ContactsMenu\Providers\LocalTimeProvider;
use OC\Contacts\ContactsMenu\Providers\ProfileProvider;
use OCP\AppFramework\QueryException;
use OCP\Contacts\ContactsMenu\IBulkProvider;
use OCP\Contacts\ContactsMenu\IProvider;
use OCP\IServerContainer;
use OCP\IUser;
use Psr\Log\LoggerInterface;
class ActionProviderStore {
public function __construct(
private IServerContainer $serverContainer,
private AppManager $appManager,
private LoggerInterface $logger,
) {
}
/**
* @return list<IProvider|IBulkProvider>
* @throws Exception
*/
public function getProviders(IUser $user): array {
$appClasses = $this->getAppProviderClasses($user);
$providerClasses = $this->getServerProviderClasses();
$allClasses = array_merge($providerClasses, $appClasses);
/** @var list<IProvider|IBulkProvider> $providers */
$providers = [];
foreach ($allClasses as $class) {
try {
$provider = $this->serverContainer->get($class);
if ($provider instanceof IProvider || $provider instanceof IBulkProvider) {
$providers[] = $provider;
} else {
$this->logger->warning('Ignoring invalid contacts menu provider', [
'class' => $class,
]);
}
} catch (QueryException $ex) {
$this->logger->error(
'Could not load contacts menu action provider ' . $class,
[
'app' => 'core',
'exception' => $ex,
]
);
throw new Exception('Could not load contacts menu action provider');
}
}
return $providers;
}
/**
* @return string[]
*/
private function getServerProviderClasses(): array {
return [
ProfileProvider::class,
LocalTimeProvider::class,
EMailProvider::class,
];
}
/**
* @return string[]
*/
private function getAppProviderClasses(IUser $user): array {
return array_reduce($this->appManager->getEnabledAppsForUser($user), function ($all, $appId) {
$info = $this->appManager->getAppInfo($appId);
if (!isset($info['contactsmenu'])) {
// Nothing to add
return $all;
}
$providers = array_reduce($info['contactsmenu'], function ($all, $provider) {
return array_merge($all, [$provider]);
}, []);
return array_merge($all, $providers);
}, []);
}
}
@@ -0,0 +1,90 @@
<?php
/**
* @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
*
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OC\Contacts\ContactsMenu\Actions;
use OCP\Contacts\ContactsMenu\ILinkAction;
class LinkAction implements ILinkAction {
private string $icon = '';
private string $name = '';
private string $href = '';
private int $priority = 10;
private string $appId = '';
/**
* @param string $icon absolute URI to an icon
*/
public function setIcon(string $icon): void {
$this->icon = $icon;
}
public function setName(string $name): void {
$this->name = $name;
}
public function getName(): string {
return $this->name;
}
public function setPriority(int $priority): void {
$this->priority = $priority;
}
public function getPriority(): int {
return $this->priority;
}
public function setHref(string $href): void {
$this->href = $href;
}
public function getHref(): string {
return $this->href;
}
/**
* @since 23.0.0
*/
public function setAppId(string $appId): void {
$this->appId = $appId;
}
/**
* @since 23.0.0
*/
public function getAppId(): string {
return $this->appId;
}
/**
* @return array{title: string, icon: string, hyperlink: string, appId: string}
*/
public function jsonSerialize(): array {
return [
'title' => $this->name,
'icon' => $this->icon,
'hyperlink' => $this->href,
'appId' => $this->appId,
];
}
}
@@ -0,0 +1,386 @@
<?php
/**
* @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
* @copyright 2017 Lukas Reschke <lukas@statuscode.ch>
*
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Georg Ehrke <oc.list@georgehrke.com>
* @author Joas Schilling <coding@schilljs.com>
* @author Lukas Reschke <lukas@statuscode.ch>
* @author Roeland Jago Douma <roeland@famdouma.nl>
* @author Tobia De Koninck <tobia@ledfan.be>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OC\Contacts\ContactsMenu;
use OC\KnownUser\KnownUserService;
use OC\Profile\ProfileManager;
use OCA\UserStatus\Db\UserStatus;
use OCA\UserStatus\Service\StatusService;
use OCP\Contacts\ContactsMenu\IContactsStore;
use OCP\Contacts\ContactsMenu\IEntry;
use OCP\Contacts\IManager;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
use OCP\L10N\IFactory as IL10NFactory;
use function array_column;
use function array_fill_keys;
use function array_filter;
use function array_key_exists;
use function array_merge;
use function count;
class ContactsStore implements IContactsStore {
public function __construct(
private IManager $contactsManager,
private ?StatusService $userStatusService,
private IConfig $config,
private ProfileManager $profileManager,
private IUserManager $userManager,
private IURLGenerator $urlGenerator,
private IGroupManager $groupManager,
private KnownUserService $knownUserService,
private IL10NFactory $l10nFactory,
) {
}
/**
* @return IEntry[]
*/
public function getContacts(IUser $user, ?string $filter, ?int $limit = null, ?int $offset = null): array {
$options = [
'enumeration' => $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes',
'fullmatch' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes') === 'yes',
];
if ($limit !== null) {
$options['limit'] = $limit;
}
if ($offset !== null) {
$options['offset'] = $offset;
}
// Status integration only works without pagination and filters
if ($offset === null && ($filter === null || $filter === '')) {
$recentStatuses = $this->userStatusService?->findAllRecentStatusChanges($limit, $offset) ?? [];
} else {
$recentStatuses = [];
}
// Search by status if there is no filter and statuses are available
if (!empty($recentStatuses)) {
$allContacts = array_filter(array_map(function (UserStatus $userStatus) use ($options) {
// UID is ambiguous with federation. We have to use the federated cloud ID to an exact match of
// A local user
$user = $this->userManager->get($userStatus->getUserId());
if ($user === null) {
return null;
}
$contact = $this->contactsManager->search(
$user->getCloudId(),
[
'CLOUD',
],
array_merge(
$options,
[
'limit' => 1,
'offset' => 0,
],
),
)[0] ?? null;
if ($contact !== null) {
$contact[Entry::PROPERTY_STATUS_MESSAGE_TIMESTAMP] = $userStatus->getStatusMessageTimestamp();
}
return $contact;
}, $recentStatuses));
if ($limit !== null && count($allContacts) < $limit) {
// More contacts were requested
$fromContacts = $this->contactsManager->search(
$filter ?? '',
[
'FN',
'EMAIL'
],
array_merge(
$options,
[
'limit' => $limit - count($allContacts),
],
),
);
// Create hash map of all status contacts
$existing = array_fill_keys(array_column($allContacts, 'URI'), null);
// Append the ones that are new
$allContacts = array_merge(
$allContacts,
array_filter($fromContacts, fn (array $contact): bool => !array_key_exists($contact['URI'], $existing))
);
}
} else {
$allContacts = $this->contactsManager->search(
$filter ?? '',
[
'FN',
'EMAIL'
],
$options
);
}
$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('UID', $contact)) {
return $contact['UID'] !== $userId;
}
return true;
});
$entries = array_map(function (array $contact) {
return $this->contactArrayToEntry($contact);
}, $contacts);
return $this->filterContacts(
$user,
$entries,
$filter
);
}
/**
* Filters the contacts. Applied filters:
* 1. if the `shareapi_allow_share_dialog_user_enumeration` config option is
* enabled it will filter all local users
* 2. if the `shareapi_exclude_groups` config option is enabled and the
* current user is in an excluded group it will filter all local users.
* 3. if the `shareapi_only_share_with_group_members` config option is
* enabled it will filter all users which doesn't have a common group
* with the current user.
*
* @param Entry[] $entries
* @return Entry[] the filtered contacts
*/
private function filterContacts(
IUser $self,
array $entries,
?string $filter
): array {
$disallowEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') !== 'yes';
$restrictEnumerationGroup = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no') === 'yes';
$restrictEnumerationPhone = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no') === 'yes';
$allowEnumerationFullMatch = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes') === 'yes';
$excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes';
// whether to filter out local users
$skipLocal = false;
// whether to filter out all users which don't have a common group as the current user
$ownGroupsOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes';
$selfGroups = $this->groupManager->getUserGroupIds($self);
if ($excludedGroups) {
$excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', '');
$decodedExcludeGroups = json_decode($excludedGroups, true);
$excludeGroupsList = $decodedExcludeGroups ?? [];
if (count(array_intersect($excludeGroupsList, $selfGroups)) !== 0) {
// a group of the current user is excluded -> filter all local users
$skipLocal = true;
}
}
$selfUID = $self->getUID();
return array_values(array_filter($entries, function (IEntry $entry) use ($skipLocal, $ownGroupsOnly, $selfGroups, $selfUID, $disallowEnumeration, $restrictEnumerationGroup, $restrictEnumerationPhone, $allowEnumerationFullMatch, $filter) {
if ($entry->getProperty('isLocalSystemBook')) {
if ($skipLocal) {
return false;
}
$checkedCommonGroupAlready = false;
// Prevent enumerating local users
if ($disallowEnumeration) {
if (!$allowEnumerationFullMatch) {
return false;
}
$filterOutUser = true;
$mailAddresses = $entry->getEMailAddresses();
foreach ($mailAddresses as $mailAddress) {
if ($mailAddress === $filter) {
$filterOutUser = false;
break;
}
}
if ($entry->getProperty('UID') && $entry->getProperty('UID') === $filter) {
$filterOutUser = false;
}
if ($filterOutUser) {
return false;
}
} elseif ($restrictEnumerationPhone || $restrictEnumerationGroup) {
$canEnumerate = false;
if ($restrictEnumerationPhone) {
$canEnumerate = $this->knownUserService->isKnownToUser($selfUID, $entry->getProperty('UID'));
}
if (!$canEnumerate && $restrictEnumerationGroup) {
$user = $this->userManager->get($entry->getProperty('UID'));
if ($user === null) {
return false;
}
$contactGroups = $this->groupManager->getUserGroupIds($user);
$canEnumerate = !empty(array_intersect($contactGroups, $selfGroups));
$checkedCommonGroupAlready = true;
}
if (!$canEnumerate) {
return false;
}
}
if ($ownGroupsOnly && !$checkedCommonGroupAlready) {
$user = $this->userManager->get($entry->getProperty('UID'));
if (!$user instanceof IUser) {
return false;
}
$contactGroups = $this->groupManager->getUserGroupIds($user);
if (empty(array_intersect($contactGroups, $selfGroups))) {
// no groups in common, so shouldn't see the contact
return false;
}
}
}
return true;
}));
}
public function findOne(IUser $user, int $shareType, string $shareWith): ?IEntry {
switch ($shareType) {
case 0:
case 6:
$filter = ['UID'];
break;
case 4:
$filter = ['EMAIL'];
break;
default:
return null;
}
$contacts = $this->contactsManager->search($shareWith, $filter, [
'strict_search' => true,
]);
$match = null;
foreach ($contacts as $contact) {
if ($shareType === 4 && isset($contact['EMAIL'])) {
if (in_array($shareWith, $contact['EMAIL'])) {
$match = $contact;
break;
}
}
if ($shareType === 0 || $shareType === 6) {
$isLocal = $contact['isLocalSystemBook'] ?? false;
if ($contact['UID'] === $shareWith && $isLocal === true) {
$match = $contact;
break;
}
}
}
if ($match) {
$match = $this->filterContacts($user, [$this->contactArrayToEntry($match)], $shareWith);
if (count($match) === 1) {
$match = $match[0];
} else {
$match = null;
}
}
return $match;
}
private function contactArrayToEntry(array $contact): Entry {
$entry = new Entry();
if (!empty($contact['UID'])) {
$uid = $contact['UID'];
$entry->setId($uid);
$entry->setProperty('isUser', false);
// overloaded usage so leaving as-is for now
if (isset($contact['isLocalSystemBook'])) {
$avatar = $this->urlGenerator->linkToRouteAbsolute('core.avatar.getAvatar', ['userId' => $uid, 'size' => 64]);
$entry->setProperty('isUser', true);
} elseif (!empty($contact['FN'])) {
$avatar = $this->urlGenerator->linkToRouteAbsolute('core.GuestAvatar.getAvatar', ['guestName' => str_replace('/', ' ', $contact['FN']), 'size' => 64]);
} else {
$avatar = $this->urlGenerator->linkToRouteAbsolute('core.GuestAvatar.getAvatar', ['guestName' => str_replace('/', ' ', $uid), 'size' => 64]);
}
$entry->setAvatar($avatar);
}
if (!empty($contact['FN'])) {
$entry->setFullName($contact['FN']);
}
$avatarPrefix = "VALUE=uri:";
if (!empty($contact['PHOTO']) && str_starts_with($contact['PHOTO'], $avatarPrefix)) {
$entry->setAvatar(substr($contact['PHOTO'], strlen($avatarPrefix)));
}
if (!empty($contact['EMAIL'])) {
foreach ($contact['EMAIL'] as $email) {
$entry->addEMailAddress($email);
}
}
// Provide profile parameters for core/src/OC/contactsmenu/contact.handlebars template
if (!empty($contact['UID']) && !empty($contact['FN'])) {
$targetUserId = $contact['UID'];
$targetUser = $this->userManager->get($targetUserId);
if (!empty($targetUser)) {
if ($this->profileManager->isProfileEnabled($targetUser)) {
$entry->setProfileTitle($this->l10nFactory->get('lib')->t('View profile'));
$entry->setProfileUrl($this->urlGenerator->linkToRouteAbsolute('core.ProfilePage.index', ['targetUserId' => $targetUserId]));
}
}
}
// Attach all other properties to the entry too because some
// providers might make use of it.
$entry->setProperties($contact);
return $entry;
}
}
@@ -0,0 +1,201 @@
<?php
declare(strict_types=1);
/**
* @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
*
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OC\Contacts\ContactsMenu;
use OCP\Contacts\ContactsMenu\IAction;
use OCP\Contacts\ContactsMenu\IEntry;
use function array_merge;
class Entry implements IEntry {
public const PROPERTY_STATUS_MESSAGE_TIMESTAMP = 'statusMessageTimestamp';
/** @var string|int|null */
private $id = 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;
}
public function setFullName(string $displayName): void {
$this->fullName = $displayName;
}
public function getFullName(): string {
return $this->fullName;
}
public function addEMailAddress(string $address): void {
$this->emailAddresses[] = $address;
}
/**
* @return string[]
*/
public function getEMailAddresses(): array {
return $this->emailAddresses;
}
public function setAvatar(string $avatar): void {
$this->avatar = $avatar;
}
public function getAvatar(): ?string {
return $this->avatar;
}
public function setProfileTitle(string $profileTitle): void {
$this->profileTitle = $profileTitle;
}
public function getProfileTitle(): ?string {
return $this->profileTitle;
}
public function setProfileUrl(string $profileUrl): void {
$this->profileUrl = $profileUrl;
}
public function getProfileUrl(): ?string {
return $this->profileUrl;
}
public function addAction(IAction $action): void {
$this->actions[] = $action;
$this->sortActions();
}
public function setStatus(string $status,
string $statusMessage = null,
int $statusMessageTimestamp = null,
string $icon = null): void {
$this->status = $status;
$this->statusMessage = $statusMessage;
$this->statusMessageTimestamp = $statusMessageTimestamp;
$this->statusIcon = $icon;
}
/**
* @return IAction[]
*/
public function getActions(): array {
return $this->actions;
}
/**
* sort the actions by priority and name
*/
private function sortActions(): void {
usort($this->actions, function (IAction $action1, IAction $action2) {
$prio1 = $action1->getPriority();
$prio2 = $action2->getPriority();
if ($prio1 === $prio2) {
// Ascending order for same priority
return strcasecmp($action1->getName(), $action2->getName());
}
// Descending order when priority differs
return $prio2 - $prio1;
});
}
public function setProperty(string $propertyName, mixed $value) {
$this->properties[$propertyName] = $value;
}
/**
* @param array $properties key-value array containing additional properties
*/
public function setProperties(array $properties): void {
$this->properties = array_merge($this->properties, $properties);
}
public function getProperty(string $key): mixed {
if (!isset($this->properties[$key])) {
return null;
}
return $this->properties[$key];
}
/**
* @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}
*/
public function jsonSerialize(): array {
$topAction = !empty($this->actions) ? $this->actions[0]->jsonSerialize() : null;
$otherActions = array_map(function (IAction $action) {
return $action->jsonSerialize();
}, array_slice($this->actions, 1));
return [
'id' => $this->id,
'fullName' => $this->fullName,
'avatar' => $this->getAvatar(),
'topAction' => $topAction,
'actions' => $otherActions,
'lastMessage' => '',
'emailAddresses' => $this->getEMailAddresses(),
'profileTitle' => $this->profileTitle,
'profileUrl' => $this->profileUrl,
'status' => $this->status,
'statusMessage' => $this->statusMessage,
'statusMessageTimestamp' => $this->statusMessageTimestamp,
'statusIcon' => $this->statusIcon,
'isUser' => $this->getProperty('isUser') === true,
'uid' => $this->getProperty('UID'),
];
}
public function getStatusMessage(): ?string {
return $this->statusMessage;
}
public function getStatusMessageTimestamp(): ?int {
return $this->statusMessageTimestamp;
}
}
@@ -0,0 +1,119 @@
<?php
/**
* @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
*
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Georg Ehrke <oc.list@georgehrke.com>
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OC\Contacts\ContactsMenu;
use Exception;
use OCP\App\IAppManager;
use OCP\Constants;
use OCP\Contacts\ContactsMenu\IBulkProvider;
use OCP\Contacts\ContactsMenu\IEntry;
use OCP\Contacts\ContactsMenu\IProvider;
use OCP\IConfig;
use OCP\IUser;
class Manager {
public function __construct(
private ContactsStore $store,
private ActionProviderStore $actionProviderStore,
private IAppManager $appManager,
private IConfig $config,
) {
}
/**
* @throws Exception
*/
public function getEntries(IUser $user, ?string $filter): array {
$maxAutocompleteResults = max(0, $this->config->getSystemValueInt('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT));
$minSearchStringLength = $this->config->getSystemValueInt('sharing.minSearchStringLength');
$topEntries = [];
if (strlen($filter ?? '') >= $minSearchStringLength) {
$entries = $this->store->getContacts($user, $filter, $maxAutocompleteResults);
$sortedEntries = $this->sortEntries($entries);
$topEntries = array_slice($sortedEntries, 0, $maxAutocompleteResults);
$this->processEntries($topEntries, $user);
}
$contactsEnabled = $this->appManager->isEnabledForUser('contacts', $user);
return [
'contacts' => $topEntries,
'contactsAppEnabled' => $contactsEnabled,
];
}
/**
* @throws Exception
*/
public function findOne(IUser $user, int $shareType, string $shareWith): ?IEntry {
$entry = $this->store->findOne($user, $shareType, $shareWith);
if ($entry) {
$this->processEntries([$entry], $user);
}
return $entry;
}
/**
* @param IEntry[] $entries
* @return IEntry[]
*/
private function sortEntries(array $entries): array {
usort($entries, function (Entry $entryA, Entry $entryB) {
$aStatusTimestamp = $entryA->getProperty(Entry::PROPERTY_STATUS_MESSAGE_TIMESTAMP);
$bStatusTimestamp = $entryB->getProperty(Entry::PROPERTY_STATUS_MESSAGE_TIMESTAMP);
if (!$aStatusTimestamp && !$bStatusTimestamp) {
return strcasecmp($entryA->getFullName(), $entryB->getFullName());
}
if ($aStatusTimestamp === null) {
return 1;
}
if ($bStatusTimestamp === null) {
return -1;
}
return $bStatusTimestamp - $aStatusTimestamp;
});
return $entries;
}
/**
* @param IEntry[] $entries
* @throws Exception
*/
private function processEntries(array $entries, IUser $user): void {
$providers = $this->actionProviderStore->getProviders($user);
foreach ($providers as $provider) {
if ($provider instanceof IBulkProvider && !($provider instanceof IProvider)) {
$provider->process($entries);
} elseif ($provider instanceof IProvider && !($provider instanceof IBulkProvider)) {
foreach ($entries as $entry) {
$provider->process($entry);
}
}
}
}
}
@@ -0,0 +1,48 @@
<?php
/**
* @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
*
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OC\Contacts\ContactsMenu\Providers;
use OCP\Contacts\ContactsMenu\IActionFactory;
use OCP\Contacts\ContactsMenu\IEntry;
use OCP\Contacts\ContactsMenu\IProvider;
use OCP\IURLGenerator;
class EMailProvider implements IProvider {
public function __construct(
private IActionFactory $actionFactory,
private IURLGenerator $urlGenerator,
) {
}
public function process(IEntry $entry): void {
$iconUrl = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/mail.svg'));
foreach ($entry->getEMailAddresses() as $address) {
if (empty($address)) {
// Skip
continue;
}
$action = $this->actionFactory->newEMailAction($iconUrl, $address, $address, 'email');
$entry->addAction($action);
}
}
}
@@ -0,0 +1,69 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2023, Joas Schilling <coding@schilljs.com>
*
* @author Joas Schilling <coding@schilljs.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OC\Contacts\ContactsMenu\Providers;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Contacts\ContactsMenu\IActionFactory;
use OCP\Contacts\ContactsMenu\IEntry;
use OCP\Contacts\ContactsMenu\IProvider;
use OCP\IConfig;
use OCP\IDateTimeFormatter;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\L10N\IFactory as IL10NFactory;
class LocalTimeProvider implements IProvider {
public function __construct(
private IActionFactory $actionFactory,
private IL10NFactory $l10nFactory,
private IURLGenerator $urlGenerator,
private IUserManager $userManager,
private ITimeFactory $timeFactory,
private IDateTimeFormatter $dateTimeFormatter,
private IConfig $config,
) {
}
public function process(IEntry $entry): void {
$targetUserId = $entry->getProperty('UID');
$targetUser = $this->userManager->get($targetUserId);
if (!empty($targetUser)) {
$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);
$iconUrl = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/recent.svg'));
$l = $this->l10nFactory->get('lib');
$profileActionText = $l->t('Local time: %s', [$localTime]);
$action = $this->actionFactory->newLinkAction($iconUrl, $profileActionText, '#', 'timezone');
// Order after the profile page
$action->setPriority(19);
$entry->addAction($action);
}
}
}
@@ -0,0 +1,60 @@
<?php
/**
* @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
*
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OC\Contacts\ContactsMenu\Providers;
use OC\Profile\ProfileManager;
use OCP\Contacts\ContactsMenu\IActionFactory;
use OCP\Contacts\ContactsMenu\IEntry;
use OCP\Contacts\ContactsMenu\IProvider;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\L10N\IFactory as IL10NFactory;
class ProfileProvider implements IProvider {
public function __construct(
private IActionFactory $actionFactory,
private ProfileManager $profileManager,
private IL10NFactory $l10nFactory,
private IURLGenerator $urlGenerator,
private IUserManager $userManager,
) {
}
public function process(IEntry $entry): void {
$targetUserId = $entry->getProperty('UID');
$targetUser = $this->userManager->get($targetUserId);
if (!empty($targetUser)) {
if ($this->profileManager->isProfileEnabled($targetUser)) {
$iconUrl = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/profile.svg'));
$profileActionText = $this->l10nFactory->get('lib')->t('View profile');
$profileUrl = $this->urlGenerator->linkToRouteAbsolute('core.ProfilePage.index', ['targetUserId' => $targetUserId]);
$action = $this->actionFactory->newLinkAction($iconUrl, $profileActionText, $profileUrl, 'profile');
// Set highest priority (by descending order), other actions have the default priority 10 as defined in lib/private/Contacts/ContactsMenu/Actions/LinkAction.php
$action->setPriority(20);
$entry->addAction($action);
}
}
}
}